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