How do I specify the browsers in my cucumber.yml files?

守給你的承諾、 提交于 2019-12-13 04:39:42

问题


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

How can I do that?


回答1:


You could add an environment variable for the browser type. Then in your test, use that variable to determine the browser to create.

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

default: BROWSER=chrome
firefox: BROWSER=firefox

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

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.

When you use the profile, it will use the specified browser.

To run the tests in chrome:

cucumber

To run the tests in firefox:

cucumber -p firefox


来源:https://stackoverflow.com/questions/18833071/how-do-i-specify-the-browsers-in-my-cucumber-yml-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!