Skip to content

Commit

Permalink
Tests: Enable cypress to run cucumber tests
Browse files Browse the repository at this point in the history
Add libraries needed to run cucumber tests with cypress,
namely cypress-cucumber-preprocessor and cypress-esbuild-preprocessor
in order to translate gherkin steps to cypress executable test.

Configure cypress to run the gherkin tests.

Signed-off-by: Michal Polovka <mpolovka@redhat.com>
  • Loading branch information
miskopo committed Jul 21, 2023
1 parent 524c38f commit a46407b
Show file tree
Hide file tree
Showing 8 changed files with 9,701 additions and 13,370 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/gating.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ jobs:
run: vagrant provision

- name: Run Cypress tests
uses: cypress-io/github-action@v4
uses: cypress-io/github-action@v5
with:
build: npm run build
start: npm run serve
browser: firefox

- name: Upload cypress screenshots
uses: actions/upload-artifact@v2
Expand Down
23 changes: 19 additions & 4 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
import { defineConfig } from "cypress";
import createBundler from "@bahmutov/cypress-esbuild-preprocessor";
import { addCucumberPreprocessorPlugin } from "@badeball/cypress-cucumber-preprocessor";
import createEsbuildPlugin from "@badeball/cypress-cucumber-preprocessor/esbuild";

export default defineConfig({
e2e: {
baseUrl: "https://server.ipa.demo/ipa/modern_ui/",
},
hosts: {
"server.ipa.demo": "127.0.0.1",
specPattern: "**/*.feature",
baseUrl: "http://localhost:3000/",

async setupNodeEvents(
on: Cypress.PluginEvents,
config: Cypress.PluginConfigOptions
): Promise<Cypress.PluginConfigOptions> {
await addCucumberPreprocessorPlugin(on, config);
on(
"file:preprocessor",
createBundler({
plugins: [createEsbuildPlugin(config)],
})
);
return config;
},
},
});
5 changes: 5 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const cucumber = require("cypress-cucumber-preprocessor").default;

module.exports = (on, config) => {
on("file:preprocessor", cucumber());
};
23,005 changes: 9,643 additions & 13,362 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@
"typescript": "^4.7.4",
"webpack": "^5.76.2",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.9.3"
"webpack-dev-server": "^4.9.3",
"@badeball/cypress-cucumber-preprocessor": "^18.0.1",
"@bahmutov/cypress-esbuild-preprocessor": "^2.2.0"
},
"cypress-cucumber-preprocessor": {
"stepDefinitions": [
"tests/features/steps/*.{js,ts}"
]
}
}
7 changes: 7 additions & 0 deletions tests/features/steps/test_webui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { When, Then, Given } from "@badeball/cypress-cucumber-preprocessor";
When("I am on the home page", () => {
cy.visit("/");
})
Then("I should be on the page {string}", function(pageName) {
cy.location('pathname').should('contain', pageName);
});
6 changes: 6 additions & 0 deletions tests/features/test_sanity.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Basic sanity
Teste if the application loads

Scenario: Load the landing page
When I am on the home page
Then I should be on the page "active-users"
10 changes: 8 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"baseUrl": ".",
"rootDir": ".",
"outDir": "dist",
"target": "es5",
"target": "ES2015",
"lib": ["es6", "dom"],
"sourceMap": true,
"jsx": "react",
Expand All @@ -18,7 +18,13 @@
"importHelpers": true,
"skipLibCheck": true,
"noEmit": false,
"resolveJsonModule": true
"resolveJsonModule": true,
"moduleResolution": "node",
"paths": {
"@badeball/cypress-cucumber-preprocessor/*": [
"./node_modules/@badeball/cypress-cucumber-preprocessor/dist/subpath-entrypoints/*"
]
}
},
"exclude": ["node_modules"]
}

0 comments on commit a46407b

Please sign in to comment.