-
Notifications
You must be signed in to change notification settings - Fork 5
/
wdio.windows.ci.conf.ts
224 lines (215 loc) · 7.4 KB
/
wdio.windows.ci.conf.ts
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
require("module-alias/register");
const allureReporter = require("@wdio/allure-reporter").default;
const sharedConfig = require("@config/wdio.shared.conf.ts").config;
const homedir = require("os").homedir;
const join = require("path").join;
const fsp = require("fs").promises;
const { readFileSync, rmSync } = require("fs");
const kill = require("kill-port");
const WINDOWS_APP_LOCATION = require("@helpers/constants").WINDOWS_APP;
export const config: WebdriverIO.Config = {
...sharedConfig,
...{
//
// ==================
// Specify Test Files
// ==================
// Define which test specs should run. The pattern is relative to the directory
// from which `wdio` was called.
//
// The specs are defined as an array of spec files (optionally using wildcards
// that will be expanded). The test for each spec file will be run in a separate
// worker process. In order to have a group of spec files run in the same worker
// process simply enclose them in an array within the specs array.
//
// If you are calling `wdio` from an NPM script (see https://docs.npmjs.com/cli/run-script),
// then the current working directory is where your `package.json` resides, so `wdio`
// will be called from there.
//
specs: [
join(process.cwd(), "./tests/suites/MainTests/02-UplinkWindows.suite.ts"),
],
// Patterns to exclude.
exclude: [
// 'path/to/excluded/files'
],
//
// ============
// Capabilities
// ============
// Define your capabilities here. WebdriverIO can run multiple capabilities at the same
// time. Depending on the number of capabilities, WebdriverIO launches several test
// sessions. Within your capabilities you can overwrite the spec and exclude options in
// order to group specific specs to a specific capability.
//
// If you have trouble getting all important capabilities together, check out the
// Sauce Labs platform configurator - a great tool to configure your capabilities:
// https://docs.saucelabs.com/reference/platforms-configurator
//
port: 4723,
path: "/wd/hub/",
capabilities: [
{
platformName: "windows",
"appium:deviceName": "WindowsPC",
"appium:automationName": "windows",
"appium:app": WINDOWS_APP_LOCATION,
"ms:waitForAppLaunch": 50,
"appium:prerun": {
command:
"If (Test-Path $home/.uplink/.user) {Remove-Item -Recurse -Force $home/.uplink/.user} Else { Break }",
},
},
],
//
// ===================
// Test Configurations
// ===================
// Define all options that are relevant for the WebdriverIO instance here
//
// Test reporter for stdout.
// The only one supported by default is 'dot'
// see also: https://webdriver.io/docs/dot-reporter
reporters: [
[
"spec",
{
showPreface: false,
},
],
[
"allure",
{
outputDir: "./allure-results",
disableWebdriverStepsReporting: true,
disableWebdriverScreenshotsReporting: true,
},
],
[
"junit",
{
outputDir: "./test-report/",
outputFileFormat: function (options) {
return `test-results-windows-ci-${options.cid}.xml`;
},
},
],
],
specFileRetries: 1,
//
// =====
// Hooks
// =====
// WebdriverIO provides several hooks you can use to interfere with the test process in order to enhance
// it and to build services around it. You can either apply a single function or an array of
// methods to it. If one of them returns with a promise, WebdriverIO will wait until that promise got
// resolved to continue.
onComplete: async function (exitCode, config, capabilities, results) {
await kill(4723, "tcp");
},
onPrepare: async function () {
// Declare constants for folder locations
const cacheFolder = homedir() + "\\.uplink\\.user";
const sourceReusableData = join(
process.cwd(),
"\\tests\\fixtures\\users\\FriendsTestUser",
);
const targetReusableData = join(
process.cwd(),
"\\tests\\fixtures\\users\\windows\\FriendsTestUser",
);
const allureResultsFolder = join(process.cwd(), "\\allure-results");
const testReportFolder = join(process.cwd(), "\\test-report");
const testResultsFolder = join(process.cwd(), "\\test-results");
try {
await rmSync(allureResultsFolder, { recursive: true, force: true });
await rmSync(testReportFolder, { recursive: true, force: true });
await rmSync(testResultsFolder, { recursive: true, force: true });
} catch (error) {
console.error(
`Got an error trying to delete artifacts folders: ${error.message}`,
);
}
// Execute the actions to clean up folders and copy required data
try {
await rmSync(cacheFolder, { recursive: true, force: true });
} catch (error) {
console.error(
`Got an error trying to delete Cache Folder: ${error.message}`,
);
}
try {
await fsp.mkdir(targetReusableData, { recursive: true });
await fsp.cp(sourceReusableData, targetReusableData, {
recursive: true,
force: true,
});
} catch (error) {
console.error(
`Got an error trying to copy Friends Test Folder: ${error.message}`,
);
}
},
/**
* Function to be executed after a test (in Mocha/Jasmine).
*/
beforeTest: async function (test) {
// Start video recording for each test
await driver.executeScript("windows: startRecordingScreen", [
{
deviceId: 1,
},
]);
},
afterTest: async function (
test,
context,
{ error, result, duration, passed, retries },
) {
// Stop video recording and saved it into base64 format
const base64Video = await driver.executeScript(
"windows: stopRecordingScreen",
[
{
remotePath: "",
},
],
);
if (!passed) {
await driver.takeScreenshot();
const imageFile = await driver.takeScreenshot();
const imageFolder = join(
process.cwd(),
"./test-results/windows-ci",
test.parent,
);
const imageTitle = test.title + " - Failed.png";
const videoTitle = test.title + " - Failed.mp4";
await fsp.mkdir(imageFolder, { recursive: true });
// Write Video File if test failure and add it to failed screenshots folder
await fsp.writeFile(
imageFolder + "/" + videoTitle,
base64Video,
"base64",
);
await fsp.writeFile(
imageFolder + "/" + imageTitle,
imageFile,
"base64",
);
// Add to Screenshot to Allure Reporter
const dataVideo = await readFileSync(`${imageFolder}/${videoTitle}`);
allureReporter.addAttachment(videoTitle, dataVideo, "video/mp4");
// Add to Screenshot to Allure Reporter
const data = await readFileSync(`${imageFolder}/${imageTitle}`);
allureReporter.addAttachment(imageTitle, data, "image/png");
// Close application if still open
await driver.executeScript("windows: closeApp", [
{
app: WINDOWS_APP_LOCATION,
},
]);
}
},
},
};