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.eclipse.jetty.server.Server;
20 import org.htmlunit.WebDriverTestCase;
21 import org.htmlunit.WebServerTestCase;
22 import org.htmlunit.junit.annotation.Alerts;
23 import org.junit.jupiter.api.AfterAll;
24 import org.junit.jupiter.api.BeforeAll;
25 import org.junit.jupiter.api.Test;
26 import org.openqa.selenium.By;
27 import org.openqa.selenium.WebDriver;
28 import org.openqa.selenium.WebElement;
29
30
31
32
33
34
35
36 public class ExtJS22Test extends WebDriverTestCase {
37
38 private static Server SERVER_;
39
40
41
42
43 @BeforeAll
44 public static void startSesrver() throws Exception {
45 SERVER_ = WebServerTestCase.createWebServer("src/test/resources/libraries/ExtJS/" + getVersion(), null);
46 }
47
48
49
50
51 @AfterAll
52 public static void stopServer() throws Exception {
53 if (SERVER_ != null) {
54 SERVER_.stop();
55 SERVER_.destroy();
56 SERVER_ = null;
57 }
58 }
59
60
61
62
63
64 protected static String getVersion() {
65 return "2.2";
66 }
67
68
69
70
71
72
73
74
75
76 protected WebDriver getPage(final String example, final String htmlName) throws Exception {
77 final WebDriver driver = getWebDriver();
78 driver.get(URL_FIRST + "examples/" + example + "/" + htmlName + ".html");
79 return driver;
80 }
81
82
83
84
85 @Test
86 public void core_templates() throws Exception {
87 final WebDriver driver = getPage("core", "templates");
88 final List<WebElement> buttons = driver.findElements(By.xpath("//button"));
89 final List<WebElement> divs = driver.findElements(By.xpath("//div[@class='x-panel-body']"));
90 assertEquals(2, buttons.size());
91 assertEquals(2, divs.size());
92 assertEquals("Apply the template to see results here", divs.get(0).getText());
93 assertEquals("Apply the template to see results here", divs.get(1).getText());
94
95 buttons.get(0).click();
96 assertEquals("Name: Jack Slocum\n" + "Company: Ext JS, LLC\n"
97 + "Location: Cleveland, Ohio", divs.get(0).getText());
98 assertEquals("Apply the template to see results here", divs.get(1).getText());
99
100 buttons.get(1).click();
101 assertEquals("Name: Jack Slocum\n" + "Company: Ext JS, LLC\n"
102 + "Location: Cleveland, Ohio", divs.get(0).getText());
103 assertEquals("Name: Jack Slocum\n" + "Company: Ext JS, LLC\n"
104 + "Location: Cleveland, Ohio\n"
105 + "Kids:\n" + "1. Jack Slocum's kid - Sara Grace\n"
106 + "2. Jack Slocum's kid - Zachary", divs.get(1).getText());
107 }
108
109
110
111
112 @Test
113 public void core_spotlight() throws Exception {
114 final WebDriver driver = getPage("core", "spotlight");
115 final List<WebElement> buttons = driver.findElements(By.xpath("//button"));
116 assertEquals(4, buttons.size());
117 assertEquals("Start", buttons.get(0).getText());
118 assertEquals("Next Panel", buttons.get(1).getText());
119 assertEquals("Next Panel", buttons.get(2).getText());
120 assertEquals("Done", buttons.get(3).getText());
121
122 assertTrue(core_spotlight_isDisabled(buttons.get(1)));
123 assertTrue(core_spotlight_isDisabled(buttons.get(2)));
124 assertTrue(core_spotlight_isDisabled(buttons.get(3)));
125
126 buttons.get(0).click();
127 Thread.sleep(200);
128 assertFalse(core_spotlight_isDisabled(buttons.get(1)));
129 assertTrue(core_spotlight_isDisabled(buttons.get(2)));
130 assertTrue(core_spotlight_isDisabled(buttons.get(3)));
131
132 buttons.get(1).click();
133 Thread.sleep(200);
134 assertTrue(core_spotlight_isDisabled(buttons.get(1)));
135 assertFalse(core_spotlight_isDisabled(buttons.get(2)));
136 assertTrue(core_spotlight_isDisabled(buttons.get(3)));
137
138 buttons.get(2).click();
139 Thread.sleep(200);
140 assertTrue(core_spotlight_isDisabled(buttons.get(1)));
141 assertTrue(core_spotlight_isDisabled(buttons.get(2)));
142 assertFalse(core_spotlight_isDisabled(buttons.get(3)));
143
144 buttons.get(3).click();
145 Thread.sleep(200);
146 assertTrue(core_spotlight_isDisabled(buttons.get(1)));
147 assertTrue(core_spotlight_isDisabled(buttons.get(2)));
148 assertTrue(core_spotlight_isDisabled(buttons.get(3)));
149 }
150
151 private static boolean core_spotlight_isDisabled(final WebElement button) {
152 final WebElement table = button.findElement(By.xpath("ancestor::table[1]"));
153 return table.getAttribute("class").contains("disabled");
154 }
155
156
157
158
159 @Test
160 @Alerts("Hello from the Ext console.")
161 public void debug_console() throws Exception {
162 final WebDriver driver = getPage("debug", "debug-console");
163
164 final List<WebElement> anchors = driver.findElements(By.xpath("//a"));
165 assertEquals(2, anchors.size());
166 anchors.get(1).click();
167 assertEquals(getExpectedAlerts()[0],
168 driver.findElement(By.xpath("//div[starts-with(text(), 'Hello')][1]")).getText());
169 }
170
171
172
173
174 @Test
175 public void desktop_desktop() throws Exception {
176 final WebDriver driver = getPage("desktop", "desktop");
177 driver.findElement(By.xpath("//button[1]")).click();
178 }
179
180
181
182
183 @Test
184 public void form_absform() throws Exception {
185 final WebDriver driver = getPage("form", "absform");
186 final String content = driver.findElement(By.xpath("//html/body")).getText();
187 assertTrue(content.contains("Resize Me"));
188 assertTrue(content.contains("Send To:"));
189 assertTrue(content.contains("Subject:"));
190 assertTrue(content.contains("Cancel"));
191 }
192
193
194
195
196 @Test
197 public void form_anchoring() throws Exception {
198 final WebDriver driver = getPage("form", "anchoring");
199 final String content = driver.findElement(By.xpath("//html/body")).getText();
200 assertTrue(content.contains("Send To:"));
201 assertTrue(content.contains("Subject:"));
202 assertTrue(content.contains("Send"));
203 assertTrue(content.contains("Cancel"));
204 }
205
206
207
208
209 @Test
210 public void grid_binding() throws Exception {
211 final WebDriver driver = getPage("grid", "binding");
212
213
214
215
216 Thread.sleep(DEFAULT_WAIT_TIME.multipliedBy(2).toMillis());
217
218 final WebElement detailPanel = driver.findElement(By.id("detailPanel"));
219 final WebElement resultsDiv = detailPanel.findElement(By.xpath("div/div[1]"));
220 assertEquals("Please select a book to see additional details.", resultsDiv.getText());
221
222 final WebElement firstRowDiv = driver.findElement(By.xpath("//div[@class='x-grid3-body']/div[1]"));
223
224 firstRowDiv.click();
225 assertEquals("Title: Master of the Game\n"
226 + "Author: Sidney Sheldon\n"
227 + "Manufacturer: Warner Books\n"
228 + "Product Group: Book", resultsDiv.getText());
229 }
230
231 }