Skip to content
This repository was archived by the owner on Jan 4, 2019. It is now read-only.

ModusCreateOrg/cucumber-training

Repository files navigation

No longer maintained

[DEPRECATED] This repository is no longer maintained

While this project is fully functional, the dependencies are no longer up to date. You are still welcome to explore, learn, and use the code provided here.

Modus is dedicated to supporting the community with innovative ideas, best-practice patterns, and inspiring open source solutions. Check out the latest Modus Labs projects.

Modus Labs


Cucumber Training


Training project to run WebdriverIO tests with CucumberJS 2. Code is written in ES6 and transpiling is done at runtime using Babel

Requirements

  • Node version 6 or higher

Quick Start

Choose one of the following options:

  1. Clone the git repo — git clone git@github.com:ModusCreateOrg/cucumber-training.git

  2. Clean the project (Optional):

  • On OSX/Linux: -- Run npm run clean

  • On Windows: -- Remove the directories /node_modules & /reports

  1. Install the dependencies (npm install)

Now you are ready to write some features.

Features

  • Super simple setup
  • Full integration with WebdriverIO
  • Full integration with CucumberJS 2
  • Full support for ES6
  • Runtime transpiling with Babel (transpiling is a specific kind of compiling)
  • Integration with cloud services like Sauce Labs

How to Write a Test

Tests are written in Gherkin syntax, a structure that lets you describe software behavior in a business readable, domain specific language. All test files are located in ./features/* and have the file ending .feature. You will already find some test files in that directory. They should demonstrate how tests could look. Just create a new file and write your first test.

landingPage.feature

Feature: Test login
  As a QA
  I want to check login functionality
  by using both valid and invalid test data

  Scenario: Login using valid credentials
    Given I open the site landing page
    When I login using email sergiu@moduscreate.com and password dummyPassword
    Then I am successfully logged in
    And I am redirected to Home page

  Scenario: ...

This test opens the browser and navigates to facebook.com to check if login functionality works as expected with both valid and invalid test data. As you can see, it is pretty simple and understandable for everyone.

How to Run the Tests

To run your tests just call the WDIO runner:

$ node_modules/.bin/wdio wdio.conf.js

Note: The WDIO runner uses the configuration file wdio.conf.js by default. The above can also be translated into the following, though will almost never be used since the conf file will be overridden:

$ node_modules/.bin/wdio

Running a Single Feature

To run a single feature file use the following command:

$ node_modules/.bin/wdio wdio.conf.js --spec ./features/landingPage.feature

For more functionality on organizing suites please take a look here

Configurations

To configure your tests, checkout the wdio.conf.js file in your test directory. It comes with a bunch of documented options you can choose from.

Environment-Specific Configurations

You can setup multiple configs for specific environments. Let's say you want to have a different baseUrl or different test packs for your local and pre-deploy tests.

Use the wdio.conf.js to set all general configs (like cucumberOpts) that don't change. It will be the default or base config file. For each different environment or configuration you can create a new config with the following name scheme:

wdio.<ENVIRONMENT>.conf.js

Now you can create a specific config for your pre-deploy tests:

wdio.PR_VALIDATION.conf.js

var config = require('./wdio.conf.js').config;

config.baseUrl = 'http://localhost:8080';

exports.config = config;

Your environment-specific config file will get merged into the default config file and overwrite the values you set. To run a test in a specific environment just add the desired configuration file as the first parameter:

NOTE: Import does not work at this level as Babel runtime transpiling is not available here.

$ node_modules/.bin/wdio wdio.PR_VALIDATION.conf.js

Adding New Steps and Snippets

In order to benefit from available IDE CucumberJS plugins all step definitions should be stored in /step_definitions. They can be separated by pageObject / functionality / application flows / etc.

Snippet definitions use regular expressions. This is pretty powerful as it allows you to create complex sentences with multiple options. Everything that's within "([^"]*)?" gets captured and appended to the callback. The last argument is always a callback function. You can access the browser and your WebdriverIO instance with browser.

To assert values this training project comes with a Chai integration.

Comments

You can add additional descriptive comments in your feature files.

###
  This is a block comment
  that can spread across multiple lines.
###
Feature: Test login
  As a QA
  I want to check login functionality
  by using both valid and invalid test data

# This is a single line comment
  Scenario: Login using valid credentials
    Given I open the site landing page
    ...

For more information on contributors see:

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •