- Timestamp:
- 02/14/13 15:20:07 (12 years ago)
- Location:
- trunk
- Files:
-
- 13 added
- 6 deleted
- 22 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-htmlmonitor-test/pom.xml
r1011 r1069 22 22 <dependencies> 23 23 <dependency> 24 <groupId>de.ugoe.cs.autoquest</groupId> 25 <artifactId>autoquest-plugin-html</artifactId> 26 <version>${tested-autoquest-version}</version> 27 <scope>test</scope> 28 </dependency> 29 <dependency> 24 30 <groupId>org.apache.httpcomponents</groupId> 25 31 <artifactId>httpclient</artifactId> … … 28 34 </dependency> 29 35 </dependencies> 36 <build> 37 <plugins> 38 <plugin> 39 <groupId>org.apache.maven.plugins</groupId> 40 <artifactId>maven-dependency-plugin</artifactId> 41 <version>2.4</version> 42 <executions> 43 <execution> 44 <id>get-htmlmonitor-config</id> 45 <phase>process-classes</phase> 46 <goals> 47 <goal>unpack</goal> 48 </goals> 49 <configuration> 50 <artifactItems> 51 <artifactItem> 52 <groupId>de.ugoe.cs.autoquest</groupId> 53 <artifactId>autoquest-htmlmonitor</artifactId> 54 <version>${tested-autoquest-version}</version> 55 <classifier>config</classifier> 56 <type>zip</type> 57 <outputDirectory>${basedir}/data</outputDirectory> 58 </artifactItem> 59 </artifactItems> 60 </configuration> 61 </execution> 62 <execution> 63 <id>get-html-plugin-config</id> 64 <phase>process-classes</phase> 65 <goals> 66 <goal>unpack</goal> 67 </goals> 68 <configuration> 69 <artifactItems> 70 <artifactItem> 71 <groupId>de.ugoe.cs.autoquest</groupId> 72 <artifactId>autoquest-plugin-html</artifactId> 73 <version>${tested-autoquest-version}</version> 74 <classifier>config</classifier> 75 <type>zip</type> 76 <outputDirectory>${basedir}/data</outputDirectory> 77 </artifactItem> 78 </artifactItems> 79 </configuration> 80 </execution> 81 </executions> 82 </plugin> 83 <plugin> 84 <artifactId>maven-clean-plugin</artifactId> 85 <version>2.5</version> 86 <configuration> 87 <filesets> 88 <fileset> 89 <directory>${basedir}/data</directory> 90 </fileset> 91 </filesets> 92 </configuration> 93 </plugin> 94 </plugins> 95 </build> 30 96 </project> -
trunk/autoquest-htmlmonitor-test/src/test/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorServerTest.java
r943 r1069 56 56 * 57 57 */ 58 private HtmlGUIElement guiStructure; 59 60 /** 61 * 62 */ 58 63 private String eventHandlingError; 59 64 … … 97 102 @Test 98 103 public void testSimpleMessage() throws Exception { 104 String clientId = "123"; 105 99 106 String message = 100 107 "{" + 101 108 " \"message\": {" + 102 109 " \"clientInfos\": {" + 103 " \"clientId\":\" 123\"," +110 " \"clientId\":\"" + clientId + "\"," + 104 111 " \"userAgent\":\"Agent\"," + 105 112 " \"title\":\"Title\"," + 106 113 " \"url\":\"http://host/path\"" + 107 114 " }," + 115 " \"guiModel\": {" + 116 " \"tagName\":\"html\"," + 117 " \"index\":\"0\"," + 118 " \"children\":" + 119 " [ {" + 120 " \"tagName\":\"head\"," + 121 " \"index\":\"0\"," + 122 " }," + 123 " {" + 124 " \"tagName\":\"body\"," + 125 " \"htmlId\":\"gsr\"," + 126 " }" + 127 " ]" + 128 " }," + 108 129 " \"events\":" + 109 130 " [ {" + 110 131 " \"time\":\"12345\"," + 111 " \"path\":\"/html[0]/body(id=gsr)\"," + 112 " \"eventType\":\"onunload\"" + 132 " \"path\":\"/html[0]/body(htmlId=gsr)\"," + 133 " \"eventType\":\"onclick\"" + 134 " \"coordinates\": [\"194\", \"7\"]" + 113 135 " }" + 114 136 " ]" + … … 122 144 } 123 145 146 // check the GUI structure 147 HtmlGUIElement parent = null; 148 HtmlGUIElement element = guiStructure; 149 150 assertGuiElement(element, HtmlServer.class, parent, 1); 151 152 parent = element; 153 element = parent.getChildren().get(0); 154 assertGuiElement(element, HtmlDocument.class, parent, 1); 155 156 HtmlDocument document = (HtmlDocument) element; 157 158 parent = element; 159 element = parent.getChildren().get(0); 160 assertGuiElement(element, HtmlPageElement.class, parent, 2); 161 162 parent = element; 163 element = parent.getChildren().get(0); 164 assertGuiElement(element, HtmlPageElement.class, parent, 0); 165 element = parent.getChildren().get(1); 166 assertGuiElement(element, HtmlPageElement.class, parent, 0); 167 168 // check the event 124 169 assertNotNull(events); 125 170 assertEquals(1, events.length); 126 171 127 assertEquals(new Long(12345), events[0].getTime()); 128 assertEquals("/html[0]/body(id=gsr)", events[0].getPath()); 129 assertEquals("onunload", events[0].getEventType()); 130 131 assertNull(events[0].getKey()); 132 assertNull(events[0].getScrollPosition()); 133 assertNull(events[0].getCoordinates()); 134 135 assertEquals("Title", events[0].getClientInfos().getTitle()); 136 assertEquals("Agent", events[0].getClientInfos().getUserAgent()); 137 assertEquals("http://host/path", events[0].getClientInfos().getUrl().toString()); 138 assertEquals("123", events[0].getClientInfos().getClientId()); 172 assertEvent(0, 12345, "/html[0]/body(htmlId=gsr)", element, document, "onclick", 173 null, null, new Integer[] {194, 7}, 174 "Title", "Agent", "http://host/path", "123"); 175 139 176 } 140 177 … … 144 181 @Test 145 182 public void testComplexMessage() throws Exception { 183 String clientId = "123"; 184 146 185 String message = 147 186 "{" + 148 187 " \"message\": {" + 149 188 " \"clientInfos\": {" + 150 " \"clientId\":\" 123\"," +189 " \"clientId\":\"" + clientId + "\"," + 151 190 " \"userAgent\":\"Agent\"," + 152 191 " \"title\":\"Title\"," + 153 192 " \"url\":\"http://host/path\"" + 154 193 " }," + 194 " \"guiModel\": {" + 195 " \"tagName\":\"html\"," + 196 " \"index\":\"0\"," + 197 " \"children\":" + 198 " [ {" + 199 " \"tagName\":\"head\"," + 200 " \"index\":\"0\"," + 201 " }," + 202 " {" + 203 " \"tagName\":\"body\"," + 204 " \"htmlId\":\"gsr\"," + 205 " \"children\":" + 206 " [ {" + 207 " \"tagName\":\"input_button\"," + 208 " \"htmlId\":\"input1\"," + 209 " }," + 210 " {" + 211 " \"tagName\":\"input_button\"," + 212 " \"htmlId\":\"input2\"," + 213 " }," + 214 " {" + 215 " \"tagName\":\"input_button\"," + 216 " \"htmlId\":\"input3\"," + 217 " }," + 218 " {" + 219 " \"tagName\":\"input_button\"," + 220 " \"htmlId\":\"input4\"," + 221 " }," + 222 " {" + 223 " \"tagName\":\"input_button\"," + 224 " \"htmlId\":\"input5\"," + 225 " }," + 226 " {" + 227 " \"tagName\":\"input_button\"," + 228 " \"htmlId\":\"input6\"," + 229 " }," + 230 " {" + 231 " \"tagName\":\"input_button\"," + 232 " \"htmlId\":\"input7\"," + 233 " }," + 234 " {" + 235 " \"tagName\":\"input_button\"," + 236 " \"htmlId\":\"input8\"," + 237 " }," + 238 " {" + 239 " \"tagName\":\"input_button\"," + 240 " \"htmlId\":\"input9\"," + 241 " }," + 242 " {" + 243 " \"tagName\":\"input_button\"," + 244 " \"htmlId\":\"input10\"," + 245 " }," + 246 " ]" + 247 " }" + 248 " ]" + 249 " }," + 155 250 " \"events\":" + 156 " [" + 157 " {" + 251 " [ {" + 158 252 " \"time\":\"1\"," + 159 " \"path\":\"/html[0]/body( id=gsr)/input(id=input1)\"," +253 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input1)\"," + 160 254 " \"eventType\":\"onclick\"," + 161 255 " \"coordinates\": [\"194\", \"7\"]" + … … 163 257 " {" + 164 258 " \"time\":\"2\"," + 165 " \"path\":\"/html[0]/body( id=gsr)/input(id=input2)\"," +259 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input2)\"," + 166 260 " \"eventType\":\"ondblclick\"," + 167 261 " \"coordinates\": [\"194\", \"7\"]" + … … 169 263 " {" + 170 264 " \"time\":\"3\"," + 171 " \"path\":\"/html[0]/body( id=gsr)/input(id=input3)\"," +265 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input3)\"," + 172 266 " \"eventType\":\"onfocus\"" + 173 267 " }," + 174 268 " {" + 175 269 " \"time\":\"4\"," + 176 " \"path\":\"/html[0]/body( id=gsr)/input(id=input4)\"," +270 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input4)\"," + 177 271 " \"eventType\":\"onclick\"," + 178 272 " \"coordinates\": [\"125\", \"14\"]" + … … 180 274 " {" + 181 275 " \"time\":\"5\"," + 182 " \"path\":\"/html[0]/body( id=gsr)/input(id=input5)\"," +276 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input5)\"," + 183 277 " \"eventType\":\"onfocus\"" + 184 278 " }," + 185 279 " {" + 186 280 " \"time\":\"6\"," + 187 " \"path\":\"/html[0]/body( id=gsr)/input(id=input6)\"," +281 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input6)\"," + 188 282 " \"eventType\":\"onfocus\"" + 189 283 " }," + 190 284 " {" + 191 285 " \"time\":\"7\"," + 192 " \"path\":\"/html[0]/body( id=gsr)/input(id=input7)\"," +286 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input7)\"," + 193 287 " \"eventType\":\"onfocus\"" + 194 288 " }," + 195 289 " {" + 196 290 " \"time\":\"8\"," + 197 " \"path\":\"/html[0]/body( id=gsr)/input(id=input8)\"," +291 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input8)\"," + 198 292 " \"eventType\":\"onclick\"," + 199 293 " \"coordinates\": [\"255\", \"4\"]" + … … 201 295 " {" + 202 296 " \"time\":\"9\"," + 203 " \"path\":\"/html[0]/body( id=gsr)\"," +297 " \"path\":\"/html[0]/body(htmlId=gsr)\"," + 204 298 " \"eventType\":\"onscroll\"," + 205 299 " \"scrollPosition\": [\"23\", \"567\"]" + … … 207 301 " {" + 208 302 " \"time\":\"10\"," + 209 " \"path\":\"/html[0]/body( id=gsr)/input(id=input10)\"," +303 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input10)\"," + 210 304 " \"eventType\":\"onclick\"," + 211 305 " \"coordinates\": [\"516\", \"154\"]" + … … 214 308 " }" + 215 309 "}"; 216 310 217 311 sendMessageAndAssertResponse(message); 218 312 … … 221 315 } 222 316 317 // check the GUI structure 318 HtmlGUIElement parent = null; 319 HtmlGUIElement element = guiStructure; 320 321 assertGuiElement(element, HtmlServer.class, parent, 1); 322 323 parent = element; 324 element = parent.getChildren().get(0); 325 assertGuiElement(element, HtmlDocument.class, parent, 1); 326 327 HtmlDocument document = (HtmlDocument) element; 328 329 parent = element; 330 element = parent.getChildren().get(0); 331 assertGuiElement(element, HtmlPageElement.class, parent, 2); 332 333 parent = element; 334 element = parent.getChildren().get(0); 335 assertGuiElement(element, HtmlPageElement.class, parent, 0); 336 element = parent.getChildren().get(1); 337 assertGuiElement(element, HtmlPageElement.class, parent, 10); 338 339 parent = element; 340 for (HtmlGUIElement child : parent.getChildren()) { 341 assertGuiElement(child, HtmlPageElement.class, parent, 0); 342 } 343 344 // check the events 223 345 assertNotNull(events); 224 346 assertEquals(10, events.length); 225 347 226 348 for (int i = 0; i < events.length; i++) { 227 assertEquals("event " + i, new Long(i + 1), events[i].getTime()); 349 String targetDOMPath; 350 HtmlGUIElement target; 351 Integer[] scrollPosition = null; 228 352 229 353 if (i == 8) { 230 assertEquals("event " + i, "/html[0]/body(id=gsr)", events[i].getPath()); 354 targetDOMPath = "/html[0]/body(htmlId=gsr)"; 355 target = parent; 356 scrollPosition = new Integer[] { 23, 567 }; 231 357 } 232 358 else { 233 assertEquals("event " + i, "/html[0]/body(id=gsr)/input(id=input" + (i + 1) + ")", 234 events[i].getPath()); 235 } 236 359 targetDOMPath = 360 "/html[0]/body(htmlId=gsr)/input_button(htmlId=input" + (i + 1) + ")"; 361 target = parent.getChildren().get(i); 362 } 363 364 String eventType; 237 365 if ((i == 1)) { 238 assertEquals("event " + i, "ondblclick", events[i].getEventType());366 eventType = "ondblclick"; 239 367 } 240 368 else if ((i == 2) || ((4 <= i) && (i <= 6))) { 241 assertEquals("event " + i, "onfocus", events[i].getEventType());369 eventType = "onfocus"; 242 370 } 243 371 else if ((i == 8)) { 244 assertEquals("event " + i, "onscroll", events[i].getEventType());372 eventType = "onscroll"; 245 373 } 246 374 else { 247 assertEquals("event " + i, "onclick", events[i].getEventType());375 eventType = "onclick"; 248 376 } 249 377 250 378 assertNull("event " + i, events[i].getKey()); 251 379 252 if ((i == 8)) { 253 assertNotNull("event " + i, events[i].getScrollPosition()); 254 assertArrayEquals 255 ("event " + i, new Integer[] { 23, 567 }, events[i].getScrollPosition()); 256 } 257 else { 258 assertNull("event " + i, events[i].getScrollPosition()); 259 } 260 261 if ((i == 2) || ((4 <= i) && (i <= 6)) || (i == 8)) { 262 assertNull("event " + i, events[i].getCoordinates()); 263 } 264 else { 265 assertNotNull("event " + i, events[i].getCoordinates()); 266 assertEquals("event " + i, 2, events[i].getCoordinates().length); 267 } 268 269 assertEquals("event " + i, "Title", events[i].getClientInfos().getTitle()); 270 assertEquals("event " + i, "Agent", events[i].getClientInfos().getUserAgent()); 271 assertEquals("event " + i, "http://host/path", 272 events[i].getClientInfos().getUrl().toString()); 273 assertEquals("event " + i, "123", events[i].getClientInfos().getClientId()); 380 Integer[] coordinates = null; 381 if (i <= 1) { 382 coordinates = new Integer[] { 194, 7 }; 383 } 384 else if (i == 3) { 385 coordinates = new Integer[] { 125, 14 }; 386 } 387 else if (i == 7) { 388 coordinates = new Integer[] { 255, 4 }; 389 } 390 else if (i == 9) { 391 coordinates = new Integer[] { 516, 154 }; 392 } 393 394 assertEvent(i, i + 1, targetDOMPath, target, document, eventType, 395 null, scrollPosition, coordinates, 396 "Title", "Agent", "http://host/path", "123"); 397 274 398 } 275 399 } … … 310 434 " \"url\":\"http://host/path\"" + 311 435 " }," + 436 " \"guiModel\": {" + 437 " \"tagName\":\"html\"," + 438 " \"index\":\"0\"," + 439 " \"children\":" + 440 " [ {" + 441 " \"tagName\":\"head\"," + 442 " \"index\":\"0\"," + 443 " }," + 444 " {" + 445 " \"tagName\":\"body\"," + 446 " \"htmlId\":\"gsr\"," + 447 " }" + 448 " ]" + 449 " }," + 312 450 " \"events\":" + 313 451 " [ {" + 314 " \"time\":\" 12345\"," +315 " \"path\":\"/html[0]/body( id=gsr)\"," +316 " \"eventType\":\"onscroll\" " +452 " \"time\":\"9\"," + 453 " \"path\":\"/html[0]/body(htmlId=gsr)\"," + 454 " \"eventType\":\"onscroll\"," + 317 455 " }" + 318 456 " ]" + … … 337 475 " \"url\":\"http://host/path\"" + 338 476 " }," + 477 " \"guiModel\": {" + 478 " \"tagName\":\"html\"," + 479 " \"index\":\"0\"," + 480 " \"children\":" + 481 " [ {" + 482 " \"tagName\":\"head\"," + 483 " \"index\":\"0\"," + 484 " }," + 485 " {" + 486 " \"tagName\":\"body\"," + 487 " \"htmlId\":\"gsr\"," + 488 " }" + 489 " ]" + 490 " }," + 339 491 " \"events\":" + 340 492 " [ {" + 341 493 " \"time\":\"12345\"," + 342 " \"path\":\"/html[0]/body( id=gsr)\"," +494 " \"path\":\"/html[0]/body(htmlId=gsr)\"," + 343 495 " \"eventType\":\"onunload\"" + 344 496 " }" + … … 365 517 " \"url\":\"http://host/path\"" + 366 518 " }," + 519 " \"guiModel\": {" + 520 " \"tagName\":\"html\"," + 521 " \"index\":\"0\"," + 522 " \"children\":" + 523 " [ {" + 524 " \"tagName\":\"head\"," + 525 " \"index\":\"0\"," + 526 " }," + 527 " {" + 528 " \"tagName\":\"body\"," + 529 " \"htmlId\":\"gsr\"," + 530 " }" + 531 " ]" + 532 " }," + 367 533 " \"events\":" + 368 534 " [ {" + 369 535 " \"time\":\"blub\"," + 370 " \"path\":\"/html[0]/body( id=gsr)\"," +536 " \"path\":\"/html[0]/body(htmlId=gsr)\"," + 371 537 " \"eventType\":\"onunload\"" + 372 538 " }" + … … 389 555 */ 390 556 @Override 391 public void handleMessage(HtmlClientInfos clientInfos, HtmlEvent[] events) { 557 public void handleMessage(HtmlClientInfos clientInfos, 558 HtmlGUIElement guiStructure, 559 HtmlEvent[] events) 560 { 392 561 if (clientInfos == null) { 393 562 eventHandlingError = "client infos were null"; 563 } 564 else if (guiStructure == null) { 565 eventHandlingError = "gui structure was null"; 394 566 } 395 567 else if (events == null) { … … 404 576 405 577 this.events = events; 578 this.guiStructure = guiStructure; 406 579 } 407 580 } … … 435 608 } 436 609 610 /** 611 * 612 */ 613 private void assertGuiElement(HtmlGUIElement element, 614 Class<? extends HtmlGUIElement> type, 615 HtmlGUIElement parent, 616 int noOfChildren) 617 { 618 assertTrue(type.isInstance(element)); 619 620 if (parent != null) { 621 assertEquals(parent.getId(), element.getParentId()); 622 } 623 else { 624 assertNull(element.getParentId()); 625 } 626 627 assertNotNull(element.getId()); 628 629 if (noOfChildren > 0) { 630 assertNotNull(element.getChildren()); 631 assertEquals(noOfChildren, element.getChildren().size()); 632 } 633 else { 634 assertNull(element.getChildren()); 635 } 636 } 637 638 /** 639 * 640 */ 641 private void assertEvent(int index, 642 long timestamp, 643 String targetDOMPath, 644 HtmlGUIElement target, 645 HtmlDocument document, 646 String eventType, 647 Integer key, 648 Integer[] scrollPosition, 649 Integer[] coordinates, 650 String clientInfoTitle, 651 String clientInfoAgent, 652 String clientInfoURL, 653 String clientId) 654 { 655 assertEquals("event " + index, new Long(timestamp), events[index].getTime()); 656 assertEquals("event " + index, targetDOMPath, events[index].getTargetDOMPath()); 657 assertEquals("event " + index, target, events[index].getTarget()); 658 assertEquals("event " + index, document, events[index].getTargetDocument()); 659 assertEquals("event " + index, eventType, events[index].getEventType()); 660 661 assertEquals("event " + index, key, events[index].getKey()); 662 assertArrayEquals("event " + index, scrollPosition, events[index].getScrollPosition()); 663 assertArrayEquals("event " + index, coordinates, events[index].getCoordinates()); 664 665 assertEquals 666 ("event " + index, clientInfoTitle, events[index].getClientInfos().getTitle()); 667 assertEquals 668 ("event " + index, clientInfoAgent, events[index].getClientInfos().getUserAgent()); 669 assertEquals 670 ("event " + index, clientInfoURL, events[index].getClientInfos().getUrl().toString()); 671 assertEquals 672 ("event " + index, clientId, events[index].getClientInfos().getClientId()); 673 } 674 437 675 } -
trunk/autoquest-htmlmonitor-test/src/test/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorTest.java
r943 r1069 17 17 import static org.junit.Assert.*; 18 18 19 import java.io.BufferedReader;20 19 import java.io.File; 21 import java.io.FileInputStream; 22 import java.io.InputStreamReader; 23 import java.util.ArrayList; 20 import java.util.Collection; 21 import java.util.Iterator; 24 22 import java.util.List; 25 23 … … 34 32 import org.junit.Test; 35 33 34 import de.ugoe.cs.autoquest.eventcore.Event; 35 import de.ugoe.cs.autoquest.eventcore.IEventType; 36 import de.ugoe.cs.autoquest.eventcore.gui.KeyboardFocusChange; 37 import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction; 38 import de.ugoe.cs.autoquest.eventcore.gui.MouseClick; 39 import de.ugoe.cs.autoquest.eventcore.gui.MouseDoubleClick; 40 import de.ugoe.cs.autoquest.eventcore.gui.Scroll; 41 import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel; 42 import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; 43 import de.ugoe.cs.autoquest.plugin.html.HTMLLogParser; 44 import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLDocument; 45 import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPageElement; 46 import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLServer; 36 47 import de.ugoe.cs.util.console.TextConsole; 37 48 … … 108 119 " \"url\":\"http://host/path\"" + 109 120 " }," + 121 " \"guiModel\": {" + 122 " \"tagName\":\"html\"," + 123 " \"index\":\"0\"," + 124 " \"children\":" + 125 " [ {" + 126 " \"tagName\":\"head\"," + 127 " \"index\":\"0\"," + 128 " }," + 129 " {" + 130 " \"tagName\":\"body\"," + 131 " \"htmlId\":\"gsr\"," + 132 " }" + 133 " ]" + 134 " }," + 110 135 " \"events\":" + 111 136 " [ {" + 112 137 " \"time\":\"12345\"," + 113 " \"path\":\"/html[0]/body(id=gsr)\"," + 114 " \"eventType\":\"onunload\"" + 138 " \"path\":\"/html[0]/body(htmlId=gsr)\"," + 139 " \"eventType\":\"onclick\"" + 140 " \"coordinates\": [\"194\", \"7\"]" + 115 141 " }" + 116 142 " ]" + … … 120 146 sendMessageAndAssertResponse(message); 121 147 148 htmlMonitor.stop(); 149 htmlMonitor = null; 150 122 151 File logFile = new File(LOG_FILE_DIR + File.separator + clientId + File.separator + 123 "htmlmonitor_" + clientId + " .log");152 "htmlmonitor_" + clientId + "_000.log"); 124 153 125 154 assertTrue(logFile.exists()); 126 155 127 String[] logEntries = readLogEntries(logFile); 128 assertEquals(1, logEntries.length); 129 130 assertLogMessage(logEntries[0], clientId, "12345", "Title", "http://host/path", "Agent", 131 "onunload", "/html[0]/body(id=gsr)"); 156 HTMLLogParser parser = new HTMLLogParser(); 157 158 parser.parseFile(logFile); 159 160 // check the GUI model 161 GUIModel guiModel = parser.getGuiModel(); 162 assertNotNull(guiModel); 163 164 List<IGUIElement> nodes = guiModel.getRootElements(); 165 assertNotNull(nodes); 166 assertEquals(1, nodes.size()); 167 168 // get server node 169 IGUIElement node = nodes.get(0); 170 assertNotNull(node); 171 assertTrue(node instanceof HTMLServer); 172 assertEquals("HTML", node.getPlatform()); 173 assertFalse(node.isUsed()); 174 175 nodes = guiModel.getChildren(node); 176 assertNotNull(nodes); 177 assertEquals(1, nodes.size()); 178 179 // get document node 180 node = nodes.get(0); 181 assertNotNull(node); 182 assertTrue(node instanceof HTMLDocument); 183 assertEquals("HTML", node.getPlatform()); 184 assertFalse(node.isUsed()); 185 186 nodes = guiModel.getChildren(node); 187 assertNotNull(nodes); 188 assertEquals(1, nodes.size()); 189 190 // get html node 191 node = nodes.get(0); 192 assertNotNull(node); 193 assertTrue(node instanceof HTMLPageElement); 194 assertEquals("HTML", node.getPlatform()); 195 assertFalse(node.isUsed()); 196 197 nodes = guiModel.getChildren(node); 198 assertNotNull(nodes); 199 assertEquals(1, nodes.size()); // only one child as the head tag should have been ignored 200 201 // get body node 202 node = nodes.get(0); 203 assertNotNull(node); 204 assertTrue(node instanceof HTMLPageElement); 205 assertEquals("HTML", node.getPlatform()); 206 assertTrue(node.isUsed()); 207 208 nodes = guiModel.getChildren(node); 209 assertNotNull(nodes); 210 assertEquals(0, nodes.size()); 211 212 // check the sequences 213 Collection<List<Event>> sequences = parser.getSequences(); 214 215 assertNotNull(sequences); 216 217 Iterator<List<Event>> iterator = sequences.iterator(); 218 assertTrue(iterator.hasNext()); 219 220 List<Event> sequence = iterator.next(); 221 assertFalse(iterator.hasNext()); 222 223 assertNotNull(sequence); 224 assertEquals(1, sequence.size()); 225 226 assertEvent(sequence.get(0), 12345, MouseClick.class, node, 194, 7); 132 227 } 133 228 … … 148 243 " \"url\":\"http://host/path\"" + 149 244 " }," + 245 " \"guiModel\": {" + 246 " \"tagName\":\"html\"," + 247 " \"index\":\"0\"," + 248 " \"children\":" + 249 " [ {" + 250 " \"tagName\":\"head\"," + 251 " \"index\":\"0\"," + 252 " }," + 253 " {" + 254 " \"tagName\":\"body\"," + 255 " \"htmlId\":\"gsr\"," + 256 " \"children\":" + 257 " [ {" + 258 " \"tagName\":\"input_button\"," + 259 " \"htmlId\":\"input1\"," + 260 " }," + 261 " {" + 262 " \"tagName\":\"input_button\"," + 263 " \"htmlId\":\"input2\"," + 264 " }," + 265 " {" + 266 " \"tagName\":\"input_button\"," + 267 " \"htmlId\":\"input3\"," + 268 " }," + 269 " {" + 270 " \"tagName\":\"input_button\"," + 271 " \"htmlId\":\"input4\"," + 272 " }," + 273 " {" + 274 " \"tagName\":\"input_button\"," + 275 " \"htmlId\":\"input5\"," + 276 " }," + 277 " {" + 278 " \"tagName\":\"input_button\"," + 279 " \"htmlId\":\"input6\"," + 280 " }," + 281 " {" + 282 " \"tagName\":\"input_button\"," + 283 " \"htmlId\":\"input7\"," + 284 " }," + 285 " {" + 286 " \"tagName\":\"input_button\"," + 287 " \"htmlId\":\"input8\"," + 288 " }," + 289 " {" + 290 " \"tagName\":\"input_button\"," + 291 " \"htmlId\":\"input9\"," + 292 " }," + 293 " {" + 294 " \"tagName\":\"input_button\"," + 295 " \"htmlId\":\"input10\"," + 296 " }," + 297 " ]" + 298 " }" + 299 " ]" + 300 " }," + 150 301 " \"events\":" + 151 " [" + 152 " {" + 302 " [ {" + 153 303 " \"time\":\"1\"," + 154 " \"path\":\"/html[0]/body( id=gsr)/input(id=input1)\"," +304 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input1)\"," + 155 305 " \"eventType\":\"onclick\"," + 156 306 " \"coordinates\": [\"194\", \"7\"]" + … … 158 308 " {" + 159 309 " \"time\":\"2\"," + 160 " \"path\":\"/html[0]/body( id=gsr)/input(id=input2)\"," +310 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input2)\"," + 161 311 " \"eventType\":\"ondblclick\"," + 162 312 " \"coordinates\": [\"194\", \"7\"]" + … … 164 314 " {" + 165 315 " \"time\":\"3\"," + 166 " \"path\":\"/html[0]/body( id=gsr)/input(id=input3)\"," +316 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input3)\"," + 167 317 " \"eventType\":\"onfocus\"" + 168 318 " }," + 169 319 " {" + 170 320 " \"time\":\"4\"," + 171 " \"path\":\"/html[0]/body( id=gsr)/input(id=input4)\"," +321 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input4)\"," + 172 322 " \"eventType\":\"onclick\"," + 173 323 " \"coordinates\": [\"125\", \"14\"]" + … … 175 325 " {" + 176 326 " \"time\":\"5\"," + 177 " \"path\":\"/html[0]/body( id=gsr)/input(id=input5)\"," +327 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input5)\"," + 178 328 " \"eventType\":\"onfocus\"" + 179 329 " }," + 180 330 " {" + 181 331 " \"time\":\"6\"," + 182 " \"path\":\"/html[0]/body( id=gsr)/input(id=input6)\"," +332 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input6)\"," + 183 333 " \"eventType\":\"onfocus\"" + 184 334 " }," + 185 335 " {" + 186 336 " \"time\":\"7\"," + 187 " \"path\":\"/html[0]/body( id=gsr)/input(id=input7)\"," +337 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input7)\"," + 188 338 " \"eventType\":\"onfocus\"" + 189 339 " }," + 190 340 " {" + 191 341 " \"time\":\"8\"," + 192 " \"path\":\"/html[0]/body( id=gsr)/input(id=input8)\"," +342 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input8)\"," + 193 343 " \"eventType\":\"onclick\"," + 194 344 " \"coordinates\": [\"255\", \"4\"]" + … … 196 346 " {" + 197 347 " \"time\":\"9\"," + 198 " \"path\":\"/html[0]/body( id=gsr)\"," +348 " \"path\":\"/html[0]/body(htmlId=gsr)\"," + 199 349 " \"eventType\":\"onscroll\"," + 200 350 " \"scrollPosition\": [\"23\", \"567\"]" + … … 202 352 " {" + 203 353 " \"time\":\"10\"," + 204 " \"path\":\"/html[0]/body( id=gsr)/input(id=input10)\"," +354 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input10)\"," + 205 355 " \"eventType\":\"onclick\"," + 206 356 " \"coordinates\": [\"516\", \"154\"]" + … … 212 362 sendMessageAndAssertResponse(message); 213 363 364 htmlMonitor.stop(); 365 htmlMonitor = null; 366 214 367 File logFile = new File(LOG_FILE_DIR + File.separator + clientId + File.separator + 215 "htmlmonitor_" + clientId + " .log");368 "htmlmonitor_" + clientId + "_000.log"); 216 369 217 370 assertTrue(logFile.exists()); 218 371 219 String[] logEntries = readLogEntries(logFile); 220 assertEquals(10, logEntries.length); 221 222 assertLogMessage(logEntries[0], clientId, "1", "Title", "http://host/path", "Agent", 223 "onclick", "/html[0]/body(id=gsr)/input(id=input1)", "194,7"); 224 assertLogMessage(logEntries[1], clientId, "2", "Title", "http://host/path", "Agent", 225 "ondblclick", "/html[0]/body(id=gsr)/input(id=input2)", "194,7"); 226 assertLogMessage(logEntries[2], clientId, "3", "Title", "http://host/path", "Agent", 227 "onfocus", "/html[0]/body(id=gsr)/input(id=input3)"); 228 assertLogMessage(logEntries[3], clientId, "4", "Title", "http://host/path", "Agent", 229 "onclick", "/html[0]/body(id=gsr)/input(id=input4)", "125,14"); 230 assertLogMessage(logEntries[4], clientId, "5", "Title", "http://host/path", "Agent", 231 "onfocus", "/html[0]/body(id=gsr)/input(id=input5)"); 232 assertLogMessage(logEntries[5], clientId, "6", "Title", "http://host/path", "Agent", 233 "onfocus", "/html[0]/body(id=gsr)/input(id=input6)"); 234 assertLogMessage(logEntries[6], clientId, "7", "Title", "http://host/path", "Agent", 235 "onfocus", "/html[0]/body(id=gsr)/input(id=input7)"); 236 assertLogMessage(logEntries[7], clientId, "8", "Title", "http://host/path", "Agent", 237 "onclick", "/html[0]/body(id=gsr)/input(id=input8)", "255,4"); 238 assertLogMessage(logEntries[8], clientId, "9", "Title", "http://host/path", "Agent", 239 "onscroll", "/html[0]/body(id=gsr)", "23,567"); 240 assertLogMessage(logEntries[9], clientId, "10", "Title", "http://host/path", "Agent", 241 "onclick", "/html[0]/body(id=gsr)/input(id=input10)", "516,154"); 372 HTMLLogParser parser = new HTMLLogParser(); 373 374 parser.parseFile(logFile); 375 376 // check the GUI model 377 GUIModel guiModel = parser.getGuiModel(); 378 assertNotNull(guiModel); 379 380 List<IGUIElement> nodes = guiModel.getRootElements(); 381 assertNotNull(nodes); 382 assertEquals(1, nodes.size()); 383 384 // get server node 385 IGUIElement node = nodes.get(0); 386 assertNotNull(node); 387 assertTrue(node instanceof HTMLServer); 388 assertEquals("HTML", node.getPlatform()); 389 assertFalse(node.isUsed()); 390 391 nodes = guiModel.getChildren(node); 392 assertNotNull(nodes); 393 assertEquals(1, nodes.size()); 394 395 // get document node 396 node = nodes.get(0); 397 assertNotNull(node); 398 assertTrue(node instanceof HTMLDocument); 399 assertEquals("HTML", node.getPlatform()); 400 assertFalse(node.isUsed()); 401 402 nodes = guiModel.getChildren(node); 403 assertNotNull(nodes); 404 assertEquals(1, nodes.size()); 405 406 // get html node 407 node = nodes.get(0); 408 assertNotNull(node); 409 assertTrue(node instanceof HTMLPageElement); 410 assertEquals("HTML", node.getPlatform()); 411 assertFalse(node.isUsed()); 412 413 nodes = guiModel.getChildren(node); 414 assertNotNull(nodes); 415 assertEquals(1, nodes.size()); // only one child as the head tag should have been ignored 416 417 // get body node 418 IGUIElement body = nodes.get(0); 419 assertNotNull(body); 420 assertTrue(body instanceof HTMLPageElement); 421 assertEquals("HTML", body.getPlatform()); 422 assertTrue(body.isUsed()); 423 424 nodes = guiModel.getChildren(body); 425 assertNotNull(nodes); 426 assertEquals(10, nodes.size()); 427 428 // get input nodes 429 for (int i = 0; i < nodes.size(); i++) { 430 node = nodes.get(i); 431 assertNotNull(node); 432 assertTrue(node instanceof HTMLPageElement); 433 assertEquals("HTML", node.getPlatform()); 434 435 if (i != 8) { 436 assertTrue(node.isUsed()); 437 } 438 else { 439 assertFalse(node.isUsed()); 440 } 441 442 assertNotNull(guiModel.getChildren(node)); 443 assertEquals(0, guiModel.getChildren(node).size()); 444 } 445 446 // check the sequences 447 Collection<List<Event>> sequences = parser.getSequences(); 448 449 assertNotNull(sequences); 450 451 Iterator<List<Event>> iterator = sequences.iterator(); 452 assertTrue(iterator.hasNext()); 453 454 List<Event> sequence = iterator.next(); 455 assertFalse(iterator.hasNext()); 456 457 assertNotNull(sequence); 458 assertEquals(10, sequence.size()); 459 460 assertEvent(sequence.get(0), 1, MouseClick.class, nodes.get(0), 194, 7); 461 assertEvent(sequence.get(1), 2, MouseDoubleClick.class, nodes.get(1), 194, 7); 462 assertEvent(sequence.get(2), 3, KeyboardFocusChange.class, nodes.get(2), 0, 0); 463 assertEvent(sequence.get(3), 4, MouseClick.class, nodes.get(3), 125, 14); 464 assertEvent(sequence.get(4), 5, KeyboardFocusChange.class, nodes.get(4), 0, 0); 465 assertEvent(sequence.get(5), 6, KeyboardFocusChange.class, nodes.get(5), 0, 0); 466 assertEvent(sequence.get(6), 7, KeyboardFocusChange.class, nodes.get(6), 0, 0); 467 assertEvent(sequence.get(7), 8, MouseClick.class, nodes.get(7), 255, 4); 468 assertEvent(sequence.get(8), 9, Scroll.class, body, 0, 0); 469 assertEvent(sequence.get(9), 10, MouseClick.class, nodes.get(9), 516, 154); 470 242 471 } 243 472 … … 258 487 " \"url\":\"http://host/path\"" + 259 488 " }," + 489 " \"guiModel\": {" + 490 " \"tagName\":\"html\"," + 491 " \"index\":\"0\"," + 492 " \"children\":" + 493 " [ {" + 494 " \"tagName\":\"head\"," + 495 " \"index\":\"0\"," + 496 " }," + 497 " {" + 498 " \"tagName\":\"body\"," + 499 " \"htmlId\":\"gsr\"," + 500 " }" + 501 " ]" + 502 " }," + 260 503 " \"events\":" + 261 504 " [ {" + 262 505 " \"time\":\"12345\"," + 263 " \"path\":\"/html[0]/body(id=gsr)\"," + 264 " \"eventType\":\"onunload\"" + 506 " \"path\":\"/html[0]/body(htmlId=gsr)\"," + 507 " \"eventType\":\"onclick\"" + 508 " \"coordinates\": [\"194\", \"7\"]" + 265 509 " }" + 266 510 " ]" + … … 279 523 } 280 524 525 htmlMonitor.stop(); 526 htmlMonitor = null; 527 528 HTMLLogParser parser = new HTMLLogParser(); 529 281 530 // assert 9 already rotated log files 282 for (int i = 0; i < (numberOfSessions - 1); i++) {531 for (int i = 0; i < numberOfSessions; i++) { 283 532 File logFile = new File(LOG_FILE_DIR + File.separator + clientId + File.separator + 284 533 "htmlmonitor_" + clientId + "_00" + i + ".log"); … … 286 535 assertTrue(logFile.exists()); 287 536 288 String[] logEntries = readLogEntries(logFile); 289 assertEquals(1, logEntries.length); 537 parser.parseFile(logFile); 538 } 539 540 // check the GUI model 541 GUIModel guiModel = parser.getGuiModel(); 542 assertNotNull(guiModel); 543 544 List<IGUIElement> nodes = guiModel.getRootElements(); 545 assertNotNull(nodes); 546 assertEquals(1, nodes.size()); 547 548 // get server node 549 IGUIElement node = nodes.get(0); 550 assertNotNull(node); 551 assertTrue(node instanceof HTMLServer); 552 assertEquals("HTML", node.getPlatform()); 553 assertFalse(node.isUsed()); 554 555 nodes = guiModel.getChildren(node); 556 assertNotNull(nodes); 557 assertEquals(1, nodes.size()); 558 559 // get document node 560 node = nodes.get(0); 561 assertNotNull(node); 562 assertTrue(node instanceof HTMLDocument); 563 assertEquals("HTML", node.getPlatform()); 564 assertFalse(node.isUsed()); 565 566 nodes = guiModel.getChildren(node); 567 assertNotNull(nodes); 568 assertEquals(1, nodes.size()); 569 570 // get html node 571 node = nodes.get(0); 572 assertNotNull(node); 573 assertTrue(node instanceof HTMLPageElement); 574 assertEquals("HTML", node.getPlatform()); 575 assertFalse(node.isUsed()); 576 577 nodes = guiModel.getChildren(node); 578 assertNotNull(nodes); 579 assertEquals(1, nodes.size()); // only one child as the head tag should have been ignored 580 581 // get body node 582 node = nodes.get(0); 583 assertNotNull(node); 584 assertTrue(node instanceof HTMLPageElement); 585 assertEquals("HTML", node.getPlatform()); 586 assertTrue(node.isUsed()); 587 588 nodes = guiModel.getChildren(node); 589 assertNotNull(nodes); 590 assertEquals(0, nodes.size()); 591 592 // check the sequences 593 Collection<List<Event>> sequences = parser.getSequences(); 594 595 assertNotNull(sequences); 596 assertEquals(numberOfSessions, sequences.size()); 597 598 Iterator<List<Event>> iterator = sequences.iterator(); 599 600 while (iterator.hasNext()) { 601 List<Event> sequence = iterator.next(); 602 603 assertNotNull(sequence); 604 assertEquals(1, sequence.size()); 290 605 291 assertLogMessage(logEntries[0], clientId, "12345", "Title", "http://host/path", "Agent", 292 "onunload", "/html[0]/body(id=gsr)"); 293 } 294 295 // and now the last but current one 296 File logFile = new File(LOG_FILE_DIR + File.separator + clientId + File.separator + 297 "htmlmonitor_" + clientId + ".log"); 298 299 assertTrue(logFile.exists()); 300 301 String[] logEntries = readLogEntries(logFile); 302 assertEquals(1, logEntries.length); 303 304 assertLogMessage(logEntries[0], clientId, "12345", "Title", "http://host/path", "Agent", 305 "onunload", "/html[0]/body(id=gsr)"); 606 assertEvent(sequence.get(0), 12345, MouseClick.class, node, 194, 7); 607 } 306 608 } 307 609 … … 335 637 336 638 /** 337 * <p> 338 * TODO: comment 339 * </p> 340 * 341 * @param logFile 342 * @return 343 */ 344 private String[] readLogEntries(File logFile) throws Exception { 345 List<String> logEntries = new ArrayList<String>(); 346 BufferedReader reader = null; 347 348 try { 349 reader = new BufferedReader 350 (new InputStreamReader(new FileInputStream(logFile))); 351 352 String line = null; 353 while ((line = reader.readLine()) != null) { 354 logEntries.add(line); 355 } 356 } 357 finally { 358 if (reader != null) { 359 reader.close(); 360 } 361 } 362 363 return logEntries.toArray(new String[logEntries.size()]); 364 } 365 366 /** 367 * 368 */ 369 private void assertLogMessage(String logMessage, 370 String... assertedMessageContent) 639 * 640 */ 641 private void assertEvent(Event event, 642 int timestamp, 643 Class<? extends IEventType> eventType, 644 IGUIElement eventTarget, 645 int xCoordinate, 646 int yCoordinate) 371 647 { 372 StringBuffer assertedMessage = new StringBuffer(); 373 374 for (int i = 0; i < assertedMessageContent.length; i++) { 375 if (i > 0) { 376 assertedMessage.append(' '); 377 } 378 379 assertedMessage.append('"'); 380 assertedMessage.append(assertedMessageContent[i]); 381 assertedMessage.append('"'); 382 } 383 384 assertEquals(assertedMessage.toString(), logMessage); 648 assertEquals(timestamp, event.getTimestamp()); 649 assertTrue(eventType.isInstance(event.getType())); 650 assertEquals(eventTarget, event.getTarget()); 651 652 if (event.getType() instanceof MouseButtonInteraction) { 653 assertEquals(xCoordinate, ((MouseButtonInteraction) event.getType()).getX()); 654 assertEquals(yCoordinate, ((MouseButtonInteraction) event.getType()).getY()); 655 } 385 656 } 386 657 -
trunk/autoquest-htmlmonitor-test/src/test/resources/test.html
r1000 r1069 5 5 <script type="text/javascript" 6 6 src="http://localhost:8090/script/autoquest-htmlmonitor.js"></script> 7 8 <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script> 7 9 8 10 <style type="text/css"> … … 16 18 17 19 </style> 18 20 <meta http-equiv="Content-type" content="text/html;charset=UTF-8"> 19 21 </head> 20 22 … … 30 32 <tr> 31 33 <td class="label">input type text</td> 32 <td><input type="text" ></input></td>34 <td><input type="text" /></td> 33 35 </tr> 34 36 <tr> … … 38 40 <tr> 39 41 <td class="label"></td> 40 <td><input type="button" value="Daten abschicken" onclick="sendRequest();" ></input></td>42 <td><input type="button" value="Daten abschicken" onclick="sendRequest();" /></td> 41 43 </tr> 42 44 </table> -
trunk/autoquest-htmlmonitor/.settings/org.eclipse.core.resources.prefs
r918 r1069 1 1 eclipse.preferences.version=1 2 encoding//src/main/java=UTF-8 3 encoding//src/main/js=UTF-8 2 4 encoding/<project>=UTF-8 -
trunk/autoquest-htmlmonitor/pom.xml
r938 r1069 56 56 <artifactId>json-simple</artifactId> 57 57 <version>1.1.1</version> 58 </dependency> 59 <dependency> 60 <groupId>commons-codec</groupId> 61 <artifactId>commons-codec</artifactId> 62 <version>1.7</version> 58 63 </dependency> 59 64 </dependencies> … … 118 123 <descriptors> 119 124 <descriptor>src/main/assembly/bin.xml</descriptor> 125 <descriptor>src/main/assembly/config.xml</descriptor> 120 126 </descriptors> 121 127 </configuration> -
trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlEvent.java
r942 r1069 38 38 39 39 /** 40 * the path in the HTML DOM to the object on which the event was executed 41 */ 42 private String path; 40 * the HTML element on which the event was executed 41 */ 42 private HtmlPageElement target; 43 44 /** 45 * the document to which the HTML element on which the event was executed belongs 46 */ 47 private HtmlDocument targetDocument; 48 49 /** 50 * the targets DOM path through the document to which it belongs 51 */ 52 private String targetDOMPath; 43 53 44 54 /** … … 69 79 /** 70 80 * <p> 71 * initializes the event with all relevant infos81 * initializes the event with all relevant infos 72 82 * </p> 73 83 * 74 84 * @param clientInfos infos about the client that caused the event 75 85 * @param time the time stamp of the event 76 * @param path the path in the HTML DOM to the object on which the event was executed86 * @param target the HTML element on which the event was executed 77 87 * @param eventType the type of the event, e.g. onclick 78 88 * @param coordinates the coordinates of the event, usually an array with two values … … 86 96 HtmlEvent(HtmlClientInfos clientInfos, 87 97 Long time, 88 String path,98 HtmlPageElement target, 89 99 String eventType, 90 100 Integer[] coordinates, … … 95 105 this.clientInfos = clientInfos; 96 106 this.time = time; 97 this.path = path; 107 this.target = target; 108 this.targetDocument = target.getDocument(); 109 this.targetDOMPath = target.getDOMPath(); 98 110 this.eventType = eventType; 99 111 this.coordinates = coordinates; … … 104 116 105 117 /** 118 * <p> 119 * initializes the event for which the id of the target is not known yet. In this case 120 * the document and DOM path for the target are provided 121 * </p> 122 * 123 * @param clientInfos infos about the client that caused the event 124 * @param time the time stamp of the event 125 * @param targetDocument the document to which the HTML element belongs on which the event was 126 * executed 127 * @param targetDOMPath the path through the DOM of the document of the HTML element on which 128 * the event was executed 129 * @param eventType the type of the event, e.g. onclick 130 * @param coordinates the coordinates of the event, usually an array with two values 131 * (x and y) 132 * @param key if the event is a key event, the key that was pressed or released 133 * @param scrollPosition if the event is a scroll event, the resulting position of the 134 * scrolled element 135 * @param selectedValue if the event is an on change event, the value to which the changed 136 * element is changed 137 */ 138 HtmlEvent(HtmlClientInfos clientInfos, 139 Long time, 140 HtmlDocument targetDocument, 141 String targetDOMPath, 142 String eventType, 143 Integer[] coordinates, 144 Integer key, 145 Integer[] scrollPosition, 146 String selectedValue) 147 { 148 this.clientInfos = clientInfos; 149 this.time = time; 150 this.targetDocument = targetDocument; 151 this.targetDOMPath = targetDOMPath; 152 this.eventType = eventType; 153 this.coordinates = coordinates; 154 this.key = key; 155 this.scrollPosition = scrollPosition; 156 this.selectedValue = selectedValue; 157 } 158 159 /** 106 160 * @return the clientInfos 107 161 */ … … 118 172 119 173 /** 120 * @return the path 121 */ 122 String getPath() { 123 return path; 174 * @return the target 175 */ 176 HtmlPageElement getTarget() { 177 return target; 178 } 179 180 /** 181 * @return the targetDocument 182 */ 183 HtmlDocument getTargetDocument() { 184 return targetDocument; 185 } 186 187 /** 188 * @return the targetDOMPath 189 */ 190 String getTargetDOMPath() { 191 return targetDOMPath; 124 192 } 125 193 -
trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorLogManager.java
r1019 r1069 116 116 @Override 117 117 public void handleMessage(HtmlClientInfos clientInfos, 118 Html PageElementguiStructure,118 HtmlGUIElement guiStructure, 119 119 HtmlEvent[] events) 120 120 { … … 140 140 Console.printerrln("could not handle message of client " + clientInfos.getClientId() + 141 141 ": " + e); 142 e.printStackTrace(); 142 143 Console.logException(e); 143 144 -
trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorMessageListener.java
r1022 r1069 36 36 */ 37 37 void handleMessage(HtmlClientInfos clientInfos, 38 Html PageElementguiStructure,38 HtmlGUIElement guiStructure, 39 39 HtmlEvent[] events); 40 40 -
trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorOutputWriter.java
r1022 r1069 179 179 @Override 180 180 public void handleMessage(HtmlClientInfos clientInfos, 181 Html PageElementguiStructure,181 HtmlGUIElement guiStructure, 182 182 HtmlEvent[] events) 183 183 { … … 214 214 * @param guiStructure the GUI structure to be logged 215 215 */ 216 private void dumpGuiStructure(Html PageElement guiStructure) {217 outputWriter.print("<component path=\"");218 outputWriter.print(guiStructure.get Path());216 private void dumpGuiStructure(HtmlGUIElement guiStructure) { 217 outputWriter.print("<component id=\""); 218 outputWriter.print(guiStructure.getId()); 219 219 outputWriter.println("\">"); 220 220 221 dumpParam("class", guiStructure.getTagName()); 222 dumpParam("htmlId", guiStructure.getId()); 223 dumpParam("title", guiStructure.getTitle()); 224 dumpParam("index", guiStructure.getIndex()); 225 dumpParam("parent", guiStructure.getParentPath()); 221 if (guiStructure instanceof HtmlServer) { 222 dumpParam("host", ((HtmlServer) guiStructure).getName()); 223 dumpParam("port", ((HtmlServer) guiStructure).getPort()); 224 } 225 else if (guiStructure instanceof HtmlDocument) { 226 dumpParam("path", ((HtmlDocument) guiStructure).getPath()); 227 dumpParam("query", ((HtmlDocument) guiStructure).getQuery()); 228 dumpParam("title", ((HtmlDocument) guiStructure).getTitle()); 229 } 230 else if (guiStructure instanceof HtmlPageElement) { 231 dumpParam("tagname", ((HtmlPageElement) guiStructure).getTagName()); 232 dumpParam("htmlid", ((HtmlPageElement) guiStructure).getHtmlId()); 233 dumpParam("index", ((HtmlPageElement) guiStructure).getIndex()); 234 } 235 236 dumpParam("parent", guiStructure.getParentId()); 226 237 227 238 outputWriter.println("</component>"); 228 239 229 240 if (guiStructure.getChildren() != null) { 230 for (Html PageElement child : guiStructure.getChildren()) {241 for (HtmlGUIElement child : guiStructure.getChildren()) { 231 242 dumpGuiStructure(child); 232 243 } … … 260 271 261 272 dumpParam("selectedValue", event.getSelectedValue()); 262 dumpParam("target", event.getPath()); 273 274 if (event.getTarget() != null) { 275 dumpParam("target", event.getTarget().getId()); 276 } 277 else { 278 dumpParam("targetDocument", event.getTargetDocument().getId()); 279 dumpParam("targetDOMPath", event.getTargetDOMPath()); 280 } 263 281 dumpParam("timestamp", event.getTime()); 264 282 -
trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorServlet.java
r1022 r1069 78 78 * the message listener to forward received messages to. 79 79 */ 80 private HtmlGUIElementManager guiElementManager = new HtmlGUIElementManager(); 81 82 /** 83 * the message listener to forward received messages to. 84 */ 80 85 private transient HtmlMonitorMessageListener messageListener; 81 86 … … 199 204 } 200 205 else { 201 Html PageElement guiStructure = extractHtmlPageElements(message, clientInfos);206 HtmlGUIElement guiStructure = extractHtmlPageElements(message, clientInfos); 202 207 HtmlEvent[] events = extractHtmlEvents(message, clientInfos); 203 208 … … 275 280 events = new ArrayList<HtmlEvent>(); 276 281 277 Html PageElementserver = getServerElement(clientInfos);278 Html PageElement page= getPageElementRepresentingWebPage(clientInfos, server);282 HtmlServer server = getServerElement(clientInfos); 283 HtmlDocument document = getPageElementRepresentingWebPage(clientInfos, server); 279 284 280 285 for (int i = 0; i < eventArray.size(); i++) { … … 285 290 else { 286 291 Long time = assertValue(((JSONObject) eventObj), "time", Long.class); 287 String path = assertValue(((JSONObject) eventObj), "path", String.class);292 String domPath = assertValue(((JSONObject) eventObj), "path", String.class); 288 293 String eventType = 289 294 assertValue(((JSONObject) eventObj), "eventType", String.class); … … 302 307 Console.printerrln(eventType + " event has no valid timestamp"); 303 308 } 304 else if ( path == null) {305 Console.printerrln(eventType + " event has no valid path");309 else if (domPath == null) { 310 Console.printerrln(eventType + " event has no valid DOM path"); 306 311 } 307 312 else if ((coordinates != null) && (coordinates.length != 2)) { … … 311 316 (eventType, coordinates, key, scrollPosition, selectedValue)) 312 317 { 313 path = page.getPath() + path; 314 events.add(new HtmlEvent(clientInfos, time, path, eventType, 315 coordinates, key, scrollPosition, selectedValue)); 318 HtmlPageElement target = 319 guiElementManager.getPageElement(document, domPath); 320 321 if (target != null) { 322 events.add(new HtmlEvent(clientInfos, time, target, eventType, 323 coordinates, key, scrollPosition, 324 selectedValue)); 325 } 326 else { 327 events.add(new HtmlEvent(clientInfos, time, document, domPath, 328 eventType, coordinates, key, scrollPosition, 329 selectedValue)); 330 } 316 331 } 317 332 else { … … 342 357 * representation of the server of the HTML page that was observed 343 358 */ 344 private Html PageElementextractHtmlPageElements(JSONObject object,345 359 private HtmlServer extractHtmlPageElements(JSONObject object, 360 HtmlClientInfos clientInfos) 346 361 { 347 Html PageElementserver = getServerElement(clientInfos);348 Html PageElement page= getPageElementRepresentingWebPage(clientInfos, server);362 HtmlServer server = getServerElement(clientInfos); 363 HtmlDocument document = getPageElementRepresentingWebPage(clientInfos, server); 349 364 350 365 JSONObject jsonPageElement = assertValue(object, "guiModel", JSONObject.class); 351 page.addChild(convert(jsonPageElement, page.getPath()));366 document.addChild(convert(jsonPageElement, document, null)); 352 367 353 368 return server; … … 364 379 * @return as described 365 380 */ 366 private HtmlPageElement getServerElement(HtmlClientInfos clientInfos) { 367 String id = clientInfos.getUrl().getHost(); 381 private HtmlServer getServerElement(HtmlClientInfos clientInfos) { 382 String host = clientInfos.getUrl().getHost(); 383 int port = 80; 384 368 385 if (clientInfos.getUrl().getPort() > -1) { 369 id += ":" +clientInfos.getUrl().getPort();370 } 371 372 return new HtmlPageElement(null, "server", id, 0);386 port = clientInfos.getUrl().getPort(); 387 } 388 389 return guiElementManager.createHtmlServer(host, port); 373 390 } 374 391 … … 384 401 * @return as described 385 402 */ 386 private Html PageElement getPageElementRepresentingWebPage(HtmlClientInfos clientInfos,387 HtmlPageElementserver)403 private HtmlDocument getPageElementRepresentingWebPage(HtmlClientInfos clientInfos, 404 HtmlServer server) 388 405 { 389 String id = clientInfos.getUrl().getPath(); 406 String path = clientInfos.getUrl().getPath(); 407 String query = null; 390 408 391 409 if (clientInfos.getUrl().getQuery() != null) { 392 id += "?" + clientInfos.getUrl().getQuery();393 } 394 395 Html PageElement page =396 new HtmlPageElement(server.getPath(), "document", id, clientInfos.getTitle(), 0);397 398 server.addChild( page);399 400 return page;410 query = "?" + clientInfos.getUrl().getQuery(); 411 } 412 413 HtmlDocument document = guiElementManager.createHtmlDocument 414 (server, path, query, clientInfos.getTitle()); 415 416 server.addChild(document); 417 418 return document; 401 419 } 402 420 … … 408 426 * 409 427 * @param jsonPageElement the JSON object to be converted 410 * @param parentPath the path through the DOM of the parent HTML page element of the 411 * converted one 428 * @param document the document to which the page element belongs 429 * @param parent the parent page element of the converted element, of null, if none 430 * is present. In this case the document is considered the parent 431 * element. 412 432 * 413 433 * @return as described. 414 434 */ 415 private HtmlPageElement convert(JSONObject jsonPageElement, String parentPath) { 435 private HtmlPageElement convert(JSONObject jsonPageElement, 436 HtmlDocument document, 437 HtmlPageElement parent) 438 { 416 439 HtmlPageElement result = null; 417 440 418 441 if (jsonPageElement != null) { 419 442 String tagName = assertValue(jsonPageElement, "tagName", String.class); 420 String id = assertValue(jsonPageElement, "id", String.class);443 String htmlid = assertValue(jsonPageElement, "htmlId", String.class); 421 444 Integer index = assertValue(jsonPageElement, "index", Integer.class); 422 445 423 result = new HtmlPageElement(parentPath, tagName, id, index); 446 result = guiElementManager.createHtmlPageElement 447 (document, parent, tagName, htmlid, index); 424 448 425 449 JSONArray childElements = assertValue(jsonPageElement, "children", JSONArray.class); … … 435 459 } 436 460 else { 437 result.addChild(convert((JSONObject) jsonChild, result.getPath()));461 result.addChild(convert((JSONObject) jsonChild, document, result)); 438 462 } 439 463 } -
trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlPageElement.java
r1022 r1069 15 15 package de.ugoe.cs.autoquest.htmlmonitor; 16 16 17 import java.util.ArrayList;18 import java.util.List;19 20 17 /** 21 18 * <p> 22 * represents an element of an HTML GUI. This can be a server, which is usually the root of a 23 * GUI structure, a web page, or a tag within a web page. 19 * represents an element of an HTML GUI, i.e. a tag within a web page. 24 20 * </p> 25 21 * 26 22 * @author Patrick Harms 27 23 */ 28 class HtmlPageElement { 29 30 /** 31 * path to the parent of this page element or null, if this is the root element 32 */ 33 private String parentPath; 34 35 /** 36 * the name of the tag represented by this page element. May also be the name of the server 37 * or the page. 24 class HtmlPageElement extends HtmlGUIElement { 25 26 /** 27 * the document to which the represented tag belongs 28 */ 29 private HtmlDocument document; 30 31 /** 32 * the parent page element; if null, the document is considered the parent 33 */ 34 private HtmlPageElement parent; 35 36 /** 37 * the name of the tag represented by this page element. 38 38 */ 39 39 private String tagName; 40 40 41 41 /** 42 * the id of the page element. May also be the name of the server including port number or the 43 * URL of the page 44 */ 45 private String id; 46 47 /** 48 * the title of the page if a page is represented through this element 49 */ 50 private String title; 42 * the id of the page element inside the DOM. 43 */ 44 private String htmlId; 51 45 52 46 /** … … 57 51 58 52 /** 59 * the children of this element60 */61 private List<HtmlPageElement> children;62 63 /**64 53 * <p> 65 54 * instantiates a new element representing a tag in an HTML page 66 55 * </p> 67 56 * 68 * @param parentPath the path through the DOM to the parent node of the represented tag 69 * @param tagName the name of the represented tag 70 * @param id the id of the tag in the DOM 71 * @param index the index of the represented tag regarding all tags with the same tag name 72 * in the list of children of the parent tag 73 */ 74 HtmlPageElement(String parentPath, String tagName, String id, Integer index) { 75 this.parentPath = parentPath; 57 * @param id the id of the page element 58 * @param document the document to which the represented tag belongs 59 * @param parent the parent page element; if null, the document is considered the parent 60 * @param tagName the name of the represented tag 61 * @param htmlId the id of the tag in the DOM 62 * @param index the index of the represented tag regarding all tags with the same 63 * tag name in the list of children of the parent tag 64 */ 65 HtmlPageElement(String id, 66 HtmlDocument document, 67 HtmlPageElement parent, 68 String tagName, 69 String htmlId, 70 Integer index) 71 { 72 super(id, parent == null ? document : parent); 73 74 if (document == null) { 75 throw new IllegalArgumentException("document must not be null"); 76 } 77 78 if (tagName == null) { 79 throw new IllegalArgumentException("tagName must not be null"); 80 } 81 82 if ((htmlId == null) && (index == null)) { 83 throw new IllegalArgumentException("either one of htmlId and index must not be null"); 84 } 85 86 this.document = document; 87 this.parent = parent; 76 88 this.tagName = tagName; 77 this. id = id;89 this.htmlId = htmlId; 78 90 this.index = index; 79 91 } … … 81 93 /** 82 94 * <p> 83 * instantiates a new element representing an HTML page95 * returns the document to which the represented tag belongs 84 96 * </p> 85 97 * 86 * @param parentPath the path through the DOM to the parent node of the represented tag which is 87 * usually a server 88 * @param tagName the name of the represented tag which is the path of the web page 89 * @param title the title of the web page 90 * @param id the id of the web page which is its path 91 * @param index usually 0 92 */ 93 HtmlPageElement(String parentPath, String tagName, String id, String title, Integer index) { 94 this(parentPath, tagName, id, index); 95 this.title = title; 96 } 97 98 /** 99 * <p> 100 * returns the name of the tag represented by this page element. May also be the name of the 101 * server or the page. 98 * @return the document 99 */ 100 HtmlDocument getDocument() { 101 return document; 102 } 103 104 /** 105 * <p> 106 * returns the name of the tag represented by this page element. 102 107 * </p> 103 108 * … … 110 115 /** 111 116 * <p> 112 * returns the id of the page element. May also be the name of the server including port 113 * number or the URL of the page 117 * returns the id of the page element. 114 118 * </p> 115 119 * 116 120 * @return the id 117 121 */ 118 String getId() { 119 return id; 120 } 121 122 /** 123 * <p> 124 * returns the title of the page if a page is represented through this element 125 * </p> 126 * 127 * @return the title 128 */ 129 String getTitle() { 130 return title; 122 String getHtmlId() { 123 return htmlId; 131 124 } 132 125 … … 141 134 Integer getIndex() { 142 135 return index; 143 }144 145 /**146 * <p>147 * returns the children of this element if any, null else148 * </p>149 *150 * @return the children151 */152 List<HtmlPageElement> getChildren() {153 return children;154 }155 156 157 /**158 * adds a child to this element159 *160 * @param child the child to be added161 */162 void addChild(HtmlPageElement child) {163 if (child != null) {164 if (children == null) {165 children = new ArrayList<HtmlPageElement>();166 }167 168 children.add(child);169 }170 }171 172 /**173 * <p>174 * returns the path to the parent of this page element or null, if this is the root element175 * </p>176 *177 * @return as described178 */179 String getParentPath() {180 return parentPath;181 136 } 182 137 … … 190 145 * @return as described 191 146 */ 192 String get Path() {147 String getDOMPath() { 193 148 StringBuffer result = new StringBuffer(); 194 if (parent Path!= null) {195 result.append(parent Path);149 if (parent != null) { 150 result.append(parent.getDOMPath()); 196 151 } 197 152 … … 199 154 result.append(tagName); 200 155 201 if (( id != null) && (!"".equals(id))) {202 result.append("( id=");203 result.append( id);156 if ((htmlId != null) && (!"".equals(htmlId))) { 157 result.append("(htmlId="); 158 result.append(htmlId); 204 159 result.append(")"); 205 160 } … … 213 168 } 214 169 170 /* (non-Javadoc) 171 * @see de.ugoe.cs.autoquest.htmlmonitor.HtmlGUIElement#equals(de.ugoe.cs.autoquest.htmlmonitor.HtmlGUIElement) 172 */ 173 @Override 174 public boolean equals(HtmlGUIElement obj) { 175 if (this == obj) { 176 return true; 177 } 178 else if (obj instanceof HtmlPageElement) { 179 return equals((HtmlPageElement) obj); 180 } 181 else { 182 return false; 183 } 184 } 185 186 /* (non-Javadoc) 187 * @see de.ugoe.cs.autoquest.htmlmonitor.HtmlGUIElement#equals(de.ugoe.cs.autoquest.htmlmonitor.HtmlGUIElement) 188 */ 189 public boolean equals(HtmlPageElement other) { 190 if (this == other) { 191 return true; 192 } 193 194 return (document.equals(other.document) && tagName.equals(other.tagName) && 195 (parent != null ? parent.equals(other.parent) : other.parent == null) && 196 (htmlId != null ? htmlId.equals(other.htmlId) : other.htmlId == null) && 197 (index != null ? index.equals(other.index) : other.index == null)); 198 } 199 200 /* (non-Javadoc) 201 * @see java.lang.Object#hashCode() 202 */ 203 @Override 204 public int hashCode() { 205 return document.hashCode() + tagName.hashCode() + (parent != null ? parent.hashCode() : 0) + 206 (htmlId != null ? htmlId.hashCode() : 0) + (index != null ? index : 0); 207 } 208 215 209 } -
trunk/autoquest-htmlmonitor/src/main/js/autoquest-htmlmonitor.js
r1023 r1069 305 305 306 306 if ((node.id) && (node.id !== "")) { 307 jsonRepresentation += "\" id\":\"" + node.id + "\"";307 jsonRepresentation += "\"htmlId\":\"" + node.id + "\""; 308 308 } 309 309 else { -
trunk/autoquest-plugin-html-test/.classpath
r953 r1069 13 13 </attributes> 14 14 </classpathentry> 15 <classpathentry kind="src" path="src/test/resources"/>15 <classpathentry including="**/*.java" kind="src" path="src/test/resources"/> 16 16 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"> 17 17 <attributes> -
trunk/autoquest-plugin-html-test/pom.xml
r953 r1069 28 28 <executions> 29 29 <execution> 30 <id>get- jfc-plugin-config</id>30 <id>get-html-plugin-config</id> 31 31 <phase>process-classes</phase> 32 32 <goals> -
trunk/autoquest-plugin-html-test/src/test/java/de/ugoe/cs/autoquest/plugin/html/HTMLLogParserTest.java
r1066 r1069 19 19 import java.io.File; 20 20 import java.util.Collection; 21 import java.util.Iterator; 21 22 import java.util.List; 22 23 import java.util.logging.Level; … … 54 55 public void testParseFile() throws Exception { 55 56 HTMLLogParser parser = new HTMLLogParser(); 56 parser.parseFile(new File(ClassLoader.getSystemResource("htmlmonitor_testtrace.xml").getFile())); 57 parser.parseFile(new File(ClassLoader.getSystemResource("htmlmonitor_testtrace_1.xml").getFile())); 58 parser.parseFile(new File(ClassLoader.getSystemResource("htmlmonitor_testtrace_2.xml").getFile())); 57 59 Collection<List<Event>> events = parser.getSequences(); 58 60 59 61 assertNotNull(events); 60 assertTrue(events.size() > 0); 62 assertEquals(2, events.size()); 63 64 Iterator<List<Event>> iterator = events.iterator(); 65 assertNotNull(iterator); 66 assertEquals(1, iterator.next().size()); 67 assertEquals(3, iterator.next().size()); 68 assertFalse(iterator.hasNext()); 61 69 62 70 System.err.println("{"); -
trunk/autoquest-plugin-html/data/guimappings/guimapping-html.txt
r1012 r1069 30 30 div = de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPanel 31 31 dl = de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPanel 32 document = de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLDocument 32 33 dt = de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLText 33 34 … … 90 91 91 92 p = de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPanel 92 page = de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPage93 93 # param = 94 94 pre = de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLText -
trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/HTMLLogParser.java
r1064 r1069 15 15 package de.ugoe.cs.autoquest.plugin.html; 16 16 17 import java.io.File;18 import java.io.FileInputStream;19 import java.io.FileNotFoundException;20 import java.io.IOException;21 import java.io.InputStreamReader;22 import java.io.UnsupportedEncodingException;23 import java.util.Collection;24 import java.util.HashMap;25 import java.util.LinkedList;26 17 import java.util.List; 27 18 import java.util.Map; 28 29 import javax.xml.parsers.ParserConfigurationException; 30 import javax.xml.parsers.SAXParser; 31 import javax.xml.parsers.SAXParserFactory; 32 33 import org.xml.sax.Attributes; 34 import org.xml.sax.InputSource; 19 import java.util.regex.Matcher; 20 import java.util.regex.Pattern; 21 35 22 import org.xml.sax.SAXException; 36 import org.xml.sax.SAXParseException;37 import org.xml.sax.helpers.DefaultHandler;38 23 39 24 import de.ugoe.cs.autoquest.eventcore.Event; 40 25 import de.ugoe.cs.autoquest.eventcore.IEventType; 41 import de.ugoe.cs.autoquest.eventcore.guimodel.GUIElementTree;42 26 import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel; 43 27 import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; 44 28 import de.ugoe.cs.autoquest.plugin.html.eventcore.HTMLEventTypeFactory; 29 import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLDocumentSpec; 45 30 import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLGUIElement; 46 31 import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLGUIElementSpec; 47 32 import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPageElementSpec; 48 import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPageSpec;49 33 import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLServerSpec; 50 import de.ugoe.cs.util.console.Console;51 34 52 35 /** 53 36 * <p> 54 37 * This class provides the functionality to parse XML log files generated by the HTMLMonitor of 55 * autoquest. The result of parsing a file is a collection of event sequences.38 * AutoQUEST. The result of parsing a file is a collection of event sequences and a GUI model 56 39 * </p> 57 40 * 58 * @author Fabian Glaser 41 * @author Fabian Glaser, Patrick Harms 59 42 * @version 1.0 60 43 * 61 44 */ 62 public class HTMLLogParser extends DefaultHandler { 45 public class HTMLLogParser extends AbstractDefaultLogParser { 46 47 /** 48 * 49 */ 50 private Pattern htmlElementPattern = 51 Pattern.compile("(\\w+)(\\[(\\d+)\\]|\\(htmlId=([\\w-]+)\\))"); 52 53 /* (non-Javadoc) 54 * @see de.ugoe.cs.autoquest.plugin.html.AbstractDefaultLogParser#handleGUIElement(java.lang.String, java.util.Map) 55 */ 56 @Override 57 protected boolean handleGUIElement(String id, Map<String, String> parameters) 58 throws SAXException 59 { 60 HTMLGUIElementSpec specification = null; 61 62 String parentId = parameters.get("parent"); 63 IGUIElement parent = super.getGUIElementTree().find(parentId); 64 65 if (parameters.containsKey("host")) { 66 // this is a server specification 67 int port = 80; 68 String portStr = parameters.get(port); 69 70 if (portStr != null) { 71 port = Integer.parseInt(portStr); 72 } 73 74 specification = new HTMLServerSpec(parameters.get("host"), port); 75 } 76 else if (parameters.containsKey("path")) { 77 // this is a document specification 78 79 if (parent != null) { 80 if (!(parent.getSpecification() instanceof HTMLServerSpec)) { 81 throw new SAXException 82 ("invalid log: parent GUI element of a document is not of type server"); 83 } 84 85 specification = new HTMLDocumentSpec 86 ((HTMLServerSpec) parent.getSpecification(), parameters.get("path"), 87 parameters.get("query"), parameters.get("title")); 88 } 89 else if (parentId == null) { 90 throw new SAXException("invalid log: a document has no parent id"); 91 } 92 } 93 else if (parameters.containsKey("tagname")) { 94 String tagName = parameters.get("tagname"); 95 96 if (!tagNameMustBeConsidered(tagName)) { 97 return true; 98 } 99 100 if (parent != null) { 101 IGUIElement document = parent; 102 103 while ((document != null) && 104 (!(document.getSpecification() instanceof HTMLDocumentSpec))) 105 { 106 document = document.getParent(); 107 } 108 109 if (document == null) { 110 throw new SAXException 111 ("invalid log: parent hierarchy of a page element does not contain a " + 112 "document"); 113 } 114 115 int index = -1; 116 String indexStr = parameters.get("index"); 117 118 if ((indexStr != null) && (!"".equals(indexStr))) { 119 index = Integer.parseInt(indexStr); 120 } 121 122 specification = new HTMLPageElementSpec 123 ((HTMLDocumentSpec) document.getSpecification(), tagName, 124 parameters.get("htmlid"), index); 125 } 126 else if (parentId == null) { 127 throw new SAXException("invalid log: a page element has no parent id"); 128 } 129 } 130 else { 131 throw new SAXException("invalid log: unknown GUI element"); 132 } 133 134 if (specification != null) { 135 super.getGUIElementTree().add(id, parentId, specification); 136 return true; 137 } 138 else { 139 return false; 140 } 141 } 142 143 /* (non-Javadoc) 144 * @see de.ugoe.cs.autoquest.plugin.html.AbstractDefaultLogParser#handleEvent(java.lang.String, java.util.Map) 145 */ 146 @Override 147 protected boolean handleEvent(String type, Map<String, String> parameters) throws SAXException { 148 String targetId = parameters.get("target"); 149 150 if (targetId == null) { 151 String targetDocument = parameters.get("targetDocument"); 152 String targetDOMPath = parameters.get("targetDOMPath"); 153 154 if ((targetDocument == null) || (targetDOMPath == null)) { 155 throw new SAXException("event has no target defined"); 156 } 157 158 targetId = determineTargetId(targetDocument, targetDOMPath); 159 160 if (targetId == null) { 161 // the target id can not be determined yet 162 return false; 163 } 164 } 165 166 IGUIElement target = super.getGUIElementTree().find(targetId); 167 168 if (target == null) { 169 // event not processable yet 170 return false; 171 } 172 173 IEventType eventType = 174 HTMLEventTypeFactory.getInstance().getEventType(type, parameters, target); 175 176 Event event = new Event(eventType, target); 177 178 String timestampStr = parameters.get("timestamp"); 179 180 if (timestampStr != null) { 181 event.setTimestamp(Long.parseLong(timestampStr)); 182 } 183 184 ((HTMLGUIElement) event.getTarget()).markUsed(); 185 186 super.addToSequence(event); 187 188 return true; 189 } 190 63 191 /** 64 192 * <p> 65 * Constructor. Creates a new HTMLLogParser.193 * TODO: comment 66 194 * </p> 67 */ 68 public HTMLLogParser() { 69 sequences = new LinkedList<List<Event>>(); 195 * 196 * @param targetDocument 197 * @param targetDOMPath 198 * @return 199 */ 200 private String determineTargetId(String targetDocument, String targetDOMPath) 201 throws SAXException 202 { 203 IGUIElement document = super.getGUIElementTree().find(targetDocument); 204 205 if (document == null) { 206 return null; 207 } 208 209 if (!(document.getSpecification() instanceof HTMLDocumentSpec)) { 210 throw new SAXException("an id that should refer to an HTML document refers to" + 211 "something else"); 212 } 213 214 GUIModel model = super.getGUIElementTree().getGUIModel(); 215 IGUIElement child = document; 216 String[] pathElements = targetDOMPath.split("/"); 217 int pathIndex = 0; 218 219 HTMLPageElementSpec compareSpec; 220 String tagName; 221 int index; 222 String htmlId; 223 224 while ((pathIndex < pathElements.length) && (child != null)) { 225 if ((pathElements[pathIndex] != null) && (!"".equals(pathElements[pathIndex]))) { 226 Matcher matcher = htmlElementPattern.matcher(pathElements[pathIndex]); 227 if (!matcher.matches()) { 228 throw new SAXException 229 ("could not parse target DOM path element " + pathElements[pathIndex]); 230 } 231 232 tagName = matcher.group(1); 233 String indexStr = matcher.group(3); 234 htmlId = matcher.group(4); 235 236 index = -1; 237 if ((indexStr != null) && (!"".equals(indexStr))) { 238 index = Integer.parseInt(indexStr); 239 } 240 241 compareSpec = new HTMLPageElementSpec 242 ((HTMLDocumentSpec) document.getSpecification(), tagName, htmlId, index); 243 244 List<IGUIElement> children = model.getChildren(child); 245 child = null; 246 247 for (IGUIElement candidate : children) { 248 if (compareSpec.getSimilarity(candidate.getSpecification())) { 249 child = candidate; 250 break; 251 } 252 } 253 } 254 255 pathIndex++; 256 } 257 258 if (child != null) { 259 return super.getGUIElementTree().find(child); 260 } 261 else { 262 return null; 263 } 70 264 } 71 265 72 266 /** 73 267 * <p> 74 * Collection of event sequences that is contained in the parsed log file. 268 * checks if tags with the provided name must be handled in the GUI model. As an example, 269 * it is not necessary to handle "head" tags and anything included in them. 75 270 * </p> 76 */ 77 private Collection<List<Event>> sequences; 78 79 /** 80 * <p> 81 * Internal handle to the parsed GUI structure, stored in a GUIElementTree 82 * </p> 83 */ 84 private GUIElementTree<String> currentGUIElementTree; 85 86 /** 87 * <p> 88 * Path of the GUI element currently being parsed. 89 * </p> 90 */ 91 private String currentGUIElementPath; 92 93 /** 94 * <p> 95 * Path of the parent of the GUI element currently being parsed. 96 * </p> 97 */ 98 private String currentParentPath; 99 100 /** 101 * <p> 102 * Source of the GUI element currently being parsed. 103 * </p> 104 */ 105 private String currentEventSource; 106 107 /** 108 * <p> 109 * Timestamp of the event currently being parsed. 110 * </p> 111 */ 112 private Long currentEventTimestamp; 113 114 /** 115 * <p> 116 * Internal handle to the parameters of the event currently being parsed. 117 * </p> 118 */ 119 private Map<String, String> currentEventParameters; 120 121 /** 122 * <p> 123 * Internal handle to the parameters of the GUI element currently being parsed. 124 * </p> 125 */ 126 private Map<String, String> currentGUIElementParameters; 127 /** 128 * <p> 129 * Internal handle to the sequence currently being parsed. 130 * </p> 131 */ 132 private List<Event> currentSequence; 133 134 /** 135 * <p> 136 * Internal handle to type of the event currently being parsed. 137 * </p> 138 */ 139 private String currentEventType; 140 141 /** 142 * <p> 143 * Class of the GUI element currently being parsed. 144 * </p> 145 */ 146 private String currentGUIElementClass; 147 148 /** 149 * <p> 150 * Index of the GUI element currently being parsed. 151 * </p> 152 */ 153 private String currentGUIElementIndex; 154 155 /** 156 * <p> 157 * internal handle to the GUI element of the previous event to be potentially reused for the 158 * current 159 * </p> 160 */ 161 private IGUIElement lastGUIElement; 162 163 /** 164 * <p> 165 * internal handle to the server specification currently being used. 166 * </p> 167 */ 168 private HTMLServerSpec currentServerSpec; 169 170 /** 171 * <p> 172 * Parses a log file written by the HTMLMonitor and creates a collection of event sequences. 173 * </p> 174 * 175 * @param filename 176 * name and path of the log file 177 */ 178 public void parseFile(String filename) { 179 if (filename == null) { 180 throw new IllegalArgumentException("filename must not be null"); 181 } 182 183 parseFile(new File(filename)); 184 } 185 186 /** 187 * <p> 188 * Parses a log file written by the HTMLMonitor and creates a collection of event sequences. 189 * </p> 190 * 191 * @param file 192 * file to be parsed 193 */ 194 public void parseFile(File file) { 195 if (file == null) { 196 throw new IllegalArgumentException("file must not be null"); 197 } 198 SAXParserFactory spf = SAXParserFactory.newInstance(); 199 spf.setValidating(true); 200 SAXParser saxParser = null; 201 InputSource inputSource = null; 202 try { 203 saxParser = spf.newSAXParser(); 204 inputSource = 205 new InputSource(new InputStreamReader(new FileInputStream(file), "UTF-8")); 206 } 207 catch (UnsupportedEncodingException e) { 208 Console.printerr("Error parsing file " + file.getName()); 209 Console.logException(e); 210 return; 211 } 212 catch (ParserConfigurationException e) { 213 Console.printerr("Error parsing file " + file.getName()); 214 Console.logException(e); 215 return; 216 } 217 catch (SAXException e) { 218 Console.printerr("Error parsing file " + file.getName()); 219 Console.logException(e); 220 } 221 catch (FileNotFoundException e) { 222 Console.printerr("Error parsing file " + file.getName()); 223 Console.logException(e); 224 } 225 if (inputSource != null) { 226 inputSource.setSystemId("file://" + file.getAbsolutePath()); 227 try { 228 if (saxParser == null) { 229 throw new RuntimeException("SaxParser creation failed"); 230 } 231 saxParser.parse(inputSource, this); 232 } 233 catch (SAXParseException e) { 234 Console.printerrln("Failure parsing file in line " + e.getLineNumber() + 235 ", column " + e.getColumnNumber() + "."); 236 Console.logException(e); 237 } 238 catch (SAXException e) { 239 Console.printerr("Error parsing file " + file.getName()); 240 Console.logException(e); 241 return; 242 } 243 catch (IOException e) { 244 Console.printerr("Error parsing file " + file.getName()); 245 Console.logException(e); 246 return; 247 } 248 } 249 } 250 251 /* 252 * (non-Javadoc) 253 * 254 * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, 255 * java.lang.String, org.xml.sax.Attributes) 256 */ 257 @Override 258 public void startElement(String uri, String localName, String qName, Attributes atts) 259 throws SAXException 260 { 261 if (qName.equals("session")) { 262 currentSequence = new LinkedList<Event>(); 263 if (currentGUIElementTree == null) 264 currentGUIElementTree = new GUIElementTree<String>(); 265 } 266 else if (qName.equals("component")) { 267 currentGUIElementPath = atts.getValue("path"); 268 currentGUIElementParameters = new HashMap<String, String>(); 269 } 270 else if (qName.equals("event")) { 271 currentEventType = atts.getValue("type"); 272 currentEventParameters = new HashMap<String, String>(); 273 } 274 else if (qName.equals("param")) { 275 String paramName = atts.getValue("name"); 276 if (currentGUIElementPath != null) { 277 if ("parent".equals(paramName)) { 278 currentParentPath = atts.getValue("value"); 279 } 280 if ("class".equals(paramName)) { 281 currentGUIElementClass = atts.getValue("value"); 282 } 283 if ("index".equals(paramName)) { 284 currentGUIElementIndex = atts.getValue("value"); 285 } 286 currentGUIElementParameters.put(paramName, atts.getValue("value")); 287 } 288 else if (currentEventType != null) { 289 if ("target".equals(paramName)) { 290 currentEventSource = atts.getValue("value"); 291 } 292 if ("timestamp".equals(paramName)) { 293 currentEventTimestamp = Long.parseLong(atts.getValue("value")); 294 } 295 currentEventParameters.put(paramName, atts.getValue("value")); 296 } 297 else { 298 throw new SAXException("param tag found where it should not be."); 299 } 300 } 301 else { 302 throw new SAXException("unknown tag found: " + qName); 303 } 304 305 } 306 307 /* 308 * (non-Javadoc) 309 * 310 * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, 311 * java.lang.String) 312 */ 313 @Override 314 public void endElement(String uri, String localName, String qName) throws SAXException { 315 if (qName.equals("session")) { 316 if (currentSequence != null && !currentSequence.isEmpty()) { 317 sequences.add(currentSequence); 318 } 319 currentSequence = null; 320 } 321 else if (qName.equals("component") && currentGUIElementPath != null) { 322 HTMLGUIElementSpec guiElementSpec = 323 getGUIElementSpec(currentGUIElementClass, currentGUIElementParameters); 324 currentGUIElementTree.add(currentGUIElementPath, currentParentPath, guiElementSpec); 325 326 currentParentPath = null; 327 currentGUIElementPath = null; 328 currentGUIElementParameters = null; 329 } 330 else if (qName.equals("event")) { 331 IGUIElement currentGUIElement; 332 currentGUIElement = currentGUIElementTree.find(currentEventSource); 333 334 IEventType eventType = 335 HTMLEventTypeFactory.getInstance().getEventType(currentEventType, 336 currentEventParameters, 337 currentGUIElement); 338 Event event = 339 new Event(eventType, (currentGUIElement == null ? lastGUIElement 340 : currentGUIElement)); 341 342 event.setTimestamp(currentEventTimestamp); 343 HTMLGUIElement currentEventTarget = (HTMLGUIElement) event.getTarget(); 344 currentEventTarget.markUsed(); 345 currentSequence.add(event); 346 347 currentEventSource = null; 348 currentEventTimestamp = -1l; 349 currentEventParameters = null; 350 currentEventType = null; 351 352 if (currentGUIElement != null) { 353 lastGUIElement = currentGUIElement; 354 } 355 356 currentGUIElement = null; 357 } 358 } 359 360 /** 361 * <p> 362 * Returns a collection of event sequences that was obtained from parsing log files. 363 * </p> 364 * 271 * 272 * @param tagName 365 273 * @return 366 274 */ 367 public Collection<List<Event>> getSequences() { 368 return sequences; 369 } 370 371 /** 372 * <p> 373 * Returns the GUI model that is obtained from parsing log files. 374 * </p> 375 * 376 * @return GUIModel 377 */ 378 public GUIModel getGuiModel() { 379 return currentGUIElementTree.getGUIModel(); 380 } 381 382 /** 383 * Returns the HTMLGUIElementSpecification for a GUI Element described 384 * by its class name and its parameters. 385 * @param guiElementClass 386 * @param guiElementParameters 387 * @return 388 */ 389 private HTMLGUIElementSpec getGUIElementSpec(String guiElementClass, 390 Map<String, String> guiElementParameters) 391 { 392 HTMLGUIElementSpec specification = null; 393 if ("server".equals(guiElementClass)) { 394 // TODO: add correct port handling 395 specification = new HTMLServerSpec(guiElementParameters.get("htmlId"), 0); 396 currentServerSpec = (HTMLServerSpec) specification; 397 } 398 399 else { 400 String id = guiElementParameters.get("htmlId"); 401 if (id == null) { 402 HTMLPageElementSpec parentSpec = 403 (HTMLPageElementSpec) currentGUIElementTree.find(currentParentPath) 404 .getSpecification(); 405 id = parentSpec.getPage().getPagePath(); 406 } 407 408 int index = -1; 409 String indexStr = guiElementParameters.get("index"); 410 411 if ((indexStr != null) && (!"".equals(indexStr))) { 412 index = Integer.parseInt(indexStr); 413 } 414 String title = guiElementParameters.get("title"); 415 HTMLPageSpec page = new HTMLPageSpec(currentServerSpec, id, title); 416 specification = new HTMLPageElementSpec(page, guiElementClass, id, index); 417 } 418 419 return specification; 420 } 275 private boolean tagNameMustBeConsidered(String tagName) { 276 return 277 !"head".equals(tagName) && !"title".equals(tagName) && !"script".equals(tagName) && 278 !"style".equals(tagName) && !"link".equals(tagName) && !"meta".equals(tagName) && 279 !"iframe".equals(tagName) && !"input_hidden".equals(tagName) && 280 !"option".equals(tagName) && !"tt".equals(tagName) && !"br".equals(tagName) && 281 !"colgroup".equals(tagName) && !"col".equals(tagName); 282 283 } 284 421 285 } -
trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/eventcore/HTMLEventTypeFactory.java
r1059 r1069 23 23 import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction; 24 24 import de.ugoe.cs.autoquest.eventcore.gui.MouseClick; 25 import de.ugoe.cs.autoquest.eventcore.gui.MouseDoubleClick; 25 26 import de.ugoe.cs.autoquest.eventcore.gui.Scroll; 26 27 import de.ugoe.cs.autoquest.eventcore.gui.TextInput; … … 76 77 77 78 if ("onscroll".equals(eventName)) { 78 int[] coordinates = getCoordinateParameter(eventName, eventParameters); 79 int[] coordinates = 80 getCoordinateParameter("scrollX", "scrollY", eventName, eventParameters); 81 79 82 result = new Scroll(coordinates[0], coordinates[1]); 80 83 } 81 84 else if ("onclick".equals(eventName)) { 82 int[] coordinates = getCoordinateParameter( eventName, eventParameters);85 int[] coordinates = getCoordinateParameter("X", "Y", eventName, eventParameters); 83 86 result = 84 87 new MouseClick(MouseButtonInteraction.Button.LEFT, coordinates[0], coordinates[1]); 88 } 89 else if ("ondblclick".equals(eventName)) { 90 int[] coordinates = getCoordinateParameter("X", "Y", eventName, eventParameters); 91 result = new MouseDoubleClick 92 (MouseButtonInteraction.Button.LEFT, coordinates[0], coordinates[1]); 85 93 } 86 94 else if ("onchange".equals(eventName)) { … … 118 126 * @return 119 127 */ 120 private int[] getCoordinateParameter(String eventName, Map<String, String> eventParameters) { 121 String xCoord = eventParameters.get("X"); 128 private int[] getCoordinateParameter(String xParamName, 129 String yParamName, 130 String eventName, 131 Map<String, String> eventParameters) 132 { 133 String xCoord = eventParameters.get(xParamName); 122 134 if (xCoord == null) { 123 throw new IllegalArgumentException("eventParameters do not contain X coordinate."); 135 throw new IllegalArgumentException 136 ("eventParameters do not contain " + xParamName + " coordinate."); 124 137 } 125 138 126 String yCoord = eventParameters.get( "Y");139 String yCoord = eventParameters.get(yParamName); 127 140 if (yCoord == null) { 128 throw new IllegalArgumentException("eventParameters do not contain Y coordinate."); 141 throw new IllegalArgumentException 142 ("eventParameters do not contain " + yParamName + " coordinate."); 129 143 } 130 144 … … 134 148 } 135 149 catch (NumberFormatException e) { 136 throw new IllegalArgumentException("the coordinates provided " + " ofan " + eventName +150 throw new IllegalArgumentException("the coordinates provided by an " + eventName + 137 151 " event are no numbers"); 138 152 } -
trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLDocument.java
r1047 r1069 24 24 * @author Patrick Harms 25 25 */ 26 public class HTML Pageextends HTMLGUIElement implements IDialog {26 public class HTMLDocument extends HTMLGUIElement implements IDialog { 27 27 28 28 /** */ … … 37 37 * @param parent 38 38 */ 39 public HTML Page(HTMLPageSpec specification, HTMLServer parent) {39 public HTMLDocument(HTMLDocumentSpec specification, HTMLServer parent) { 40 40 super(specification, parent); 41 41 } … … 48 48 @Override 49 49 public String toString() { 50 return " Page(" + getPagePath() + ", \"" + getPageTitle() + "\")";50 return "Document(" + getPath() + ", \"" + getTitle() + "\")"; 51 51 } 52 52 … … 58 58 @Override 59 59 protected String getElementDescriptor() { 60 return " Page";60 return "Document"; 61 61 } 62 62 … … 69 69 */ 70 70 HTMLServerSpec getServer() { 71 return ((HTML PageSpec) super.getSpecification()).getServer();71 return ((HTMLDocumentSpec) super.getSpecification()).getServer(); 72 72 } 73 73 … … 79 79 * @return 80 80 */ 81 String getPa gePath() {82 return ((HTML PageSpec) super.getSpecification()).getPagePath();81 String getPath() { 82 return ((HTMLDocumentSpec) super.getSpecification()).getPath(); 83 83 } 84 84 … … 90 90 * @return 91 91 */ 92 String get PageTitle() {93 return ((HTML PageSpec) super.getSpecification()).getPageTitle();92 String getTitle() { 93 return ((HTMLDocumentSpec) super.getSpecification()).getTitle(); 94 94 } 95 95 -
trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLDocumentSpec.java
r1047 r1069 15 15 package de.ugoe.cs.autoquest.plugin.html.guimodel; 16 16 17 import java.net.URL;18 19 17 import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec; 20 18 … … 26 24 * @author Patrick Harms 27 25 */ 28 public class HTML PageSpec extends HTMLGUIElementSpec implements IGUIElementSpec {26 public class HTMLDocumentSpec extends HTMLGUIElementSpec implements IGUIElementSpec { 29 27 30 28 /** */ … … 35 33 36 34 /** */ 37 private String pa gePath;35 private String path; 38 36 39 37 /** */ 40 private String pageTitle; 38 private String query; 39 40 /** */ 41 private String title; 41 42 42 43 /** … … 49 50 * @param pageTitle 50 51 */ 51 public HTML PageSpec(HTMLServerSpec server, String pagePath, String pageTitle) {52 super(" page");52 public HTMLDocumentSpec(HTMLServerSpec server, String path, String query, String title) { 53 super("document"); 53 54 54 55 if (server == null) { 55 56 throw new IllegalArgumentException("server must not be null"); 56 57 } 57 else if (pa gePath == null) {58 else if (path == null) { 58 59 throw new IllegalArgumentException("pagePath must not be null"); 59 }60 else if (pageTitle == null) {61 throw new IllegalArgumentException("pageTitle must not be null");62 60 } 63 61 64 62 this.server = server; 65 this.pagePath = pagePath; 66 this.pageTitle = pageTitle; 67 } 68 69 /** 70 * <p> 71 * TODO: comment 72 * </p> 73 * 74 * @param server 75 * @param pagePath 76 * @param pageTitle 77 */ 78 public HTMLPageSpec(URL pageURL, String pageTitle) { 79 super("page"); 80 81 if (pageURL == null) { 82 throw new IllegalArgumentException("pageURL must not be null"); 83 } 84 else if (pageTitle == null) { 85 throw new IllegalArgumentException("pageTitle must not be null"); 86 } 87 88 this.server = new HTMLServerSpec(pageURL); 89 this.pagePath = pageURL.getPath(); 90 this.pageTitle = pageTitle; 63 this.path = path; 64 this.query = query; 65 this.title = title; 91 66 } 92 67 … … 96 71 @Override 97 72 public boolean getSimilarity(IGUIElementSpec other) { 98 if (other instanceof HTML PageSpec) {99 HTML PageSpec otherSpec = (HTMLPageSpec) other;73 if (other instanceof HTMLDocumentSpec) { 74 HTMLDocumentSpec otherSpec = (HTMLDocumentSpec) other; 100 75 101 76 if (!super.getSimilarity(otherSpec)) { … … 105 80 return false; 106 81 } 107 else if (!pagePath.equals(otherSpec.pagePath)) { 82 else if (!path.equals(otherSpec.path)) { 83 return false; 84 } 85 else if (query != null ? !query.equals(otherSpec.query) : otherSpec.query != null) { 108 86 return false; 109 87 } 110 88 else { 111 return pageTitle.equals(otherSpec.pageTitle);89 return (title != null ? title.equals(otherSpec.title) : otherSpec.title == null); 112 90 } 113 91 } … … 134 112 * @return 135 113 */ 136 String getPa gePath() {137 return pa gePath;114 String getPath() { 115 return path; 138 116 } 139 117 … … 145 123 * @return 146 124 */ 147 String getPageTitle() { 148 return pageTitle; 125 String getQuery() { 126 return query; 127 } 128 129 /** 130 * <p> 131 * TODO: comment 132 * </p> 133 * 134 * @return 135 */ 136 String getTitle() { 137 return title; 149 138 } 150 139 -
trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLPageElement.java
r989 r1069 47 47 * @param parent 48 48 */ 49 public HTMLPageElement(HTMLPageElementSpec specification, HTML Pageparent) {49 public HTMLPageElement(HTMLPageElementSpec specification, HTMLDocument parent) { 50 50 super(specification, parent); 51 51 } … … 58 58 @Override 59 59 public String toString() { 60 String str = getTag ();60 String str = getTagName(); 61 61 62 if ((get TagId() != null) && (!"".equals(getTagId()))) {63 str += "(id=\"" + get TagId() + "\")";62 if ((getHtmlId() != null) && (!"".equals(getHtmlId()))) { 63 str += "(id=\"" + getHtmlId() + "\")"; 64 64 } 65 65 else { 66 str += "[" + get TagIndex() + "]";66 str += "[" + getIndex() + "]"; 67 67 } 68 68 … … 77 77 @Override 78 78 protected String getElementDescriptor() { 79 return getTag ();79 return getTagName(); 80 80 } 81 81 … … 87 87 * @return 88 88 */ 89 HTML PageSpec getPage() {89 HTMLDocumentSpec getPage() { 90 90 return ((HTMLPageElementSpec) super.getSpecification()).getPage(); 91 91 } … … 98 98 * @return 99 99 */ 100 String getTag () {101 return ((HTMLPageElementSpec) super.getSpecification()).getTag ();100 String getTagName() { 101 return ((HTMLPageElementSpec) super.getSpecification()).getTagName(); 102 102 } 103 103 … … 109 109 * @return 110 110 */ 111 String get TagId() {112 return ((HTMLPageElementSpec) super.getSpecification()).get TagId();111 String getHtmlId() { 112 return ((HTMLPageElementSpec) super.getSpecification()).getHtmlId(); 113 113 } 114 114 … … 120 120 * @return 121 121 */ 122 int get TagIndex() {123 return ((HTMLPageElementSpec) super.getSpecification()).get TagIndex();122 int getIndex() { 123 return ((HTMLPageElementSpec) super.getSpecification()).getIndex(); 124 124 } 125 125 -
trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLPageElementSpec.java
r1059 r1069 30 30 31 31 /** */ 32 private HTML PageSpec page;32 private HTMLDocumentSpec page; 33 33 34 34 /** */ 35 private String tag ;35 private String tagName; 36 36 37 37 /** */ 38 private String id;38 private String htmlId; 39 39 40 40 /** */ … … 50 50 * @param id 51 51 */ 52 public HTMLPageElementSpec(HTML PageSpec page, String tag, String id, int index) {53 super(tag );52 public HTMLPageElementSpec(HTMLDocumentSpec page, String tagName, String htmlId, int index) { 53 super(tagName); 54 54 55 55 if (page == null) { 56 56 throw new IllegalArgumentException("page must not be null"); 57 57 } 58 else if (tag == null) {58 else if (tagName == null) { 59 59 throw new IllegalArgumentException("tag must not be null"); 60 60 } 61 else if (( id == null) && (index < 0)) {61 else if ((htmlId == null) && (index < 0)) { 62 62 throw new IllegalArgumentException 63 63 ("either id must not be null or the index must be greater or equal to 0"); … … 65 65 66 66 this.page = page; 67 this.tag = tag;68 this. id = id;67 this.tagName = tagName; 68 this.htmlId = htmlId; 69 69 this.index = index; 70 70 } … … 84 84 return false; 85 85 } 86 else if (!tag .equals(otherSpec.tag)) {86 else if (!tagName.equals(otherSpec.tagName)) { 87 87 return false; 88 88 } 89 89 90 if ( id != null) {91 return id.equals(otherSpec.id);90 if (htmlId != null) { 91 return htmlId.equals(otherSpec.htmlId); 92 92 } 93 93 else if (index >= 0) { … … 106 106 * @return 107 107 */ 108 public HTMLPageSpec getPage() {108 HTMLDocumentSpec getPage() { 109 109 return page; 110 110 } … … 117 117 * @return 118 118 */ 119 String getTag () {120 return tag ;119 String getTagName() { 120 return tagName; 121 121 } 122 122 … … 128 128 * @return 129 129 */ 130 String get TagId() {131 return id;130 String getHtmlId() { 131 return htmlId; 132 132 } 133 133 … … 139 139 * @return 140 140 */ 141 int get TagIndex() {141 int getIndex() { 142 142 return index; 143 143 } -
trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLServerSpec.java
r1059 r1069 14 14 15 15 package de.ugoe.cs.autoquest.plugin.html.guimodel; 16 17 import java.net.URL;18 16 19 17 import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec; … … 58 56 this.host = host; 59 57 this.port = port; 60 }61 62 /**63 * <p>64 * TODO: comment65 * </p>66 *67 * @param pageURL68 */69 public HTMLServerSpec(URL pageURL) {70 super("server");71 72 if (pageURL == null) {73 throw new IllegalArgumentException("page URL must not be null");74 }75 76 this.host = pageURL.getHost();77 this.port = pageURL.getPort();78 58 } 79 59
Note: See TracChangeset
for help on using the changeset viewer.