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
35
36
37
38
39
40
41
42 public static WebDriver setUp(String username, String url) throws Exception {
43 return setUp(username, url, null, null);
44 }
45
46
47
48
49
50
51 public static WebDriver setUp(String username, String url, String className, TestName testName) throws Exception {
52 WebDriver driver = null;
53 if (System.getProperty("remote.driver.saucelabs") == null) {
54 driver = ITUtil.getWebDriver();
55
56
57
58
59 }
60 driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
61 driver.get(url);
62 ITUtil.login(driver, username);
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("remote.public.driver");
77 if (driverParam != null && "chrome".equals(driverParam.toLowerCase())) {
78 if (System.getProperty("webdriver.chrome.driver") == null) {
79 if (System.getProperty("remote.public.chrome") != null) {
80 System.setProperty("webdriver.chrome.driver", System.getProperty("remote.public.chrome"));
81 }
82 }
83 ChromeDriverService chromeDriverService = new ChromeDriverService.Builder()
84 .usingChromeDriverExecutable(new File(System.getProperty("remote.public.chrome")))
85 .usingAnyFreePort()
86 .build();
87 return chromeDriverService;
88 }
89 return null;
90 }
91 }