空手道 UI - 将值传递给调用的 UI 功能

问题描述 投票:0回答:1

我找到了一些关于在测试中使用值/变量的答案。含义:

* def state = 'NY'
...
And input('#state', state)

这在功能文件中效果很好。

我需要能够

* call read

 并将值传递给该功能。

所以我的测试将是

Feature: Background: * call read('classpath:util/UI_login.feature') Scenario: Create Unit test feature # API test -> Create and store name value * def create = call read('classpath:create.feature') * def name = create.response.name # UI test -> use name value to update record * call read('classpath:UI/updateRecord.feature') { name: '#(name)' }

updateRecord.feature

看起来像

Feature: update record Background: * def city = 'New York City' * def state = 'NY' Scenario: update record for specific name value via the ui * configure driver = { type: 'chrome' } Given driver URLBase + '/update' And select('#user--name', name).click() And input('#city', city) And input('#state', state)
它找到了类 

user--name

 的下拉列表,但无法找到名称值。

如果我对名称值进行硬编码,例如

And select('#user--name', 'Hassan').click()
测试通过了,但我正在尝试将其与其他功能文件集成

karate
1个回答
0
投票
显然 select() 不支持变量(如果我错了,请纠正我!)

我可以通过执行以下操作使其正常工作:

调用上面的功能(

* call read('classpath:UI/updateRecord.feature') { name: '#(name)' }

)并以相同的方式传递变量。

在 updateRecord.feature 中,我将

And select('#user--name', name).click()

 行更改为:

* mouse('#user--name').click() And input('#user--name', name)

#user--name

 是一个下拉列表,但发送名称变量作为输入可以从列表中选择它。

© www.soinside.com 2019 - 2024. All rights reserved.