-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcypress.config.js
103 lines (94 loc) · 2.74 KB
/
cypress.config.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const { defineConfig } = require("cypress");
const webpack = require("@cypress/webpack-preprocessor");
const preprocessor = require("@badeball/cypress-cucumber-preprocessor");
const { createUser } = require("./scripts/runSchoolApi");
const path = require("path");
async function setupNodeEvents(on, config) {
const isCI = config.env.environmentName === "ci";
if (isCI) {
const environmentFilename = `./env_variables/combined_credentials.json`;
const settings = require(environmentFilename);
if (settings) {
config.env = {
...config.env,
...settings,
};
}
} else {
const environmentName = config.env.environmentName || "local";
const environmentFilename = `./env_variables/${environmentName}.env.json`;
console.log("loading %s", environmentFilename);
const settings = require(environmentFilename);
if (settings.env) {
config.env = {
...config.env,
...settings.env,
};
}
console.log("loaded settings for environment %s", environmentName);
}
const parallelGroup = config.env.parallelGroup || "";
config.env.jsonOutput = `logs/${parallelGroup}/json-report.json`;
config.videosFolder = path.join("cypress", "videos", parallelGroup);
config.screenshotsFolder = path.join("cypress", "screenshots", parallelGroup);
// This is required for the preprocessor to be able to generate JSON reports after each run, and more,
await preprocessor.addCucumberPreprocessorPlugin(on, config);
on(
"file:preprocessor",
webpack({
webpackOptions: {
resolve: {
extensions: [".ts", ".js"],
},
module: {
rules: [
{
test: /\.feature$/,
use: [
{
loader: "@badeball/cypress-cucumber-preprocessor/webpack",
options: config,
},
],
},
],
},
},
})
);
on("task", {
async loginViaSchoolApi(obj) {
try {
return ({ schoolId, username, initialPassword } = await createUser(
obj.url,
obj.apiKey,
obj.schoolId,
obj.userType
));
} catch (error) {
console.error("Error in calling createUser method:", error);
throw error;
}
},
});
// Make sure to return the config object as it might have been modified by the plugin.
return config;
}
module.exports = defineConfig({
viewportWidth: 1500,
viewportHeight: 768,
videoCompression: 18,
video: true,
chromeWebSecurity: false,
pageLoadTimeout: 80000,
defaultCommandTimeout: 80000,
requestTimeout: 60000,
responseTimeout: 60000,
e2e: {
specPattern: "cypress/e2e/**/*.feature",
supportFile: "cypress/support/e2e.js",
setupNodeEvents,
// we are using cy.session() in login custom command, which is inheriting the testIsolation properties by default as true and clearing the page (cookies, local storage..etc.) in the test.
testIsolation: true,
},
});