View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
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   * Tests for <a href="https://www.gwtproject.org/">GWT Project</a>.
28   *
29   * @author Ahmed Ashour
30   * @author Ronald Brill
31   */
32  public abstract class GWTTest extends WebDriverTestCase {
33  
34      /**
35       * @throws Exception if an error occurs
36       */
37      @BeforeEach
38      public void startSesrver() throws Exception {
39          startWebServer("src/test/resources/libraries/GWT/" + getDirectory(), null, null);
40      }
41  
42      /**
43       * @throws Exception if an error occurs
44       */
45      @AfterEach
46      public void stopServer() throws Exception {
47          stopWebServers();
48      }
49  
50      /**
51       * @return the GWT directory being tested
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  }