feature1 的变量值 -> feature 2 通过调用读取
Variable value of feature1 -> feature 2 through call read
在这种情况下,我有 2 个特征文件
1) 创建-user.feature
2) 赎回-create.feature
我创建了新功能,即 redeem.feature 来集成这两个功能。
在 redeem.feature 中,我没有使用任何背景步骤,而是创建了如下场景步骤
场景:运行创建用户
# fetch service token (redemption endpoints are protected by service token)
* def result = call read('classpath:com/imscreateuser/create-user.feature')
* print "testing ..."+ result.teacher
* def idval = result.teacher
* print idval
* def signIn = call read('classpath:com/redeem/redeem-create.feature') { username: idval }
我有以下兑换方案-create.feature
@ignore
功能:可重复使用的功能来创建一只猫
场景:
* def result = call read('classpath:com/ims/fetch-
rrc2servicetoken.feature')
Given url 'https://aps-il-test.io/api/redemptions'
And header Accept = 'application/json'
And request { userId: '#(username)' }
When method post
Then status 200
* print response.subscriptionId
请阅读documentation,我在下面引用:
Variables set using def
in the Background
will be re-set before every
Scenario
. If you are looking for a way to do something only once per
Feature
, take a look at callonce
. On the other hand, if you are
expecting a variable in the Background
to be modified by one Scenario
so that later ones can see the updated value - that is not how you
should think of them, and you should combine your 'flow' into one
scenario. Keep in mind that you should be able to comment-out a
Scenario
or skip some via tags without impacting any others.
编辑:好的,在您编辑问题后,这对您有帮助吗:
* def signIn = call read('classpath:com/redeem/redeem-create.feature') { username: '#(idval)' }
请花时间了解嵌入式表达式:https://github.com/intuit/karate#embedded-expressions
在这种情况下,我有 2 个特征文件
1) 创建-user.feature
2) 赎回-create.feature
我创建了新功能,即 redeem.feature 来集成这两个功能。
在 redeem.feature 中,我没有使用任何背景步骤,而是创建了如下场景步骤
场景:运行创建用户
# fetch service token (redemption endpoints are protected by service token)
* def result = call read('classpath:com/imscreateuser/create-user.feature')
* print "testing ..."+ result.teacher
* def idval = result.teacher
* print idval
* def signIn = call read('classpath:com/redeem/redeem-create.feature') { username: idval }
我有以下兑换方案-create.feature
@ignore
功能:可重复使用的功能来创建一只猫
场景:
* def result = call read('classpath:com/ims/fetch-
rrc2servicetoken.feature')
Given url 'https://aps-il-test.io/api/redemptions'
And header Accept = 'application/json'
And request { userId: '#(username)' }
When method post
Then status 200
* print response.subscriptionId
请阅读documentation,我在下面引用:
Variables set using
def
in theBackground
will be re-set before everyScenario
. If you are looking for a way to do something only once perFeature
, take a look atcallonce
. On the other hand, if you are expecting a variable in theBackground
to be modified by oneScenario
so that later ones can see the updated value - that is not how you should think of them, and you should combine your 'flow' into one scenario. Keep in mind that you should be able to comment-out aScenario
or skip some via tags without impacting any others.
编辑:好的,在您编辑问题后,这对您有帮助吗:
* def signIn = call read('classpath:com/redeem/redeem-create.feature') { username: '#(idval)' }
请花时间了解嵌入式表达式:https://github.com/intuit/karate#embedded-expressions