【问题标题】:Why does Karate strip chars from the front of my field names?为什么空手道会从我的字段名称前面去除字符?
【发布时间】:2020-02-13 00:21:58
【问题描述】:

我的一项空手道测试发生了一些奇怪的事情。我继承了很多(而不是自己写的),而且它们大部分都工作正常。我的应用程序使用 GraphQL 并且我正在更改现有的变异函数以添加参数。新参数是DestinationInput 的列表,定义如下:

createScheduledTitles(titles: [ScheduledTitleInput!]!, destinations: [DestinationInput]!): [ScheduledTitle!]!

这就是我在空手道脚本中设置参数的方式:

        * def input =
        """
         {titles: [ {
          ...
          ],
          destinations: [
            {
                'destinationType': "od", 
                'brightcovePublish': "true" 
            }
          ]
         }
        """

这被服务器端(java)拒绝:

The variables input contains a field name 'stinationType' that is not defined for input object type 'DestinationInput' 

嗯,是的,当然,但我提供的是“destinationType”而不是“stinationType”。当我检查发送内容的日志时,我看到了这个:

        "destinations": [
          {
            "stinationType": "od",
            "ightcovePublish": "true"
          }
        ]

嗯?那些最初的角色去哪儿了?从那以后,我在字段名称和参数上尝试了所有引号组合(双引号、单引号、无引号)。我尝试了不同的行格式等。一些细微的差异,一些组合在字段名称中留下引号,所以我看到 stinationtype\' 作为错误的字段名称,有时它会从前面咀嚼更多的字母。我已经重新输入了字段名称,以防我在那里编辑了一些隐藏的字符。到目前为止,没有什么能让我成功。我有这种事情的其他工作示例,并且我已经复制了它们的格式,但仍然没有乐趣。无论发生什么都在客户端,因为日志显示正在发送的错误字段名称。有谁知道我做错了什么?

【问题讨论】:

    标签: graphql karate


    【解决方案1】:

    这里是空手道开发者——这很奇怪,从来没有见过这样的东西。请记住,这可能是一个真正的服务器端错误——但我猜你已经查看了请求/http 日志。

    我没有看到整个项目结构的另一个猜测是,可能有一些自定义 Java / JS 代码正在预处理请求,这对于 GraphQL 项目很常见。尝试形成一个有效的 cURL 请求,第 2 步是将其转换为简单的(硬编码)空手道测试。如果你能管理这个过程,我们可以看看:https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

    但我只是尝试在您可以复制的测试中使用您的示例 JSON(甚至是 HTTP POST)。所以试着把它粘贴到一个新的Scenario

    Scenario:
    * def input =
            """
             {titles: [
                {}
              ],
              destinations: [
                {
                    'destinationType': "od", 
                    'brightcovePublish': "true" 
                }
              ]
             }
            """
    * print input
    * url 'https://httpbin.org/post'
    * request input
    * method post
    

    结果:

    14:26:59.370 [main] INFO  com.intuit.karate - [print] {
      "titles": [
        {
        }
      ],
      "destinations": [
        {
          "destinationType": "od",
          "brightcovePublish": "true"
        }
      ]
    }
    
    14:26:59.614 [main] DEBUG com.intuit.karate - request:
    1 > POST https://httpbin.org/post
    1 > Accept-Encoding: gzip,deflate
    1 > Connection: Keep-Alive
    1 > Content-Length: 84
    1 > Content-Type: application/json; charset=UTF-8
    1 > Host: httpbin.org
    1 > User-Agent: Apache-HttpClient/4.5.11 (Java/1.8.0_231)
    {"titles":[{}],"destinations":[{"destinationType":"od","brightcovePublish":"true"}]}
    
    14:27:00.890 [main] DEBUG com.intuit.karate - response time in milliseconds: 1274.99
    1 < 200
    1 < Access-Control-Allow-Credentials: true
    1 < Access-Control-Allow-Origin: *
    1 < Connection: keep-alive
    1 < Content-Length: 696
    1 < Content-Type: application/json
    1 < Date: Thu, 13 Feb 2020 08:57:00 GMT
    1 < Server: gunicorn/19.9.0
    {
      "args": {}, 
      "data": "{\"titles\":[{}],\"destinations\":[{\"destinationType\":\"od\",\"brightcovePublish\":\"true\"}]}", 
      "files": {}, 
      "form": {}, 
      "headers": {
        "Accept-Encoding": "gzip,deflate", 
        "Content-Length": "84", 
        "Content-Type": "application/json; charset=UTF-8", 
        "Host": "httpbin.org", 
        "User-Agent": "Apache-HttpClient/4.5.11 (Java/1.8.0_231)", 
        "X-Amzn-Trace-Id": "Root=1-5e450f5c-18d2618834da3a7afdd3402a"
      }, 
      "json": {
        "destinations": [
          {
            "brightcovePublish": "true", 
            "destinationType": "od"
          }
        ], 
        "titles": [
          {}
        ]
      }, 
      "origin": "103.15.250.10", 
      "url": "https://httpbin.org/post"
    }
    

    【讨论】:

    • 感谢您的回复。我发现我有一些制表符而不是前导空格,因此我将它们更改为空格。你的例子只有空格,所以我给它打勾。我不知道空手道对前导标签很敏感。
    • @RogerParkinson 我认为这是一个错误,那么您能否向我们发送一个复制此问题的文件?请继续提交错误!
    猜你喜欢
    • 2017-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-13
    • 1970-01-01
    相关资源
    最近更新 更多