-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomWebDriver.java
116 lines (92 loc) · 2.95 KB
/
CustomWebDriver.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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package com.browserstack.webdriver;
import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
public class CustomWebDriver implements WebDriver, JavascriptExecutor, TakesScreenshot {
private static final Logger logger = Logger.getLogger(CustomWebDriver.class.getName());
private final static long DEFAULT_TIME_OUT_IN_SECONDS = 25;
private final static long DEFAULT_SLEEP_IN_MILLIS = 500;
private final WebDriver driver;
private final WebDriverWait wait;
public CustomWebDriver(WebDriver driver) {
this(driver, DEFAULT_TIME_OUT_IN_SECONDS, DEFAULT_SLEEP_IN_MILLIS);
}
public CustomWebDriver(WebDriver driver, long timeOutInSeconds) {
this(driver, timeOutInSeconds, DEFAULT_SLEEP_IN_MILLIS);
}
public CustomWebDriver(WebDriver driver, long timeOutInSeconds, long sleepInMillis) {
this.driver = driver;
this.wait = new WebDriverWait(driver, DEFAULT_TIME_OUT_IN_SECONDS, DEFAULT_SLEEP_IN_MILLIS);
}
@Override
public void get(String url) {
driver.get(url);
}
@Override
public String getCurrentUrl() {
return driver.getCurrentUrl();
}
@Override
public String getTitle() {
return driver.getTitle();
}
@Override
public List<WebElement> findElements(By by) {
return driver.findElements(by);
}
@Override
public WebElement findElement(By by) {
return driver.findElement(by);
}
@Override
public String getPageSource() {
return driver.getPageSource();
}
@Override
public void close() {
driver.close();
}
@Override
public void quit() {
driver.quit();
}
@Override
public Set<String> getWindowHandles() {
return driver.getWindowHandles();
}
@Override
public String getWindowHandle() {
return driver.getWindowHandle();
}
@Override
public TargetLocator switchTo() {
return driver.switchTo();
}
@Override
public Navigation navigate() {
return driver.navigate();
}
@Override
public Options manage() {
return driver.manage();
}
@Override
public Object executeScript(String script, Object... args) {
return ((JavascriptExecutor) driver).executeScript(script, args);
}
@Override
public Object executeAsyncScript(String script, Object... args) {
return ((JavascriptExecutor) driver).executeAsyncScript(script, args);
}
@Override
public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException {
return ((TakesScreenshot) driver).getScreenshotAs(target);
}
public WebElement waitForVisibilityOf(WebElement element) {
logger.info("waitForVisibilityOf:: start");
return wait.until(ExpectedConditions.visibilityOf(element));
}
}