空手道 - GraphQL - 如何验证架构然后响应?

时间:2018-03-19 19:19:03

标签: java automated-tests cucumber graphql karate

我终于让Karate使用GraphQL并且能够验证简单的200响应,尽管我在验证模式然后响应时遇到了问题。我是超级新人所以我道歉(不是程序员,只是测试人员)。我想验证模式是否正确,例如结果只返回(providerID,firstName,lastName等),而不是数据。然后我想分别验证数据本身。我不明白的另一件事是如何传递数据,例如我可以改变Latitude,Longitude,MaxDistance等,并让它成为一个变量。我在示例中看到" name"作为变量使用但这些似乎以不同方式传递,因此我不确定如何做到这一点。很抱歉不知道这么多,我感谢你的帮助。

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' }

1 个答案:

答案 0 :(得分: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'

一旦你开始工作,就可以搜索&#34; graphql&#34;的文档。更多的想法。

对于匹配模式,它应该很简单:

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

该文档在fuzzy matching上有一整节。