1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package edu.samplu.common;
18
19 import org.junit.rules.TestName;
20 import org.openqa.selenium.WebDriver;
21 import org.openqa.selenium.chrome.ChromeDriverService;
22
23 import java.io.File;
24 import java.util.concurrent.TimeUnit;
25
26
27
28
29
30 public class WebDriverUtil {
31
32 public static int DEFAULT_IMPLICIT_WAIT_TIME = 30;
33 public static int SHORT_IMPLICIT_WAIT_TIME = 1;
34 public static final String REMOTE_DRIVER_SAUCELABS_PROPERTY = "remote.driver.saucelabs";
35
36
37
38
39
40
41
42
43 public static WebDriver setUp(String username, String url) throws Exception {
44 return setUp(username, url, null, null);
45 }
46
47
48
49
50
51
52 public static WebDriver setUp(String username, String url, String className, TestName testName) throws Exception {
53 WebDriver driver = null;
54 if (System.getProperty(REMOTE_DRIVER_SAUCELABS_PROPERTY) == null) {
55 driver = ITUtil.getWebDriver();
56
57
58
59
60 }
61 driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
62 driver.get(url);
63 driver.manage().timeouts().implicitlyWait(DEFAULT_IMPLICIT_WAIT_TIME, TimeUnit.SECONDS);
64 return driver;
65 }
66
67 public static void checkForIncidentReport(WebDriver driver, String locator) {
68 checkForIncidentReport(driver, locator, "");
69 }
70
71 public static void checkForIncidentReport(WebDriver driver, String locator, String message) {
72 ITUtil.checkForIncidentReport(driver.getPageSource(), locator, message);
73 }
74
75 public static ChromeDriverService createAndStartService() {
76 String driverParam = System.getProperty(ITUtil.HUB_DRIVER_PROPERTY);
77
78 if (driverParam != null && "chrome".equals(driverParam.toLowerCase())) {
79 if (System.getProperty("webdriver.chrome.driver") == null) {
80 if (System.getProperty("remote.public.chrome") != null) {
81 System.setProperty("webdriver.chrome.driver", System.getProperty("remote.public.chrome"));
82 }
83 }
84 ChromeDriverService chromeDriverService = new ChromeDriverService.Builder()
85 .usingChromeDriverExecutable(new File(System.getProperty("remote.public.chrome")))
86 .usingAnyFreePort()
87 .build();
88 return chromeDriverService;
89 }
90 return null;
91 }
92 }