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