如何在我的cucumber.yml文件中指定浏览器? [英] How do I specify the browsers in my cucumber.yml files?

查看:366
本文介绍了如何在我的cucumber.yml文件中指定浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建黄瓜个人资料并指定我想在我的个人资料中运行测试的浏览器。例如我的cucumber.yml看起来像:

I want to create cucumber profiles and specify the browsers I want to run the tests on in my profiles. For example my cucumber.yml looks like:

default: @chrome --tags @sanity1 --require features
firefox: @ff--tags @sanity1 --require features

p>

推荐答案

您可以添加环境变量

例如,您可以在您的cucumber.yml个人资料中添加BROWSER变量:

For example, you could add a BROWSER variable to your cucumber.yml profiles:

default: BROWSER=chrome
firefox: BROWSER=firefox

然后,当你创建一个浏览器,说在前钩,你会检查ENV变量:

Then when you create a browser, say in the before hook, you would check the ENV variable:

Before do
    @browser = Watir::Browser.new ENV['BROWSER']
end

请注意,如果浏览器值是lowercased,它可以直接传递到Watir :: Browser的初始化。如果你想使用不同的值(例如FIREFOX而不是firefox),你需要使用一个case语句来评估它。

Note that if the browser value is lowercased it can be passed directly into the initialization of the Watir::Browser. If you want to use a different value (eg "FIREFOX" instead of "firefox"), you will need to use a case statement to evaluate it.

要在chrome中运行测试:

To run the tests in chrome:

cucumber

要在firefox中运行测试:

To run the tests in firefox:

cucumber -p firefox

这篇关于如何在我的cucumber.yml文件中指定浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