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