问题
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