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