2.1.0-beta.4 • Published 6 years ago

cypress-scenario-runner v2.1.0-beta.4

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

Cypress Scenario Runner npm version Build Status

Run Gherkin scenarios with Cypress without a single line of code.

By adding a few HTML attributes:

<input … data-test="email input" />
<input … data-test="password input" />
<button … data-test="login button">Login</button>

Cypress Scenario Runner can run Gherkin scenarios without any Cypress code like cy.visit(), cy.click():

Feature: Login
===

Scenario: Successful login
---
Given I navigate to "login"
And I set "email input" to "name@example.com"
And I set "password input" to "abc123"
When I click "login button"
Then I should be on "home"

Table of contents

Installation

Cypress Scenario Runner requires Node.js v8.0+, cypress, and cypress-cucumber-preprocessor.

npm install --save-dev cypress cypress-cucumber-preprocessor cypress-scenario-runner

Configuration

TBD

Installation & setup

  1. Install packages
  2. Set up Cypress
  3. Set up Cypress Scenario Runner

NOTE: Cypress Scenario Runner requires Node.js v8.0+

1. Install packages

Install cypress-scenario-runner and its dependencies, cypress and cypress-cucumber-preprocessor:

npm install --save-dev cypress cypress-cucumber-preprocessor cypress-scenario-runner

2. Set up Cypress

Follow the setup instructions for Cypress and launch its GUI at least once in order to create the initial Cypress directory structure.

3. Set up cypress-scenario-runner

Edit the Cypress plugins file:

const cucumber = require('cypress-cucumber-preprocessor').default

module.exports = (on, config) => {
	on('file:preprocessor', cucumber())
}

Edit the Cypress support file:

const { addCommands } = require('cypress-scenario-runner')
addCommands()

Create a new file at cypress/support/step_definitions/index.js:

const { addSteps } = require('cypress-scenario-runner')
addSteps()

Now you're ready to begin writing test scenarios.

Usage

Writing test scenarios

Test scenarios are written in Gherkin syntax which looks like this:

Feature: Login
===

Scenario: Successful login
---
Given I navigate to "login"
And I set "email input" to "name@example.com"
And I set "password input" to "abc123"
When I click "login button"
Then I should be on "home"

Each given/when/then/and line is called a "step". cypress-scenario-runner works by using a comprehensive set of reusable step templates that have already been implemented behind the scenes:

StepDescription
I navigate to {route}
I click {element}
I set {element} to {string}
I set:
I wait for {element} to disappear
I wait {float} seconds
I pause
I debug
I should be on {route}
I should not be on {route}
{element} should be visible
{element} should not be visible
{element} should have {int} occurrences
{element} should be {string}
elements should be:
{element} should be set to {string}
{element} should not be {string}
{element} should contain {string}
elements should contain:
{element} should not contain {string}

Parameters appear in {brackets} in step templates and in "double quotes" in the scenario. For example, this step:

And I set "email input" to "name@example.com"

corresponds to this step template:

I set {element} to {string}

where:

{element} = email input
{string}  = name@example.com

In addition, the full Gherkin specification is supported along with additional enhancements by cypress-cucumber-preprocessor. For instance, you can use scenario templates/outlines, data tables, and tags in your scenarios.

See the cypress/integration/ directory for more examples.

Annotating HTML elements

HTML attributes are used to map the {element} step parameters to their corresponding HTML elements. data-test is used by default, but this is configurable.

<!-- login.html -->
<input name="email" data-test="email input" />
<input name="password" data-test="password input" />
<button type="submit" data-test="login button">Login</button>

Setting routes

Routes need to provided for navigation steps like these to work:

Given I navigate to "login"

A map of all label => path routes should be provided to addSteps() in the cypress/support/step_definitions/index.js file created during installation. Route paths can be relative to the web root or absolute URLs.

const { addSteps } = require('cypress-scenario-runner')
addSteps({
+	routes: {
+		login: '/login',
+	},
})

Running scenarios

Scenario files can be run directly with Cypress:

$(npm bin)/cypress run [files]

or, using the Cypress UI:

$(npm bin)/cypress open

Customization

Coming soon.

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.1.0-beta.5

6 years ago

2.1.0-beta.4

6 years ago

2.1.0-beta.3

6 years ago

2.1.0-beta.2

6 years ago

2.1.0-beta.1

6 years ago

2.1.0-beta.0

6 years ago

2.0.0

6 years ago

2.0.0-beta.1

6 years ago

2.0.0-beta.0

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.6

6 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.5.3

8 years ago

0.5.2

8 years ago

0.5.1

8 years ago

0.5.0

8 years ago

0.4.0

8 years ago