空手道:有没有办法在场景大纲和示例中将变量作为字符串传递 table
Karate: Is there a way to pass variable as string in scenario outline and examples table
我正在使用最新的空手道 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)|
在黄瓜中:我能够在 Ua-string table 和 AppleWebKit/537.36 中实现 'userid' 的变量值(KHTML,如 Gecko,${userid })
在空手道中:我尝试使用 '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 header?
谢谢
非常适合我。试试这个您可以剪切并粘贴到任何功能中的示例,看看它是否适合您自己:
Scenario Outline:
* url 'https://httpbin.org/anything'
* header User-Agent = userAgent
* method get
Examples:
| userAgent |
| foo |
| bar |
但我认为您希望函数和变量在 Examples:
内工作 - 但抱歉,不支持:
编辑我仍然不明白你在评论中所说的“变量”是什么意思,但如果你发现逗号有问题,试试这个,并参考文档:https://github.com/intuit/karate#scenario-outline-enhancements
Scenario Outline:
* url 'https://httpbin.org/anything'
* header User-Agent = userAgent
* method get
Examples:
| userAgent! |
| 'foo, bar' |
| 'baz, ban' |
最后,如果你真的想使用变量做一些“魔术”,你总是可以在场景主体中这样做,如下所示:
或者只使用字符串连接。有这么难吗?
我正在使用最新的空手道 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)|
在黄瓜中:我能够在 Ua-string table 和 AppleWebKit/537.36 中实现 'userid' 的变量值(KHTML,如 Gecko,${userid })
在空手道中:我尝试使用 '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 header? 谢谢
非常适合我。试试这个您可以剪切并粘贴到任何功能中的示例,看看它是否适合您自己:
Scenario Outline:
* url 'https://httpbin.org/anything'
* header User-Agent = userAgent
* method get
Examples:
| userAgent |
| foo |
| bar |
但我认为您希望函数和变量在 Examples:
内工作 - 但抱歉,不支持:
编辑我仍然不明白你在评论中所说的“变量”是什么意思,但如果你发现逗号有问题,试试这个,并参考文档:https://github.com/intuit/karate#scenario-outline-enhancements
Scenario Outline:
* url 'https://httpbin.org/anything'
* header User-Agent = userAgent
* method get
Examples:
| userAgent! |
| 'foo, bar' |
| 'baz, ban' |
最后,如果你真的想使用变量做一些“魔术”,你总是可以在场景主体中这样做,如下所示:
或者只使用字符串连接。有这么难吗?