Passing variables on the command line to a Cucumber test
So, I saw your comments with the Tin Man, and answer is Yes.
cucumber PASSWORD=my_password
PASSWORD is set as an environment variable and you can use its value by referring to it as ENV['PASSWORD']
. For an example, browser.text_field(:id => 'pwd').set ENV['PASSWORD']
Another way is indirect.
What I did in past was to pass profile name and that profile will do something that I want. So, for example, I have a profile name as firefox
and a firefox profile in cucumber.yml has a variable named BROWSER_TYPE
with its value assigned to firefox. And this variable (BROWSER_TYPE
) is used by my method that opens the browser. If its value is firefox, than this method opens firefox browser.
So, what I did here was -
- Pass a profile. Name of the profile is
firefox
- firefox profile is defined in cucumber.yml. You can any thing with the profiles, but in this case, I define a variable named
BROWSER_TYPE
and assign its value as firefox. - Then I have a method that uses
BROWSER_TYPE
variable and uses its value to open browser.
Code for these steps -
cucumber -p firefox
My cucumber.yml file looks like
firefox: BROWSER_TYPE=firefox PLATFORM=beta
My method to open browser looks similar to -
@browser = Watir::Browser.new ENV['BROWSER_TYPE']
So, ideally you can create a profile that sets an environment variable with password, and pass that profile name to cucumber.
How do I pass a CLI argument to a Cucumber Java test suit?
In your method, you can read this value as a system property like this:
@Before
public void server_connection() {
ConnectionToServer serverConnection = new ConnectionToServer(System.getProperty("IPArgumentFromMaven"), 5776);
serverConnection.open();
}
Now you can pass a value for IPArgumentFromMaven to maven from command line like this:
mvn clean test -DIPArgumentFromMaven=localhost
Different arguments per test run with cucumber
cucumber COUNTRY=my_country
then you can get value with
ENV['COUNTRY']
Then you can write
Given I'm from registered on what ever country website
When I login
Then i should receive a ok stats.
in the step definition
@country = ENV['COUNTRY']
and use them like you want
see here
Passing variables on the command line to a Cucumber test
pass special values to Cucumber
The first link show interesting way using cucumber profiles.
Any way to pass custom additional args to cucumber and parse them?
you can use environment variables for this
from: https://github.com/cucumber/cucumber/wiki/Environment-Variables
When you are Running Features it can sometimes be handy to pass
special values to Cucumber so that they can be picked up in your Step
Definitions. You can easily do this on the command line:cucumber FOO=BAR --format progress features You can now pick up
ENV['FOO'] in ruby (for example in env.rb or a step definition) and
take actions according to the value
Related Topics
How to Force To_Yaml to Output Long Strings in Literal Block Style
Ruby Block Taking Array or Multiple Parameters
Dangerousattributeerror in Omniauth Railscast Tutorial: Create Is Defined by Activerecord
Why Is Ruby's Loop Command Slower Than While True
Ruby 2.4 on MAC Os Mojave:Image Not Found ... Related to Openssl.Bundle
How to Http Post Stream Data from Memory in Ruby
Ruby 1.9 - No Such File to Load 'Win32/Open3'
How to Efficiently Extract Repeated Elements in a Ruby Array
Validating Phone Number in Ruby
Why Doesn't Array Override the Triple Equal Sign Method in Ruby
Rails Postgresql Multiple Schemas and the Same Table Name
Conditional Dependency in Ruby Gemspec
What Does "String Literal in Condition" Mean
How to Effectively Force Minitest to Run My Tests in Order
Ssl_Connect Syscall Returned=5 Errno=0 State=Sslv3 Read Server Hello a (Openssl::Ssl::Sslerror)
Can Someone Explain the Following Code to Me
How to Deal with a Page Which Fails to Load and Continue Testing in Watir-Webdriver