我使用最新的空手道v1.1.0。我的特征是这样的:
Feature: Scenario outline with examples table
Background:
* url 'http://localhost:8080'
* def dummy = Java.type(karatetests.attributes)
* def test = new attributes()
* def userid = test.getuserid()
Scenario Outline: pass userid with string as parameter
Given path '<path>'
And Header Host = 'hostname'
And Header User-Agent = '<Ua-string>'
When method POST
Then status 200
Examples:
| path | Ua-string |
| api | AppleWebKit/537.36 (KHTML, like Gecko, userid)|
在黄瓜:我能够实现'userid'的变量值与AppleWebKit/537.36 (KHTML,像Gecko, ${userid})在u -string表
在空手道中:我尝试了'userid', "userid" "#(userid)"和'#(userid)',不幸的是没有成功。
Examples:
| path | Ua-string |
| api | AppleWebKit/537.36 (KHTML, like Gecko, userid)| => Result: userid string is passed not its value
| api | AppleWebKit/537.36 (KHTML, like Gecko, 'userid')| => Result: syntax error
| api | AppleWebKit/537.36 (KHTML, like Gecko, "userid")| => Result: "userid" string is passed not its value
| api | AppleWebKit/537.36 (KHTML, like Gecko, "#(userid)")| => Result: "#(userid)" string is passed not its value
| api | AppleWebKit/537.36 (KHTML, like Gecko, '#(userid)')| => Result: '#(userid)' syntax error
我如何用它的值替换userid,同时传递它到Ua-string头?由于
非常适合我。试试这个例子,你可以剪切和粘贴到任何特性中,看看它是否适合你:
Scenario Outline:
* url 'https://httpbin.org/anything'
* header User-Agent = userAgent
* method get
Examples:
| userAgent |
| foo |
| bar |
但我认为你期望函数和变量工作在Examples:
-但对不起,这是不支持的:https://stackoverflow.com/a/60358535/143475
Scenario Outline:
* url 'https://httpbin.org/anything'
* header User-Agent = userAgent
* method get
Examples:
| userAgent! |
| 'foo, bar' |
| 'baz, ban' |
最后,如果你真的想创造一些"奇迹"使用变量,您总是可以在场景主体中这样做,如下所示:https://stackoverflow.com/a/60358535/143475
或者直接使用字符串连接。有那么难吗?