如何启动所有空手道功能,设置哪个浏览器用作外部 Maven 变量
我试图找到一种方法,通过 maven 使用外部变量来设置浏览器(使用本地网络驱动程序或使用 Selenium 网格)来启动空手道测试中的所有功能。
所以类似:
mvn test -Dbrowser=chrome (or firefox, safari, etc)
或使用 Selenium 网格:
mvn test -Dbrowser=chrome (or firefox, safari, etc) -Dgrid="grid url"
使用 Cucumber 和 Java,使用单例来设置然后在所有测试中使用的全局 Web 驱动程序非常简单。通过这种方式,我可以使用不同的本地或远程网络驱动程序运行测试。
在空手道中,我尝试了不同的解决方案,最后一个是:
- 定义空手道配置文件变量“浏览器”
- 在单个功能“X”中使用变量“浏览器”,其中我仅设置
- 所有其他功能中的 空手道驱动程序曾经调用过使用该驱动程序的功能“X”
,但它不起作用,说实话,在我看来这不是正确的方法。 也许能够从功能内的 Javascript 函数设置空手道驱动程序是正确的方法,但我无法找到解决方案。
我发现空手道的另一个问题是使用本地或远程网络驱动程序来区分行为,因为它们在以不同方式设置的功能文件中。
那么有人有我同样的需求吗?我该如何解决呢?
I was trying to find a way to launch all features in Karate testing through maven using an external variable to set up the browser (with a local webdriver or using a Selenium grid).
So something like:
mvn test -Dbrowser=chrome (or firefox, safari, etc)
or using a Selenium grid:
mvn test -Dbrowser=chrome (or firefox, safari, etc) -Dgrid="grid url"
With Cucumber and Java this was quite simple using a singleton for setting up a global webdriver that was then used in all tests. In this way I could run the tests with different local or remote webdrivers.
In Karate I tried different solution, the last was to:
- define the Karate config file a variable "browser"
- use the variable "browser" in a single feature "X" in which I set up only the Karate driver
- from all the other features with callonce to re-call the feature "X" for using that driver
but it didn't work and to be honest it doesn't seem to me to be the right approach.
Probably being able to set the Karate driver from a Javascript function inside the features is the right way but I was not able to find a solution of that.
Another problem I found with karate is differentiating the behavior using a local or a remote webdriver as in the features files they're set in different ways.
So does anyone had my same needs and how can I solve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 Peter Thomas 的建议,我使用了这个 karate-config.js
通过这种方式,我能够调用测试套件,指定直接从命令行使用的浏览器(在 Jenkins 管道中使用):
With the suggestions of Peter Thomas I used this karate-config.js
In this way I was able to call the the test suite specifying the browser to use directly from the command line (to be used in a Jenkins pipeline):
这里有几个原则。 Karate 负责启动
driver
(相当于 SeleniumWebDriver
)。您需要做的就是按照此处所述设置配置驱动程序
:https://github.com/intuit/karate/tree/master/karate-core#configure-driver最后,根据您的环境,只需切换驱动程序配置即可。这实际上可以在 karate-config.js 中(全局)轻松完成,而不是在每个功能文件中:
在命令行上:
我建议您熟悉空手道的配置:https://github.com/intuit/karate#configuration - 它实际上比典型的 Java / Maven 更简单项目。
另一种方法是在 karate-config.js 中设置变量,然后在功能文件中使用它们。
请记住这些原则:
不需要任何其他模式。
编辑:文档中有更多详细信息: https:// github.com/intuit/karate/tree/develop/karate-core#code-reuse
对于并行执行或尝试在所有测试中重复使用单个浏览器,请参阅:https://stackoverflow.com/a/60387907/143475
Here are a couple of principles. Karate is responsible for starting the
driver
(the equivalent of the SeleniumWebDriver
). All you need to do is set up theconfigure driver
as described here: https://github.com/intuit/karate/tree/master/karate-core#configure-driverFinally, depending on your environment, just switch the driver config. This can easily be done in
karate-config.js
actually (globally) instead of in each feature file:And on the command-line:
I suggest you get familiar with Karate's configuration: https://github.com/intuit/karate#configuration - it actually ends up being simpler than typical Java / Maven projects.
Another way is to set variables in the
karate-config.js
and then use them in feature files.Keep these principles in mind:
You don't need any other patterns.
EDIT: there's some more details in the documentation: https://github.com/intuit/karate/tree/develop/karate-core#code-reuse
And for parallel execution or trying to re-use a single browser for all tests, refer: https://stackoverflow.com/a/60387907/143475