【问题标题】:Karate - GraphQL - How to verify schema and then response?空手道 - GraphQL - 如何验证模式然后响应?
【发布时间】:2018-08-28 11:21:09
【问题描述】:

我终于让 Karate 使用 GraphQL 并能够验证一个简单的 200 响应,尽管我在验证架构和响应时遇到了问题。我是超级新手,所以我道歉(不是程序员,只是测试员)。我想验证架构是否正确,例如结果只是返回(providerID、firstName、lastName 等),而不是数据。然后我想单独验证数据本身。我不明白的另一件事是如何传递数据,例如我可以在哪里更改纬度、经度、最大距离等并将其作为变量。我在示例中看到“名称”如何用作变量,但这些似乎以不同的方式传递,所以我不确定如何去做。很抱歉没有知道这么多,感谢您的帮助。

Scenario: simple graphql request
    #Verify 200 response status returned    
    Given text query =
        """
     {
                    Results: getSearchResults(searchLatitude:"38.942833", 
    searchLongitude: "-119.984549", providerType: "Primary Care Physicians", 
    sortBy: "distance", maxDistance:"600",skip: 0, take: 10) {
                        providerID
                        firstName 
                        lastName
                        mI
                        title
                        name
                        nameLFMT
                        status
                        specialties
                        locations
                        institutions
                        acceptNewPatient
                        imageUri
                        distanceToNearest
                    }

    } 

        """
    And request { query: '#(query)' }
    When method post
    Then status 200

    # pretty print the response
    * print 'response:', response


    # the '..' wildcard is useful for traversing deeply nested parts of the 
    json
    * def results = get[0] response..Results
    * match results contains { ProviderId: 520, firstName: 'Richard', 
lastName: 'Botto' }

【问题讨论】:

    标签: java automated-tests cucumber graphql karate


    【解决方案1】:

    看看replace关键字。

    然后试试这个:

    Given text query =
        """
     {
                    Results: getSearchResults(searchLatitude:"<searchLatitude>", 
    searchLongitude: "<searchLongitude>", providerType: "Primary Care Physicians", 
    sortBy: "distance", maxDistance:"600",skip: 0, take: 10) {
                        providerID
                        firstName 
                        lastName
                        mI
                        title
                        name
                        nameLFMT
                        status
                        specialties
                        locations
                        institutions
                        acceptNewPatient
                        imageUri
                        distanceToNearest
                    }
    
    } 
    
        """
    * replace query.searchLatitude = '38.942833'
    * replace query.searchLongitude = '-119.984549'
    

    一旦你得到这个工作,搜索“graphql”的文档以获得更多想法。

    对于匹配模式应该很容易:

    * match results contains { ProviderId: '#number', firstName: '#string', lastName: '#string' }
    

    该文档在fuzzy matching 上有一个完整的部分。

    【讨论】:

    • @PeterSmith,替换很棒,谢谢。我一直在与比赛结果战斗包含仍然。我尝试了一个更简单的 GraphQL 查询和响应,但没有成功。更简单的查询返回一个冗长的数组/对象,如下所示(数组中有 10 个),但我不知道如何实现。数据:'#object',{ getClaimHeadersList:'#array',[ { claimNumber:'#string',claimStatus:'#string',totalPatientResponsibility:'#number',providerName:'#string',memberName:'#string ' } ] }
    • @Jo-AnneB 听起来你只需要习惯嵌套的 JSON 和数组。我建议您将此答案标记为已接受,并使用您要验证的响应 JSON 的简单示例打开一个新问题。您还可以浏览其中一些示例:github.com/intuit/karate/blob/master/karate-junit4/src/test/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-13
    • 1970-01-01
    • 2019-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多