![](/img/trans.png)
[英]Karate API Testing - Passing variable from one feature file to another
[英]Karate API : Passing variables to other feature file is not working
我正在从传递 url、用户名和密码的其他功能文件中调用登录功能文件,但它对我不起作用。 我在这里没有使用背景键,我也不想。
@CallAnotherFeature
Feature: Call Login Feature
Scenario: Calling Login Test
* def config = { endPointURL: 'https://qa1.testurl.com/login',username: 'user123', password: 'password123' }
* def result= call read('Login.feature') config
* print result.response
* print 'Sign In-'+signIn
* print 'Sign In Reponse-'+signIn.response
Feature: Login Feature
Scenario: Test Login for different users
* print 'Starting Test','#(endPointURL)'
Given url '#(endPointURL)'
* print 'user name','#(username)'
* print 'Password ','#(password)'
#And form field username = '#(username)'
#And form field password = '#(password)'
And request { username: '#(username)', password: '#(password)'}
When method post
Then status 200
* print response
* match response.loginSuccess == true
在 Login.feature 中,我也尝试将用户名和密码作为表单数据传递,即使它们不起作用。 有人能告诉我我在这里犯了什么错误吗?
我正在使用最新的空手道版本 0.9.0
我在你的脚本中看到了一些问题,
1.调用登录功能
1.1) 我没有看到signIn
变量在此功能中的任何地方初始化,也没有从您的login feature
中看到,但您正在尝试打印它。
1.2) =
应妥善放置;)
* def result = call read('Login.feature') config
2.登录功能
2.1) 我认为你误解了嵌入表达式的概念。 仅用于将其模板化为 JSON,您可以使用它。 但要调用它,您只需使用变量名即可。
例如。
Given url endPointURL
And form field username = username
And request { username: '#(username)', password: '#(password)'}
不是
Given url '#(endPointURL)'
And form field username = '#(username)'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.