Refer defined variable in Scenario outline example

半腔热情 提交于 2021-02-16 21:01:13

问题


Feature: Test Type

  Background:
    * url host
    * def name = 'test_name' 
    * def label = name

  Scenario Outline: Test 2
    Given url homeLinks.groupTypesUrl
    And headers { tenant: #(tenantId), Authorization: #(authToken) }
    * def name = <name>
    * def description = <description>
    * def label = <label>
    * json data = read('path/to/file/create_group_type_request.json')

    And request data
    When method POST
    Then status 400

    Examples:
      | name     | label   | description   |
      | '\u0000' | 'label' | 'description' |
      | #(name)  | '\u0000'| 'description' |

I need to refer global name defined inside examples map. How to get that reference?

Getting Javascript evalution error when I tried to like above piece of code.


回答1:


Yes, Examples do not support JS eval and variables. Use the table form and loop over it with a call to a second feature: https://github.com/intuit/karate#calling-other-feature-files

Or you can try to use a dynamic Scenario Outline by initializing the table in the background: https://github.com/intuit/karate#dynamic-scenario-outline



来源:https://stackoverflow.com/questions/57284011/refer-defined-variable-in-scenario-outline-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!