项目作者: ModusCreateOrg

项目描述 :
Cucumber Training
高级语言: JavaScript
项目地址: git://github.com/ModusCreateOrg/cucumber-training.git
创建时间: 2017-07-12T14:44:40Z
项目社区:https://github.com/ModusCreateOrg/cucumber-training

开源协议:

下载


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

  1. Feature: Test login
  2. As a QA
  3. I want to check login functionality
  4. by using both valid and invalid test data
  5. Scenario: Login using valid credentials
  6. Given I open the site landing page
  7. When I login using email sergiu@moduscreate.com and password dummyPassword
  8. Then I am successfully logged in
  9. And I am redirected to Home page
  10. 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:

  1. $ 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:

  1. $ node_modules/.bin/wdio

Running a Single Feature

To run a single feature file use the following command:

  1. $ 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:

  1. wdio.<ENVIRONMENT>.conf.js

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

wdio.PR_VALIDATION.conf.js

  1. var config = require('./wdio.conf.js').config;
  2. config.baseUrl = 'http://localhost:8080';
  3. 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.

  1. $ 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.

  1. ###
  2. This is a block comment
  3. that can spread across multiple lines.
  4. ###
  5. Feature: Test login
  6. As a QA
  7. I want to check login functionality
  8. by using both valid and invalid test data
  9. # This is a single line comment
  10. Scenario: Login using valid credentials
  11. Given I open the site landing page
  12. ...

For more information on contributors see: