-
-
Notifications
You must be signed in to change notification settings - Fork 97
/
BrowserFactory.java
67 lines (48 loc) · 1.73 KB
/
BrowserFactory.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package io.github.tahanima.factory;
import static io.github.tahanima.config.ConfigurationManager.config;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import java.time.Duration;
/**
* @author tahanima
*/
public enum BrowserFactory {
CHROME {
@Override
public WebDriver getDriver() {
WebDriver driver = new ChromeDriver(getOptions());
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(config().timeout()));
driver.manage().window().maximize();
return driver;
}
private ChromeOptions getOptions() {
ChromeOptions options = new ChromeOptions();
options.setAcceptInsecureCerts(true);
if (Boolean.TRUE.equals(config().headless())) {
options.addArguments("--headless=new");
}
return options;
}
},
FIREFOX {
@Override
public WebDriver getDriver() {
WebDriver driver = new FirefoxDriver(getOptions());
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(config().timeout()));
driver.manage().window().maximize();
return driver;
}
private FirefoxOptions getOptions() {
FirefoxOptions options = new FirefoxOptions();
options.setAcceptInsecureCerts(true);
if (Boolean.TRUE.equals(config().headless())) {
options.addArguments("--headless=new");
}
return options;
}
};
public abstract WebDriver getDriver();
}