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.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   * Tests for <a href="https://www.gwtproject.org/">GWT Project</a>.
30   *
31   * @author Ahmed Ashour
32   * @author Ronald Brill
33   */
34  @RunWith(BrowserRunner.class)
35  public abstract class GWTTest extends WebDriverTestCase {
36  
37      /**
38       * @throws Exception if an error occurs
39       */
40      @Before
41      public void startSesrver() throws Exception {
42          startWebServer("src/test/resources/libraries/GWT/" + getDirectory(), null, null);
43      }
44  
45      /**
46       * @throws Exception if an error occurs
47       */
48      @After
49      public void stopServer() throws Exception {
50          stopWebServers();
51      }
52  
53      /**
54       * @return the GWT directory being tested
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  }