Run testcafe tests with gherkin syntax
Maintenance of this package has been moved to: https://github.com/kiwigrid/gherkin-testcafe
Thank you very much @Lukas-Kullmann for being so kind to take care of this package ❤️
- Wilhelm Behncke - [email protected]
The development and the public-releases of this package is generously sponsored by our employer https://www.sitegeist.de.
This package is inspired by helen-dikareva/testcafe-cucumber-demo. The test example for the google search is taken from there.
Currently, this tool is still under development and very likely to break.
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.
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.
With npm:
npm install --save-dev gherkin-testcafe
With yarn:
yarn add --dev gherkin-testcafe
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
--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
- Start up the container for the test runner
docker run --name testrunner -v $(pwd)/specs:/test/specs sitegeist/gherkin-testcafe
- Execute the tests
docker exec testrunner gherkin-testcafe --specs ./specs/**/*.feature --steps ./specs/**/*.js --browsers firefox
- 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"
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.
see LICENSE.md