-
-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathutils.js
More file actions
98 lines (83 loc) · 3.14 KB
/
utils.js
File metadata and controls
98 lines (83 loc) · 3.14 KB
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
import {Builder, By, until} from "selenium-webdriver";
import {spawnSync} from "child_process";
import testData from "./testData.json";
const firefox = require("selenium-webdriver/firefox");
const waitTime = 5000;
const orgSlug = "default";
export const executeCommand = (command, argv) => {
const result = spawnSync(command, [argv]);
if (result.stdout) {
process.stdout.write(`${result.stdout}\n`);
}
if (result.stderr) {
process.stderr.write(`${result.stderr}\n`);
}
if (result.status !== 0) {
process.exit(result.status);
}
};
export const getDriver = async () =>
new Builder()
.forBrowser("firefox")
.setFirefoxOptions(new firefox.Options().addArguments("-headless"))
.build();
export const getElementByCss = async (driver, css) => {
let el;
try {
el = await driver.wait(until.elementLocated(By.css(css)), waitTime);
} catch (err) {
/* eslint-disable-next-line no-console */
console.log(err, css, await driver.getPageSource());
}
return el;
};
export const getElementsByCss = async (driver, css) => {
let el;
try {
el = await driver.wait(until.elementsLocated(By.css(css)), waitTime);
} catch (err) {
/* eslint-disable-next-line no-console */
console.log(err, css, await driver.getPageSource());
}
return el;
};
export const initialData = () => testData;
export const initializeData = async (argv = null) => {
await executeCommand(`./browser-test/initialize_data.py`, argv);
};
export const clearData = async () => {
await executeCommand("./browser-test/clear_data.py", () => {});
};
export const tearDown = async (driver) => {
await clearData();
await driver.executeScript("window.sessionStorage.clear()");
await driver.executeScript("window.localStorage.clear()");
await driver.manage().deleteAllCookies();
driver.close();
};
export const getPhoneToken = () => {
const result = spawnSync("./browser-test/get_phone_token.py");
return result.stdout.toString();
};
export const urls = {
registration: `http://127.0.0.1:8080/${orgSlug}/registration`,
registrationTos: `http://127.0.0.1:8080/${orgSlug}/registration/terms-and-conditions`,
registrationPrivacy: `http://127.0.0.1:8080/${orgSlug}/registration/privacy-policy`,
login: `http://127.0.0.1:8080/${orgSlug}/login`,
loginTos: `http://127.0.0.1:8080/${orgSlug}/login/terms-and-conditions`,
loginPrivacy: `http://127.0.0.1:8080/${orgSlug}/login/privacy-policy`,
status: `http://127.0.0.1:8080/${orgSlug}/status`,
passwordChange: `http://127.0.0.1:8080/${orgSlug}/change-password`,
passwordReset: `http://127.0.0.1:8080/${orgSlug}/password/reset`,
passwordConfirm: (uid, token) =>
`http://127.0.0.1:8080/${orgSlug}/password/reset/confirm/${uid}/${token}`,
verificationLogin: (slug) => `http://127.0.0.1:8080/${slug}/login`,
mobileVerification: (slug) =>
`http://127.0.0.1:8080/${slug}/mobile-phone-verification`,
mobilePhoneChange: (slug) =>
`http://127.0.0.1:8080/${slug}/change-phone-number`,
};
export const successToastSelector = ".Toastify__toast--success div[role=alert]";
// increase the jest global test time out
// because browser tests can take a bit longer to complete
jest.setTimeout(20000);