1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.libraries;
16
17 import org.htmlunit.WebDriverTestCase;
18 import org.htmlunit.junit.BrowserRunner;
19 import org.junit.After;
20 import org.junit.Before;
21 import org.junit.runner.RunWith;
22 import org.openqa.selenium.By;
23 import org.openqa.selenium.WebDriver;
24 import org.openqa.selenium.WebElement;
25 import org.openqa.selenium.support.ui.ExpectedConditions;
26 import org.openqa.selenium.support.ui.WebDriverWait;
27
28
29
30
31
32
33
34 @RunWith(BrowserRunner.class)
35 public abstract class GWTTest extends WebDriverTestCase {
36
37
38
39
40 @Before
41 public void startSesrver() throws Exception {
42 startWebServer("src/test/resources/libraries/GWT/" + getDirectory(), null, null);
43 }
44
45
46
47
48 @After
49 public void stopServer() throws Exception {
50 stopWebServers();
51 }
52
53
54
55
56 public abstract String getDirectory();
57
58 protected WebDriver loadGWTPage(final String url, final String elementXPathToWaitFor) throws Exception {
59 final WebDriver driver = getWebDriver();
60 driver.get(url);
61
62 final WebDriverWait wait = new WebDriverWait(driver, DEFAULT_WAIT_TIME);
63 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(elementXPathToWaitFor)));
64
65 return driver;
66 }
67
68 protected void textToBePresentInElement(final WebDriver driver, final WebElement elem, final String expected) {
69 final WebDriverWait wait = new WebDriverWait(driver, DEFAULT_WAIT_TIME);
70 wait.until(ExpectedConditions.textToBePresentInElement(elem, expected));
71 }
72
73 protected void textToBePresentInElementLocated(final WebDriver driver, final By by, final String expected) {
74 final WebDriverWait wait = new WebDriverWait(driver, DEFAULT_WAIT_TIME);
75 wait.until(ExpectedConditions.textToBePresentInElementLocated(by, expected));
76 }
77 }