This repository has been archived by the owner on Apr 25, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest-helpers.js
59 lines (54 loc) · 1.98 KB
/
test-helpers.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
import path from 'path';
import os from 'os';
import { retryInterval } from 'asyncbox';
const platform = os.platform();
export function e2eBefore ({appName, log, Application, fs}) {
async function before () {
let appPath;
let args = [];
if (process.env.SPECTRON_TEST_PROD_BINARIES) {
if (platform === 'linux') {
appPath = path.join(__dirname, '..', appName, 'release', 'linux-unpacked', 'appium-desktop');
} else if (platform === 'darwin') {
appPath = path.join(__dirname, '..', appName, 'release', 'mac', 'Appium.app', 'Contents', 'MacOS', 'Appium');
} else if (platform === 'win32') {
appPath = path.join(__dirname, '..', appName, 'release', 'win-ia32-unpacked', 'Appium.exe');
}
} else {
appPath = require(path.join(__dirname, '..', 'node_modules', 'electron'));
args = [path.join(__dirname, '..')];
}
this.timeout(process.env.E2E_TIMEOUT || 60 * 1000);
log.info(`Running Appium from: ${appPath}`);
log.info(`Checking that "${appPath}" exists`);
const applicationExists = await fs.exists(appPath);
if (!applicationExists) {
log.error(`Could not run tests. "${appPath}" does not exist.`);
process.exit(1);
}
log.info(`App exists. Creating Spectron Application instance`);
this.app = new Application({
path: appPath,
env: {
FORCE_NO_WRONG_FOLDER: true,
},
args,
});
log.info(`Spectron Application instance created. Starting app`);
await this.app.start();
const client = this.app.client;
log.info(`App started; waiting for splash page to go away`);
await retryInterval(20, 1000, async function () {
const handles = await client.getWindowHandles();
await client.switchToWindow(handles[0]);
(await client.getUrl()).should.include('index.html');
});
log.info(`App ready for automation`);
}
return before;
}
export function e2eAfter () {
if (this.app && this.app.isRunning()) {
return this.app.stop();
}
}