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