Skip to content

Commit 631c3e3

Browse files
authored
fix: 🐛 fixed sample cypress project (#362)
* fix: 🐛 fixed sample cypress project * fix: 🐛 fixed cypress issue in step files
1 parent f87b15e commit 631c3e3

16 files changed

+1514
-20049
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ videos/
1212
screenshots/
1313
downloads/
1414
*.ndjson
15-
dist/
15+
dist/
16+
.run/
2.69 MB
Binary file not shown.
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{
22
"json": {
3-
"enabled": true
3+
"enabled": true,
4+
"formatter": ".bin/cucumber-json-formatter",
5+
"output": ".run/reports/json/cucumber-report.json"
46
},
57
"messages": {
6-
"enabled": false
8+
"enabled": true,
9+
"output": ".run/reports/messages/cucumber-report.json"
710
},
811
"stepDefinitions": ["cypress/e2e/[filepath].step.{js,ts}"]
912
}

examples/cypress/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Sample Cypress Cucumber
2+
3+
This is a sample project for Cypress and Cucumber with Multiple HTML Cucumber Reporter.
4+
5+
## Setup
6+
7+
Install PNPM by following the guide [here](https://pnpm.io/installation).
8+
9+
## Run the Test
10+
11+
Install the dependencies by running the following command:
12+
13+
```shell
14+
pnpm install
15+
```
16+
17+
Run the tests by using the following command:
18+
19+
```shell
20+
pnpm test
21+
```
22+
23+
Generate the HTML reporter by using the following command:
24+
25+
```shell
26+
pnpm report
27+
```

examples/cypress/cucumber-html-report.js

Lines changed: 0 additions & 73 deletions
This file was deleted.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { generate } from "multiple-cucumber-html-reporter";
2+
import dayjs from "dayjs";
3+
import { readFileSync } from "fs";
4+
5+
const data = readFileSync("./.run/results.json", {
6+
encoding: "utf8",
7+
flag: "r",
8+
});
9+
const runInfos = JSON.parse(data);
10+
11+
let mapOs = (os: string) => {
12+
if (os.startsWith("win")) {
13+
return "windows";
14+
} else if (os.startsWith("darwin")) {
15+
return "osx";
16+
} else if (os.startsWith("linux")) {
17+
return "linux";
18+
} else if (os.startsWith("ubuntu")) {
19+
return "ubuntu";
20+
} else if (os.startsWith("android")) {
21+
return "android";
22+
} else if (os.startsWith("ios")) {
23+
return "ios";
24+
}
25+
};
26+
27+
generate({
28+
jsonDir: "./.run/reports/json/",
29+
reportPath: "./.run/html-report/",
30+
openReportInBrowser: true,
31+
metadata: {
32+
browser: {
33+
name:
34+
runInfos.browserName === "chromium" ? "chrome" : runInfos.browserName,
35+
version: runInfos.browserVersion,
36+
},
37+
platform: {
38+
name: mapOs(runInfos.osName),
39+
version: runInfos.osVersion,
40+
},
41+
},
42+
customData: {
43+
title: "Run Info",
44+
data: [
45+
{ label: "Project", value: "Sample " },
46+
{ label: "Release", value: "1.0.0" },
47+
{ label: "Cypress Version", value: runInfos["cypressVersion"] },
48+
{ label: "Node Version", value: runInfos["nodeVersion"] },
49+
{
50+
label: "Execution Start Time",
51+
value: dayjs(runInfos["startedTestsAt"]).format(
52+
"YYYY-MM-DD HH:mm:ss.SSS"
53+
),
54+
},
55+
{
56+
label: "Execution End Time",
57+
value: dayjs(runInfos["endedTestsAt"]).format(
58+
"YYYY-MM-DD HH:mm:ss.SSS"
59+
),
60+
},
61+
],
62+
},
63+
pageTitle: "Sample",
64+
reportName: "Sample",
65+
displayDuration: true,
66+
displayReportTime: true,
67+
});

examples/cypress/cypress.config.js

Lines changed: 0 additions & 73 deletions
This file was deleted.

examples/cypress/cypress.config.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { defineConfig } from "cypress";
2+
import { writeFileSync } from "fs";
3+
import createBundler from "@bahmutov/cypress-esbuild-preprocessor";
4+
import {
5+
addCucumberPreprocessorPlugin,
6+
afterRunHandler,
7+
} from "@badeball/cypress-cucumber-preprocessor";
8+
import { createEsbuildPlugin } from "@badeball/cypress-cucumber-preprocessor/esbuild";
9+
10+
async function setupNodeEvents(
11+
on: Cypress.PluginEvents,
12+
config: Cypress.PluginConfigOptions
13+
): Promise<Cypress.PluginConfigOptions> {
14+
await addCucumberPreprocessorPlugin(on, config);
15+
16+
on(
17+
"file:preprocessor",
18+
createBundler({
19+
plugins: [createEsbuildPlugin(config)],
20+
})
21+
);
22+
on(
23+
"after:run",
24+
async (
25+
results:
26+
| CypressCommandLine.CypressRunResult
27+
| CypressCommandLine.CypressFailedRunResult
28+
): Promise<void> => {
29+
if (results) {
30+
await afterRunHandler(config);
31+
writeFileSync(".run/results.json", JSON.stringify(results));
32+
}
33+
}
34+
);
35+
36+
return config;
37+
}
38+
39+
export default defineConfig({
40+
e2e: {
41+
specPattern: "cypress/e2e/**/*.feature",
42+
setupNodeEvents,
43+
defaultCommandTimeout: 60000,
44+
pageLoadTimeout: 60000,
45+
video: false,
46+
experimentalInteractiveRunEvents: true,
47+
downloadsFolder: "./cypress/.run/downloads",
48+
fixturesFolder: "./cypress/.run/fixtures",
49+
screenshotsFolder: "./cypress/.run/screenshots",
50+
videosFolder: "./cypress/.run/videos",
51+
},
52+
});
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/// <reference types="Cypress"/>
1+
/// <reference types="cypress" />
22

33
import { Given } from "@badeball/cypress-cucumber-preprocessor";
44

5-
Given("I open the gmail", function () {
5+
Given("I open the gmail", () => {
66
cy.visit("https://mail.google.com");
77
});

examples/cypress/cypress/e2e/google/google.step.js renamed to examples/cypress/cypress/e2e/google/google.step.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import { Given } from "@badeball/cypress-cucumber-preprocessor";
44

5-
// Import the necessary modules
6-
7-
Given("I open the google", function () {
5+
Given("I open the google", () => {
86
cy.visit("https://www.google.co.in");
97
});

0 commit comments

Comments
 (0)