-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBaseUtils.java
More file actions
69 lines (57 loc) · 2.27 KB
/
Copy pathBaseUtils.java
File metadata and controls
69 lines (57 loc) · 2.27 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
package base;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.io.IOException;
import java.io.InputStream;
import java.time.Duration;
import java.util.Properties;
public final class BaseUtils {
static final String PREFIX_PROP = "default.";
private static final String ENV_CHROME_OPTIONS = "CHROME_OPTIONS";
private static final String PROP_CHROME_OPTIONS = PREFIX_PROP + ENV_CHROME_OPTIONS.toLowerCase();
private static final ChromeOptions chromeOptions;
private static Properties properties;
static {
initProperties();
chromeOptions = new ChromeOptions();
String options = properties.getProperty(PROP_CHROME_OPTIONS);
if (options != null) {
for (String argument : options.split(";")) {
chromeOptions.addArguments(argument);
}
}
WebDriverManager.chromedriver().setup();
}
private static void initProperties() {
if (properties == null) {
properties = new Properties();
if (isServerRun()) {
properties.setProperty(PROP_CHROME_OPTIONS, System.getenv(ENV_CHROME_OPTIONS));
} else {
try {
InputStream inputStream = BaseUtils.class.getClassLoader().getResourceAsStream("local.properties");
if (inputStream == null) {
System.out.println("ERROR: The \u001B[31mlocal.properties\u001B[0m file not found in src/test/resources/ directory.");
System.out.println("You need to create it from local.properties.TEMPLATE file.");
System.exit(1);
}
properties.load(inputStream);
} catch (IOException ignore) {
}
}
}
}
static Properties getProperties() {
return properties;
}
static boolean isServerRun() {
return System.getenv("CI_RUN") != null;
}
static WebDriver createDriver() {
WebDriver driver = new ChromeDriver(chromeOptions);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(15));
return driver;
}
}