无法使用空手道运行graphql测试

ars1skjm  于 2021-07-05  发布在  Java
关注(0)|答案(1)|浏览(328)

我试图用intellij和空手道来编写下面的代码,但收到了一条错误消息。
下面的代码

Feature: sample karate test script
  for help, see: https://github.com/intuit/karate/wiki/IDE-Support

  Scenario: create a user and then get it by id
    * def user =
     """
      {
  ethereum {
    smartContractEvents(options: {desc: "date.date"}, smartContractAddress: {is: "0x00000000219ab540356cbb839cbe05303d7705fa"}, date: {since: "2019-01-01", till: null}) {
      date {
        date: startOfInterval(unit: day)
      }
      smartContractEvent {
        __typename
        name
      }
      times: count
      uniqueCallers: count(uniq: callers)
    }
  }
}
  """

    Given url 'https://graphql.bitquery.io'
    And request user
    When method get
    Then print response

当你试图运行代码时,我收到了下面的错误消息

test.feature:6 - net.minidev.json.parser.ParseException: Unexpected token ) at position 181.
01:12:04.375 [pool-1-thread-1] INFO  com.intuit.karate.Runner - <<fail>> feature 1 of 1: src/test/java/examples/users/test.feature
0wi1tuuw

0wi1tuuw1#

得到了答案,
正确的方法是使用查询

Feature: sample karate test script
  Background:
    * url 'https://graphql.bitquery.io'

# this live url should work if you want to try this on your own

# * url 'https://graphql-pokemon.now.sh'

  Scenario: simple graphql request
    # note the use of text instead of def since this is NOT json
    Given text query =
    """
    {
  ethereum {
    dexTrades(date: {is:"2020-11-29"} options: {limit: 10}
      baseCurrency: {is: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}
        quoteCurrency:{is: "0xdac17f958d2ee523a2206206994597c13d831ec7"}
    ){

      baseCurrency {
        symbol
        address
      }
      baseAmount

      quoteCurrency {
        symbol
        address
      }
      quoteAmount

      quotePrice

    }
  }
}
    """
    And request { query: '#(query)' }
    When method post
    Then print response

相关问题