theodo / gherkin-testcafe

Run testcafe tests with gherkin syntax

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gherkin-testcafe

Run testcafe tests with gherkin syntax

Authors & Sponsors

The development and the public-releases of this package is generously sponsored by our employer http://www.sitegeist.de.

This package is inspired by helen-dikareva/testcafe-cucumber-demo. The test example for the google search is taken from there.

Support

Currently, this tool is still under development and very likely to break.

Why?

DevExpress' testcafe is an amazing tool for writing acceptance tests. Unfortunately it currently lacks support for BDD-style tests using the famous gherkin Syntax (Although there seem to be plans for future support).

This tool provides a setup in which gherkin *.feature specs can be used to run testcafe tests.

What does this do?

The tool itself has just a small footprint to glue testcafe and gherkin together.

It uses testcafe as the testrunner and constructs the fixture and test calls from gherkin sources during runtime.

To interpret *.feature files written in gherkin, it uses the gherkin package from npm. To allow custom step definitions it uses the cucumber-expressions package from npm. Both of those packages are provided by the cucumber project.

Installation

With npm:

npm install --save-dev gherkin-testcafe

With yarn:

yarn add --dev gherkin-testcafe

Usage with CLI

Take a look at the examples/ folder in this repo, to get an idea of how to write gherkin specs and step definitions.

Example:

gherkin-testcafe --specs ./tests/**/*.feature --steps ./tests/**/*.js --browers chromium firefox

Supported Parameters

--specs [list of file patterns] - One or more paths or glob patterns to the *.feature files to be tested.

--steps [list of file patterns] - One or more paths or glob patterns to the *.js files containing the step definitions.

--browsers - A space-separated list of browsers to run the tests in (see Testcafe Browser Support)

--ports - Up to 2 ports that will be used by testcafe to serve tested webpages

Usage with docker

  1. Start up the container for the test runner
docker run --name testrunner -v $(pwd)/specs:/test/specs sitegeist/gherkin-testcafe
  1. Execute the tests
docker exec testrunner gherkin-testcafe --specs ./specs/**/*.feature --steps ./specs/**/*.js --browsers firefox
  1. Clean up
docker kill testrunner
docker rm testrunner

All parameters of the command line interface can be used, but the the list of browsers is limited to:

  • firefox
  • "chromium --no-sandbox"

Writing step definitions

With the --steps parameter you can specify where to find your step definitions. These are contained in a file of the following form:

module.exports = function defineSteps({given, when, then}) {
	given(`I have a step definition with parameter {string}`, (t, myParameter) => {
		// Test implementation here
	});
}

given, when and then refer to their gherkin counterparts. Each of these functions takes two parameters.

The first one expects a parameterized step expression. You'll find more on that in the cucumber-expressions Documentation.

The second one expects a function (that is allowed to be be async), which executes the actual test. That function will get the testcafe test controller as its first parameter (t in the example). With that you can use the entirety of test cafes Test API.

All subsequent parameters for the test function are resolved from the given step expression.

License

see LICENSE.md

About

Run testcafe tests with gherkin syntax

License:MIT License


Languages

Language:JavaScript 95.0%Language:Shell 5.0%