簡體   English   中英

空手道:有沒有一種方法可以對示例應用函數:變量?

[英]Karate: is there a way to apply functions against Examples: variables?

我的空手道考試通過了:

Feature:  Armstrong numbers

  Background:
    * url baseUrl
    * configure lowerCaseResponseHeaders = true

  Scenario Outline: Find Armstrong numbers in the range from <start> to <end> are <result>
    Given path '/armstrongs'
    And param start = <start>
    And param end = <end>
    When method get
    Then status 200
    And match header content-type contains 'application/json'
    And match header content-type contains 'charset=utf-8'
    And match response == {numbers:<result>, start:<start>, end:<end>, count: <count>, type:Armstrong}
    Examples:
      | start | end    | result                | count
      | 1     | 10     | [1,2,3,4,5,6,7,8,9]   | 9
      | 100   | 1000   | [153, 370, 371, 407]  | 4
      | 90000 | 100000 | [92727, 93084]        | 2

但是,我想做的是沒有Examples:部分中的count變量,而是通過這種方式從變量的長度中得出count:

Feature:  Armstrong numbers

  Background:
    * url baseUrl
    * configure lowerCaseResponseHeaders = true

  Scenario Outline: Find Armstrong numbers in the range from <start> to <end> are <result>
    Given path '/armstrongs'
    And param start = <start>
    And param end = <end>
    When method get
    Then status 200
    And match header content-type contains 'application/json'
    And match header content-type contains 'charset=utf-8'
    And match response == {numbers:<result>, start:<start>, end:<end>, count: <result>.length, type:Armstrong}
    Examples:
      | start | end    | result
      | 1     | 10     | [1,2,3,4,5,6,7,8,9]
      | 100   | 1000   | [153, 370, 371, 407]
      | 90000 | 100000 | [92727, 93084]

嘗試此操作時,出現錯誤:

Armstrong.feature:15 - net.minidev.json.parser.ParseException: Unexpected token . at position 72.

測試失敗。

有沒有一種方法可以對示例應用函數:諸如.length之類的變量,以獲得預期結果並通過測試?

進行以下更改:

And def result = <result>
And match response == {numbers: '#(result)', start: <start>, end: <end>, count: '#(result.length)', type: 'Armstrong' }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM