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.junit.jupiter.api.AfterEach;
19 import org.junit.jupiter.api.BeforeEach;
20 import org.openqa.selenium.By;
21 import org.openqa.selenium.WebDriver;
22 import org.openqa.selenium.WebElement;
23 import org.openqa.selenium.support.ui.ExpectedConditions;
24 import org.openqa.selenium.support.ui.WebDriverWait;
25
26
27
28
29
30
31
32 public abstract class GWTTest extends WebDriverTestCase {
33
34
35
36
37 @BeforeEach
38 public void startSesrver() throws Exception {
39 startWebServer("src/test/resources/libraries/GWT/" + getDirectory(), null, null);
40 }
41
42
43
44
45 @AfterEach
46 public void stopServer() throws Exception {
47 stopWebServers();
48 }
49
50
51
52
53 public abstract String getDirectory();
54
55 protected WebDriver loadGWTPage(final String url, final String elementXPathToWaitFor) throws Exception {
56 final WebDriver driver = getWebDriver();
57 driver.get(url);
58
59 final WebDriverWait wait = new WebDriverWait(driver, DEFAULT_WAIT_TIME);
60 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(elementXPathToWaitFor)));
61
62 return driver;
63 }
64
65 protected void textToBePresentInElement(final WebDriver driver, final WebElement elem, final String expected) {
66 final WebDriverWait wait = new WebDriverWait(driver, DEFAULT_WAIT_TIME);
67 wait.until(ExpectedConditions.textToBePresentInElement(elem, expected));
68 }
69
70 protected void textToBePresentInElementLocated(final WebDriver driver, final By by, final String expected) {
71 final WebDriverWait wait = new WebDriverWait(driver, DEFAULT_WAIT_TIME);
72 wait.until(ExpectedConditions.textToBePresentInElementLocated(by, expected));
73 }
74 }