Skip to content

Commit 92cb0d6

Browse files
authored
Merge pull request #161 from Breeding-Insight/feature/BI-2502
Feature/bi 2502
2 parents acbb18d + 010ba62 commit 92cb0d6

26 files changed

Lines changed: 2321 additions & 1711 deletions

.github/workflows/daily-test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ jobs:
159159
if: (github.event.inputs.suite=='smoke')
160160
run: npm run test:chromeDaily
161161

162+
- name: Run HTML Report generator
163+
run: npm run report
164+
162165
- name: Publish Report Artifact
163166
uses: actions/upload-artifact@v4
164167
if: always()

.github/workflows/test-branch.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ jobs:
173173
if: (github.event.inputs.suite=='smoke')
174174
run: npm run test:chromeDaily
175175

176+
- name: Run HTML Report generator
177+
run: npm run report
178+
176179
- id: biWebBranch
177180
run: INPUT=${{ github.event.inputs.biweb }} && echo "::set-output name=branch::${INPUT/\//-}"
178181

.vscode/launch.json

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
{
2-
// Use IntelliSense to learn about possible attributes.
3-
// Hover to view descriptions of existing attributes.
4-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
52
"version": "0.2.0",
63
"configurations": [
74
{
85
"type": "node",
96
"request": "launch",
10-
"name": "Debug",
7+
"name": "Debug Cucumber Tests",
118
"program": "${workspaceRoot}/node_modules/@cucumber/cucumber/bin/cucumber-js",
129
"args": [
13-
"${workspaceRoot}/src/features",
14-
"--require",
15-
"cucumber.conf.js",
16-
"--require",
17-
"src/step_definitions",
18-
"--world-parameters",
19-
"{\"browser\":\"chrome\",\"launch_url\":\"http://localhost\"}",
20-
"--format",
21-
"json:report/cucumber_report.json",
22-
"--tags",
23-
"@debug"
24-
]
10+
"--require", "cucumber.conf.js",
11+
"--require", "src/step_definitions",
12+
"src/features",
13+
"--format", "json:report/cucumber_report.json",
14+
"--tags", "@debug"
15+
],
16+
"console": "integratedTerminal",
17+
"skipFiles": ["<node_internals>/**"],
18+
"env": {
19+
"NODE_ENV": "test"
20+
},
21+
"runtimeArgs": ["--inspect-brk"]
2522
}
2623
]
27-
}
24+
}

cucumber.conf.js

