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 java.util.List;
18  
19  import org.junit.jupiter.api.Test;
20  import org.openqa.selenium.By;
21  import org.openqa.selenium.WebDriver;
22  import org.openqa.selenium.WebElement;
23  
24  /**
25   * Tests for version 2.5.0 of <a href="https://www.gwtproject.org/">GWT Project</a>.
26   *
27   * @author Ahmed Ashour
28   * @author Ronald Brill
29   */
30  public class GWTTest2x5x0 extends GWTTest {
31  
32      @Override
33      public String getDirectory() {
34          return "2.5.0";
35      }
36  
37      /**
38       * @throws Exception if an error occurs
39       */
40      @Test
41      public void hello() throws Exception {
42          final String url = URL_FIRST + "Hello/Hello.html";
43  
44          final WebDriver driver = loadGWTPage(url, "//button");
45  
46          final WebElement button = driver.findElement(By.xpath("//button"));
47          assertEquals("Click me", button.getText());
48  
49          button.click();
50          assertEquals("Hello, AJAX", driver.switchTo().alert().getText());
51          driver.switchTo().alert().dismiss();
52      }
53  
54      /**
55       * @throws Exception if an error occurs
56       */
57      @Test
58      public void mail() throws Exception {
59          final String url = URL_FIRST + "Mail/Mail.html";
60  
61          final WebDriver driver = loadGWTPage(url, "//div[@class='MGJ']");
62  
63          final WebElement cell = driver.findElement(By.xpath("//div[@class='MGJ']"));
64          assertTrue(cell.getText(), cell.getText().startsWith("Welcome back, foo@example.com"));
65  
66          final List<WebElement> cells = driver.findElements(By.xpath("//tr[@class='MKI']/td"));
67          assertEquals(3, cells.size());
68          assertEquals("markboland05", cells.get(0).getText());
69          assertEquals("mark@example.com", cells.get(1).getText());
70          assertEquals("URGENT -[Mon, 24 Apr 2006 02:17:27 +0000]", cells.get(2).getText());
71  
72          verifyStartMailBody(driver,
73                  "Dear Friend,",
74                  "",
75                  "I am Mr. Mark Boland the Bank Manager of ABN AMRO BANK 101 Moorgate, London, EC2M 6SB.");
76  
77          // click on email from Hollie Voss
78          final WebElement toClick = driver.findElement(By.xpath("//td[text() = 'Hollie Voss']"));
79          assertEquals("Hollie Voss", toClick.getText());
80  
81          toClick.click();
82          verifyStartMailBody(driver,
83                  ">> Componentes e decodificadores; confira aqui;",
84                  "http://br.geocities.com/listajohn/index.htm",
85                  "THE GOVERNING AWARD");
86      }
87  
88      private static void verifyStartMailBody(final WebDriver driver, final String... details) {
89          final WebElement mail = driver.findElement(By.xpath("//div[@class='MGI']"));
90          final String text = mail.getText();
91          final String[] lines = text.split("\\R");
92  
93          for (int i = 0; i < details.length; i++) {
94              assertEquals(details[i], lines[i]);
95          }
96      }
97  
98      /**
99       * @throws Exception if an error occurs
100      */
101     @Test
102     public void json() throws Exception {
103         final String url = URL_FIRST + "JSON/JSON.html";
104 
105         final WebDriver driver = loadGWTPage(url, "//button");
106 
107         final WebElement button = driver.findElement(By.xpath("//button"));
108         assertEquals("Search", button.getText());
109 
110         button.click();
111 
112         textToBePresentInElementLocated(driver,
113                 By.xpath("//div[@class='JSON-JSONResponseObject']/div/div/table//td[2]/div/span"),
114                 "ResultSet");
115     }
116 
117     /**
118      * @throws Exception if an error occurs
119      */
120     // this is a blinker with HtmlUnit at the moment
121     // @Test
122     public void showcase() throws Exception {
123         final String url = URL_FIRST + "Showcase/Showcase.html";
124 
125         final WebDriver driver = loadGWTPage(url, "id('gwt-debug-cwCheckBox-Monday-label')");
126 
127         WebElement elem = driver.findElement(By.id("gwt-debug-cwCheckBox-Monday-label"));
128         assertEquals("Monday", elem.getText());
129 
130         elem = driver.findElement(By.id("gwt-debug-cwCheckBox-Tuesday-label"));
131         assertEquals("Tuesday", elem.getText());
132     }
133 
134     /**
135      * @throws Exception if an error occurs
136      */
137     @Test
138     public void dynaTable() throws Exception {
139         startWebServer("src/test/resources/libraries/GWT/" + getDirectory() + "/DynaTable",
140                 new String[] {"src/test/resources/libraries/GWT/" + getDirectory() + "/gwt-servlet.jar"}, null);
141 
142         final String url = URL_FIRST + "DynaTable.html";
143         final WebDriver driver = loadGWTPage(url,
144                 "/html/body/table/tbody/tr/td[1]/table/tbody/tr[2]/td/table/tbody/tr[2]/td[2]");
145 
146         final List<WebElement> cells = driver.findElements(By.xpath("//table[@class='table']//tr[2]/td"));
147         assertEquals(3, cells.size());
148 
149         textToBePresentInElement(driver, cells.get(0), "Inman Mendez");
150         assertEquals("Majoring in Phrenology", cells.get(1).getText());
151         assertEquals("Mon 9:45-10:35, Tues 2:15-3:05, Fri 8:45-9:35, Fri 9:45-10:35", cells.get(2).getText());
152     }
153 }