Page History
...
We need to configure Cypress to use the the new @badeball/
cypress-cucumber-preprocessor, which provides the ability to understand .feature files and also to produce Cucumber JSON reports.
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
const { defineConfig } = require('cypress') const createBundler = require("@bahmutov/cypress-esbuild-preprocessor"); const createEsbuildPlugin = require('@badeball/cypress-cucumber-preprocessor/esbuild').createEsbuildPlugin; const addCucumberPreprocessorPlugin = require('@badeball/cypress-cucumber-preprocessor').addCucumberPreprocessorPlugin; async function setupNodeEvents(on, config) { await addCucumberPreprocessorPlugin(on, config); on( "file:preprocessor", createBundler({ plugins: [createEsbuildPlugin(config)], }) ); // Make sure to return the config object as it might have been modified by the plugin. return config; } module.exports = defineConfig({ e2e: { baseUrl: "https://robotwebdemo.herokuapp.com/", specPattern: "**/*.feature", excludeSpecPattern: [ "*.js", "*.md" ], chromeWebSecurity: false, projectId: "bfi83g", supportFile: false, setupNodeEvents } }) |
The configuration of @badeball/cypress-cucumber-preprocessor
can either be done on a JSON file .cypress-cucumber-preprocessorrc.json
or within package.json
.
Next, here is an example of the contents of package.json.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
{ "name": "tutorial-js-cypress-cucumber", "version": "1.0.0", "description": "An example for Cypress and Cucumber usage using Robot login demo website", "main": "index.js", "scripts": { "cypress:open:local": "CYPRESS_ENV=localhost npm run cypress:open", "cypress:open:prod": "CYPRESS_ENV=production npm run cypress:open", "cypress:open": "npx cypress open", "test:local": "CYPRESS_ENV=localhost npm run test --spec 'cypress/integration/**/*.feature", "test:prod": "CYPRESS_ENV=production npm run test", "test": "npx cypress run --spec 'features/**/*.feature'", "test:debug:local": "CYPRESS_ENV=localhost npm run test:debug", "test:debug:prod": "CYPRESS_ENV=production npm run test:debug", "test:debug": "npx cypress run --headed --browser chrome --env TAGS='@e2e-test' --spec 'cypress/integration/**/*.feature'" }, "author": "Xblend", "license": "BSD-3-Clause", "dependencies": { "axios": "^0.18.0", "fs-extra": "^7.0.1", "glob": "^7.1.7" }, "devDependencies": { "@badeball/cypress-cucumber-preprocessor": "^13.0.2", "@bahmutov/cypress-esbuild-preprocessor": "^2.1.3", "@cypress/webpack-preprocessor": "latest", "cypress": "^10.8.0", "esbuild": "^0.14.45", "eslint": "^5.13.0", "eslint-config-airbnb-base": "^12.1.0", "eslint-config-prettier": "^2.9.0", "eslint-plugin-cypress": "^2.11.3", "eslint-plugin-import": "^2.23.4", "eslint-plugin-prettier": "^2.6.0", "husky": "^1.3.1", "lint-staged": "^8.1.3" }, "cypress-cucumber-preprocessor": { "json": { "enabled": true, "formatter": "/usr/local/bin/cucumber-json-formatter", "output": "cucumber-report.json" } }, "husky": { "hooks": { "pre-commit": "lint-staged" } }, "lint-staged": { "*.js": [ "eslint", "git add" ] } } |
We need to have the cucumber-json-formatter
tool, which can be downloaded from the respective GitHub repository. Make sure you pick the correct binary for your environment.
This tool is necessary to convert the Cucumber messages protobuf (*.ndjson file) report generated by @badeball/cypress-cucumber-preprocessor
.
Code Block | ||||
---|---|---|---|---|
| ||||
wget https://github.com/cucumber/json-formatter/releases/download/v19.0.0/cucumber-json-formatter-linux-amd64 -O /usr/local/bin/cucumber-json-formatter chmod +x /usr/local/bin/cucumber-json-formatter |
...
No Format |
---|
npm run test
# or instead...
node_modules/cypress/bin/cypress run --spec 'features/**/*.feature' --config integrationFolder= |
This will produce one Cucumber JSON report.
Info | ||
---|---|---|
| ||
To debug your tests while developing them, you can execute cypress with DEBUG enabled:
|
After running the tests, results can be imported to Xray via the REST API, or the Import Execution Results action within the Test Execution, or by using one of the available CI/CD plugins (e.g. see an example of Integration with Jenkins).
...