-
Notifications
You must be signed in to change notification settings - Fork 5
/
wdio.mac.multiremote.conf.ts
190 lines (184 loc) · 6.67 KB
/
wdio.mac.multiremote.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
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 MACOS_USER_A_BUNDLE_ID =
require("@helpers/constants").MACOS_USER_A_BUNDLE_ID;
const MACOS_USER_B_BUNDLE_ID =
require("@helpers/constants").MACOS_USER_B_BUNDLE_ID;
const MACOS_USER_C_BUNDLE_ID =
require("@helpers/constants").MACOS_USER_C_BUNDLE_ID;
const MACOS_DRIVER = require("@helpers/constants").MACOS_DRIVER;
const fsp = require("fs").promises;
const { readFileSync, rmSync } = require("fs");
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/Chats/01-Chats.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
//
capabilities: [
{
platformName: "mac",
"appium:automationName": MACOS_DRIVER,
"appium:bundleId": MACOS_USER_A_BUNDLE_ID,
"appium:arguments": ["--path", homedir() + "/.uplink"],
"appium:systemPort": 4725,
"appium:prerun": {
command:
'do shell script "rm -rf ~/.uplink && rm -rf ~/.uplinkUserB && rm -rf ~/.uplinkUserC"',
},
},
],
// 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-macos-multiremote-${options.cid}.xml`;
},
},
],
],
maxInstances: 1,
// The number of times to retry the entire specfile when it fails as a whole
specFileRetries: 2,
// Delay in seconds between the spec file retry attempts
specFileRetriesDelay: 0,
//
// =====
// 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.
/**
* Function to be executed after a test (in Mocha/Jasmine).
*/
onPrepare: async function (config, capabilities) {
const cacheFolderUserA = homedir() + "/.uplink/.user";
const cacheFolderUserB = homedir() + "/.uplinkUserB/.user";
const cacheFolderUserC = homedir() + "/.uplinkUserC/.user";
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}`,
);
}
try {
await rmSync(cacheFolderUserA, { recursive: true, force: true });
await rmSync(cacheFolderUserB, { recursive: true, force: true });
await rmSync(cacheFolderUserC, { recursive: true, force: true });
} catch (error) {
console.error(
`Got an error trying to delete Cache Folder: ${error.message}`,
);
}
},
afterTest: async function (
test,
context,
{ error, result, duration, passed, retries },
) {
if (!passed) {
let imageFile = await browser.takeScreenshot();
const imageFolder = join(
process.cwd(),
"./test-results/macos-multiremote",
test.parent,
);
const imageTitle = test.title + " - Failed.png";
await fsp.mkdir(imageFolder, { recursive: true });
await fsp.writeFile(
imageFolder + "/" + imageTitle,
imageFile,
"base64",
);
// Add to Screenshot to Allure Reporter
const data = await readFileSync(`${imageFolder}/${imageTitle}`);
allureReporter.addAttachment(imageTitle, data, "image/png");
}
},
afterSuite: async function (suite) {
// Close applications if open
await terminateApplication(MACOS_USER_A_BUNDLE_ID);
await terminateApplication(MACOS_USER_B_BUNDLE_ID);
await terminateApplication(MACOS_USER_C_BUNDLE_ID);
},
},
};
export async function terminateApplication(bundle: string) {
const appState = await queryAppStateMacOS(bundle);
if (appState !== 1) {
await driver.executeScript("macos: terminateApp", [
{
bundleId: bundle,
},
]);
}
}
export async function queryAppStateMacOS(bundle: string) {
const queryAppState = await driver.executeScript("macos: queryAppState", [
{
bundleId: bundle,
},
]);
return queryAppState;
}