Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Cucumber tests on different environments

I'm using Cucumber and Capybara for my automated front end tests.

I have two environments that I would like to run my tests on. One is a staging environment, and the other is the production environment.

Currently, I have my tests written to access staging directly.

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

I would like to re-use the tests in production (https://production.somewhere.com).

Would it be possible to store the URL in a variable in my step definitions

visit(domain)

and define domain using an environment variable called form the command line? Like

$> bundle exec cucumber features DOMAIN=staging

if I want to point the tests to my staging environment, or

$> bundle exec cucumber features DOMAIN=production

if I want it to run in production?

How do I go about setting this up? I'm fairly new to Ruby and I've been searching the forums for a straight forward information but could not find any. Let me know if I can provide more information. Thanks for your help!

like image 402
RaymundS Avatar asked Sep 03 '14 16:09

RaymundS


People also ask

What environment is needed for Cucumber test case?

Cucumber supports Java platform for the execution. Step 2 − Accept license agreement. Step 3 − Install JDK and JRE. Step 4 − Set the environment variable as shown in the following screenshots.

How do you run multiple test cases in Cucumber?

Cucumber can be executed in parallel using TestNG and Maven test execution plugins by setting the dataprovider parallel option to true. In TestNG the scenarios and rows in a scenario outline are executed in multiple threads. One can use either Maven Surefire or Failsafe plugin for executing the runners.


1 Answers

In the project's config file, create a config.yml file

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

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

Then extra colon in the yml file allows the hash key to be called as a symbol.

In your support/env.rb file, 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]

This will default to the staging environment unless you override the TEST_ENV. Then, from your step or hook, you can call:

visit($BASE_URL)

or you might need :/

visit "#{$BASE_URL}"

This will allow you to use

bundle exec cucumber features TEST_ENV=production
like image 103
Jarod Adair Avatar answered Nov 15 '22 09:11

Jarod Adair