Running cucumber tests in different environments

I use Cucumber and Capybara for my automatic front-end tests.

I have two environments in which I would like to run my tests. One of them is an intermediate environment, and the other is a production environment.

I currently have my tests written for direct access to the script.

visit('https://staging.somewhere.com') 

I would like to reuse tests in production ( https://production.somewhere.com ).

Is it possible to save the url in a variable in step definitions

 visit(domain) 

and define a domain using an environment variable called a command line form? how

 $> bundle exec cucumber features DOMAIN=staging 

if I want to specify tests on my intermediate environment or

 $> bundle exec cucumber features DOMAIN=production 

if i want it to work in the production process?

How do I set this up? I am new to Ruby and I was looking for forums for direct information, but could not find. Let me know if I can provide more information. Thank you for your help!

+6
source share
2 answers

In the project configuration file, create the config.yml file

 --- staging: :url: https://staging.somewhere.com production: :url: https://production.somewhere.com 

Then the extra colon in the yml file allows you to call the hash key as a character.

In the file support / env.rb add the following

 require 'yaml' ENV['TEST_ENV'] ||= 'staging' project_root = File.expand_path('../..', __FILE__) $BASE_URL = YAML.load_file(project_root + "/config/config.yml")[ENV['TEST_ENV']][:url] 

By default, this will be an intermediate environment unless you override TEST_ENV. Then, from your step or hook, you can call:

 visit($BASE_URL) 

or you may need: /

 visit "#{$BASE_URL}" 

This will allow you to use

 bundle exec cucumber features TEST_ENV=production 
+7
source

I do not use cucumber much, but you should be able to do

 bundle exec cucumber features DOMAIN=staging 

then in your tests use ENV['DOMAIN'] || YOUR_DEFAULT_DOMAIN ENV['DOMAIN'] || YOUR_DEFAULT_DOMAIN to use this variable. YOUR_DEFAULT_DOMAIN will probably be your test environment.

See here

+1
source

Source: https://habr.com/ru/post/974762/


All Articles