-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcypress.config.js
190 lines (174 loc) · 5.35 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
const { defineConfig } = require('cypress')
const createBundler = require('@bahmutov/cypress-esbuild-preprocessor')
const preprocessor = require("@badeball/cypress-cucumber-preprocessor");
const createEsbuildPlugin = require("@badeball/cypress-cucumber-preprocessor/esbuild");
const fs = require('fs-extra');
const { exec } = require('child_process')
let githubActionsKeys = {}
module.exports = defineConfig({
e2e: {
watchForFileChanges: false,
specPattern: ["**/*.feature", "cypress/e2e/**/*.cy.{js,jsx,ts,tsx}"],
pageLoadTimeout: 90000,
responseTimeout: 45000,
defaultCommandTimeout: 6000,
video: true,
chromeWebSecurity: false,
screenshotsFolder: "cypress/results/screenshots",
videosFolder: "cypress/results/videos",
downloadsFolder: "cypress/results/downloads",
supportFile: 'cypress/support/e2e.js',
reporter: "cypress-multi-reporters",
reporterOptions: {
"configFile": "cypress/config/reporter-configs.json"
},
env: {
"TEST_TRIGGER": "local",
"TAGS": "not @skip",
"expandCollapseTime": 1500,
"HeroApp": "https://the-internet.herokuapp.com/",
"appiumTimeout": 60000,
"appiumRetries": 3,
"appiumPort": "4723",
"appiumCapabilitiesPath": "cypress/config/appium.json",
"androidPort": "5554",
"apkPath": "wdio/apk",
"avdHeadless": true
},
setupNodeEvents,
}
})
async function setupNodeEvents(on, config) {
const testTrigger = config.env.TEST_TRIGGER || 'local'
await preprocessor.addCucumberPreprocessorPlugin(on, config);
on(
"file:preprocessor",
createBundler({
plugins: [createEsbuildPlugin.default(config)],
})
);
cleanReports();
readGitHubSecrets(config);
on('task', {
logMsg(msg) {
console.log(msg);
return null;
},
getGithubKeys: () => {
return githubActionsKeys;
},
androidAVDStart({startCmd, checkCmd}){
let avdMsg = emulatorStart(startCmd, checkCmd, testTrigger)
return avdMsg
},
appiumServerStart( {startCmd, checkCmd} ){
let appiumMsg = appiumStart(startCmd, checkCmd)
return appiumMsg;
}
});
return config;
}
function cleanReports() {
const reportPath = './cypress/results/reports';
if (fs.existsSync(reportPath)) {
fs.rmdirSync('./cypress/results/reports', { recursive: true });
}
};
function readGitHubSecrets(config) {
githubActionsKeys["process_env_CYPRESS_ACTION_TEST"] = process.env.CYPRESS_ACTION_TEST
githubActionsKeys["config_ACTION_TEST"] = config.env.ACTION_TEST
}
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
async function emulatorStart(avdStartCmd, avdCheckCmd, testTrigger) {
console.log(`Cypress and AVD triggered by ${testTrigger}`)
// When running on Github Actions total timeout will be 8 minutes
const avdCheckAttempts = (testTrigger === 'local')? 5 : 32
const checkSleep = (testTrigger === 'local')? 3000 : 15000
let avdOn = false
let avdMsg
let avdOutput
let i = 0
console.log(avdStartCmd)
exec(avdStartCmd, (error, stdout, stderr) => {
avdOutput = `AVD stdout: ${stdout}`
if (stderr) {
avdOutput = `${avdOutput}\nAVD stderror: ${stderr}`
console.log(`AVD stderror: ${stderr}`);
}
if (error) {
avdOutput = `${avdOutput}\nAVD Error: ${error.message}`
console.log(`AVD Error: ${error.message}`);
}
console.log(avdOutput);
})
while(avdOn === false && i <= avdCheckAttempts) {
await sleep(checkSleep)
i++;
exec(avdCheckCmd, (error, stdout, stderr) => {
let checkOutput = `${avdCheckCmd}\n${stdout}`
if (stderr) {
checkOutput = `${checkOutput}\n${stderr}`
}
if (error) {
checkOutput = `${checkOutput}\n${error.message}`
}
console.log(checkOutput)
avdOn = stdout.includes('emulator-') && !stdout.includes('offline');
})
}
if( avdOn ) {
avdMsg = 'Success: Android AVD Started!!!'
} else {
avdMsg = "Android AVD Initialization Failed!!!!"
}
console.log(avdMsg)
return avdMsg
}
async function appiumStart(appiumStartCmd, appiumCheckCmd) {
const appiumCheckAttempts = 5
let appiumOn = false
let appiumMsg
let appiumOutput
let i = 0
console.log(appiumStartCmd)
exec(appiumStartCmd, (error, stdout, stderr) => {
appiumOutput = `Appium stdout: ${stdout}`
if (stderr) {
appiumOutput = `${appiumOutput}\nAppium stderror: ${stderr}`
console.log(`Appium stderror: ${stderr}`)
}
if (error) {
appiumOutput = `${appiumOutput}\nAppium Error: ${error.message}`
console.log(`Appium Error: ${error.message}`)
}
// A bit noisy, remove comment for debugging
console.log(appiumOutput);
})
while(appiumOn === false && i <= appiumCheckAttempts) {
await sleep(3000)
i++;
exec(appiumCheckCmd, (error, stdout, stderr) => {
let checkOutput = `${appiumCheckCmd}\n${stdout}`
if (stderr) {
checkOutput = `${checkOutput}\n${stderr}`
}
if (error) {
checkOutput = `${checkOutput}\n${error.message}`
}
console.log(checkOutput)
appiumOn = stdout.includes('LISTEN');
})
}
if( appiumOn ) {
appiumMsg = 'Success: Appium Server Started!!!'
} else {
appiumMsg = "Appium Server Initialization Failed!!!!"
console.log(appiumOutput);
}
console.log(appiumMsg)
return appiumMsg
}