-
Notifications
You must be signed in to change notification settings - Fork 16
/
WebDriverFactory.java
51 lines (46 loc) · 2.2 KB
/
WebDriverFactory.java
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
package io.redskap.swagger.brake.integration.artifactory.factory;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class WebDriverFactory {
private static final String CHROME_DRIVER_VERSION_ENV_VAR = "CHROME_DRIVER_VERSION";
private static final String CHROME_BROWSER_VERSION_ENV_VAR = "CHROME_BROWSER_VERSION";
public static final String DEFAULT_DRIVER_VERSION = "111.0.5563.64";
public static final String DEFAULT_BROWSER_VERSION = "111.0.5563.111";
public static WebDriver create() {
WebDriverManager
.chromedriver()
.browserVersion(getBrowserVersion())
.driverVersion(getDriverVersion())
.setup();
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("enable-automation");
options.addArguments("--no-sandbox");
options.addArguments("--disable-infobars");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--disable-browser-side-navigation");
options.addArguments("--disable-gpu");
options.addArguments("--window-size=1600,900");
// https://stackoverflow.com/questions/75718422/org-openqa-selenium-remote-http-connectionfailedexception-unable-to-establish-w
options.addArguments("--remote-allow-origins=*");
options.addArguments("--headless");
return new ChromeDriver(options);
}
private static String getDriverVersion() {
String chromeDriverVersion = System.getenv(CHROME_DRIVER_VERSION_ENV_VAR);
if (StringUtils.isBlank(chromeDriverVersion)) {
chromeDriverVersion = DEFAULT_DRIVER_VERSION;
}
return chromeDriverVersion;
}
private static String getBrowserVersion() {
String chromeBrowserVersion = System.getenv(CHROME_BROWSER_VERSION_ENV_VAR);;
if (StringUtils.isBlank(chromeBrowserVersion)) {
chromeBrowserVersion = DEFAULT_BROWSER_VERSION;
}
return chromeBrowserVersion;
}
}