Lines changed: 105 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,120 @@
1-
const fs = require("fs");
1+
const Nightwatch = require("nightwatch");
22
const {
3-
setDefaultTimeout,
43
After,
54
AfterAll,
6-
BeforeAll,
75
Before,
6+
setDefaultTimeout,
87
} = require("@cucumber/cucumber");
9-
const {
10-
createSession,
11-
closeSession,
12-
startWebDriver,
13-
stopWebDriver,
14-
getNewScreenshots,
15-
saveScreenshot,
16-
} = require("nightwatch-api");
8+
const fs = require("fs");
9+
const fsPromises = fs.promises;
10+
const path = require("path");
11+
const os = require("os");
1712
const reporter = require("cucumber-html-reporter");
18-
const { client } = require("nightwatch-api");
19-
const run = {
20-
browserName: "",
21-
platform: "",
22-
version: "",
23-
BreedingInsight: "",
24-
};
25-
26-
setDefaultTimeout(600000);
27-
global.__basedir = __dirname;
28-
29-
Before(async function () {
30-
await createSession({ env: this.parameters.browser });
31-
await client.resizeWindow(1900, 1200);
32-
this.parameters.timeStamp = Date.now();
33-
if (process.env.npm_config_url != undefined) {
34-
this.parameters.launch_url = process.env.npm_config_url;
13+
14+
require("events").EventEmitter.defaultMaxListeners = 20;
15+
setDefaultTimeout(300000);
16+
17+
Before(async function ({ pickle }) {
18+
fs.mkdirSync("report", { recursive: true });
19+
fs.mkdirSync("screenshots", { recursive: true });
20+
21+
this.tmpUserDataDir = fs.mkdtempSync(
22+
path.join(os.tmpdir(), "nw-chrome-profile-")
23+
);
24+
console.log("tmpUserDataDir:", this.tmpUserDataDir);
25+
26+
const chromeArgs = [
27+
"--no-sandbox",
28+
"--disable-dev-shm-usage",
29+
"--disable-extensions",
30+
"--disable-gpu",
31+
"--disable-background-networking",
32+
"--disable-sync",
33+
"--metrics-recording-only",
34+
"--disable-default-apps",
35+
"--mute-audio",
36+
"--no-first-run",
37+
"--ignore-certificate-errors",
38+
"--allow-insecure-localhost",
39+
"--window-size=1920,1080",
40+
"--headless=new",
41+
];
42+
43+
const webdriver = {};
44+
if (this.parameters["webdriver-host"])
45+
webdriver.host = this.parameters["webdriver-host"];
46+
if (this.parameters["webdriver-port"])
47+
webdriver.port = this.parameters["webdriver-port"];
48+
if (typeof this.parameters["start-process"] !== "undefined")
49+
webdriver.start_process = this.parameters["start-process"];
50+
51+
const globals = {};
52+
if (this.parameters["retry-interval"]) {
53+
globals.waitForConditionPollInterval = this.parameters["retry-interval"];
3554
}
36-
});
3755

38-
BeforeAll(async () => {
39-
await startWebDriver();
40-
});
56+
this.client = Nightwatch.createClient({
57+
headless: this.parameters.headless,
58+
env: this.parameters.env,
59+
timeout: this.parameters.timeout,
60+
parallel: !!this.parameters.parallel,
61+
output: !this.parameters["disable-output"],
62+
enable_global_apis: true,
63+
silent: !this.parameters.verbose,
64+
always_async_commands: true,
65+
webdriver,
66+
persist_globals: this.parameters["persist-globals"],
67+
config: this.parameters.config,
68+
globals: {
69+
run: {},
70+
},
71+
desiredCapabilities: {
72+
browserName: "chrome",
73+
"goog:chromeOptions": {
74+
args: chromeArgs,
75+
},
76+
},
77+
});
4178

42-
AfterAll(async () => {
43-
run.browserName = client.capabilities.browserName;
44-
switch (client.capabilities.browserName) {
45-
case "msedge": //same as chrome
46-
case "chrome-headless-shell":
47-
case "chrome":
48-
run.version = client.capabilities.version;
49-
run.platform = client.capabilities.platform;
50-
break;
51-
case "firefox":
52-
run.version = client.capabilities.browserVersion;
53-
run.platform = client.capabilities.platformName;
54-
break;
55-
default:
56-
throw new Error("Unrecognized browser.");
79+
if (this.client.settings.sync_test_names) {
80+
this.client.updateCapabilities({ name: pickle.name });
5781
}
58-
await stopWebDriver();
5982

60-
// convert JSON object to string
61-
const data = JSON.stringify(run);
83+
console.log("Launching Chrome with args: ", chromeArgs);
84+
console.log("Executing test : " + pickle.name);
6285

63-
// write JSON string to a file
64-
fs.writeFile("run.json", data, (err) => {
65-
if (err) {
66-
throw err;
67-
}
68-
console.log("JSON data is saved.");
69-
});
86+
this.browser = await this.client.launchBrowser();
87+
this.browser.globals.timestamp = Date.now();
7088
});
7189

72-
After(function () {
73-
if (run.BreedingInsight == "") {
74-
run.BreedingInsight = client.globals.breedingInsightVersion;
90+
After(async function (testCase) {
91+
if (testCase.result.status === "FAILED" && this.browser) {
92+
const filename = `screenshots/${testCase.pickle.name}-${Date.now()}.png`;
93+
await this.browser.saveScreenshot(filename);
94+
this.attach(fs.readFileSync(filename), "image/png");
7595
}
76-
77-
getNewScreenshots().forEach((file) =>
78-
this.attach(fs.readFileSync(file), "image/png")
79-
);
80-
//Note: The following line can be commented out to keep browsers open for debugging purposes on local
81-
closeSession();
82-
});
96+
97+
if (this.browser) {
98+
await this.browser.quit();
99+
}
100+
101+
if (this.tmpUserDataDir) {
102+
fs.rmSync(this.tmpUserDataDir, { recursive: true, force: true });
103+
}
104+
105+
if (!this.browser?.globals?.run?.browserName) {
106+
const caps = this.browser.capabilities;
107+
const globalsRun = this.browser.globals.run;
108+
109+
globalsRun.browserName = caps.browserName;
110+
globalsRun.version = caps.browserVersion;
111+
globalsRun.platform = caps.platformName;
112+
113+
try {
114+
await fsPromises.writeFile("report/run.json", JSON.stringify(globalsRun));
115+
console.log("Saved run metadata.");
116+
} catch (err) {
117+
console.error("Error saving run metadata:", err);
118+
}
119+
}
120+
});

0 commit comments

Comments
 (0)