-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathutils.js
67 lines (57 loc) · 1.86 KB
/
utils.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
const Vars = require("./vars");
const WebDriver = require("selenium-webdriver");
const seleniumEdge = require("selenium-webdriver/edge");
const seleniumChrome = require("selenium-webdriver/chrome");
const seleniumFirefox = require("selenium-webdriver/firefox");
function messUserPass(str) {
return str
.split("")
.map(function (c) {
return String.fromCharCode(c.charCodeAt(0) ^ 0x1f);
})
.join("");
}
function getPlatform() {
return process.platform;
}
function setWebdriverBrowser(driver, browser, path) {
switch (browser) {
case "firefox":
const firefoxOptions = new seleniumFirefox.Options();
firefoxOptions.setBinary(path);
driver.forBrowser(WebDriver.Browser.FIREFOX).setFirefoxOptions(firefoxOptions);
break;
case "chrome":
const chromeOptions = new seleniumChrome.Options();
chromeOptions.setChromeBinaryPath(path);
chromeOptions.addArguments("--start-maximized");
chromeOptions.excludeSwitches("enable-automation");
driver.forBrowser(WebDriver.Browser.CHROME).setChromeOptions(chromeOptions);
break;
case "edge":
const edgeOptions = new seleniumEdge.Options();
edgeOptions.setEdgeChromiumBinaryPath(path);
edgeOptions.addArguments("--start-maximized");
edgeOptions.excludeSwitches("enable-automation");
driver.forBrowser(WebDriver.Browser.EDGE).setEdgeOptions(edgeOptions);
break;
}
}
function getWebDriver(platform) {
const driver = new WebDriver.Builder();
const browserPaths = Vars.browserPaths[platform];
if (!browserPaths) {
console.error("Sistema operacional não suportado.");
process.exit(1);
}
const path = browserPaths[Vars.browser];
if (!path) {
console.error("Navegador não suportado.");
process.exit(1);
}
setWebdriverBrowser(driver, Vars.browser, path);
return driver.build();
}
exports.messUserPass = messUserPass;
exports.getWebDriver = getWebDriver;
exports.getPlatform = getPlatform;