Changeset 1069 for trunk/autoquest-htmlmonitor-test/src
- Timestamp:
- 02/14/13 15:20:07 (12 years ago)
- Location:
- trunk/autoquest-htmlmonitor-test/src/test
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
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>
Note: See TracChangeset
for help on using the changeset viewer.