-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcucumber.conf.js
82 lines (74 loc) · 1.97 KB
/
cucumber.conf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const fs = require("fs");
const {
setDefaultTimeout,
After,
AfterAll,
BeforeAll,
Before,
} = require("@cucumber/cucumber");
const {
createSession,
closeSession,
startWebDriver,
stopWebDriver,
getNewScreenshots,
saveScreenshot,
} = require("nightwatch-api");
const reporter = require("cucumber-html-reporter");
const { client } = require("nightwatch-api");
const run = {
browserName: "",
platform: "",
version: "",
BreedingInsight: "",
};
setDefaultTimeout(600000);
global.__basedir = __dirname;
Before(async function () {
await createSession({ env: this.parameters.browser });
await client.resizeWindow(1900, 1200);
this.parameters.timeStamp = Date.now();
if (process.env.npm_config_url != undefined) {
this.parameters.launch_url = process.env.npm_config_url;
}
});
BeforeAll(async () => {
await startWebDriver();
});
AfterAll(async () => {
run.browserName = client.capabilities.browserName;
switch (client.capabilities.browserName) {
case "msedge": //same as chrome
case "chrome-headless-shell":
case "chrome":
run.version = client.capabilities.version;
run.platform = client.capabilities.platform;
break;
case "firefox":
run.version = client.capabilities.browserVersion;
run.platform = client.capabilities.platformName;
break;
default:
throw new Error("Unrecognized browser.");
}
await stopWebDriver();
// convert JSON object to string
const data = JSON.stringify(run);
// write JSON string to a file
fs.writeFile("run.json", data, (err) => {
if (err) {
throw err;
}
console.log("JSON data is saved.");
});
});
After(function () {
if (run.BreedingInsight == "") {
run.BreedingInsight = client.globals.breedingInsightVersion;
}
getNewScreenshots().forEach((file) =>
this.attach(fs.readFileSync(file), "image/png")
);
//Note: The following line can be commented out to keep browsers open for debugging purposes on local
closeSession();
});