Ignore:
Timestamp:
02/14/13 15:20:07 (11 years ago)
Author:
pharms
Message:
  • support of new HTML logging format
Location:
trunk/autoquest-htmlmonitor-test
Files:
5 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-htmlmonitor-test/pom.xml

    r1011 r1069  
    2222    <dependencies> 
    2323        <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> 
    2430            <groupId>org.apache.httpcomponents</groupId> 
    2531            <artifactId>httpclient</artifactId> 
     
    2834        </dependency> 
    2935    </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> 
    3096</project> 
  • trunk/autoquest-htmlmonitor-test/src/test/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorServerTest.java

    r943 r1069  
    5656     *  
    5757     */ 
     58    private HtmlGUIElement guiStructure; 
     59 
     60    /** 
     61     *  
     62     */ 
    5863    private String eventHandlingError; 
    5964 
     
    97102    @Test 
    98103    public void testSimpleMessage() throws Exception { 
     104        String clientId = "123"; 
     105         
    99106        String message = 
    100107            "{" + 
    101108            "  \"message\": {" + 
    102109            "    \"clientInfos\": {" + 
    103             "      \"clientId\":\"123\"," + 
     110            "      \"clientId\":\"" + clientId + "\"," + 
    104111            "      \"userAgent\":\"Agent\"," + 
    105112            "      \"title\":\"Title\"," + 
    106113            "      \"url\":\"http://host/path\"" + 
    107114            "    }," + 
     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            "    }," + 
    108129            "    \"events\":" + 
    109130            "    [ {" + 
    110131            "        \"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\"]" + 
    113135            "      }" + 
    114136            "    ]" + 
     
    122144        } 
    123145         
     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 
    124169        assertNotNull(events); 
    125170        assertEquals(1, events.length); 
    126171         
    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         
    139176    } 
    140177 
     
    144181    @Test 
    145182    public void testComplexMessage() throws Exception { 
     183        String clientId = "123"; 
     184         
    146185        String message = 
    147186            "{" + 
    148187            "  \"message\": {" + 
    149188            "    \"clientInfos\": {" + 
    150             "      \"clientId\":\"123\"," + 
     189            "      \"clientId\":\"" + clientId + "\"," + 
    151190            "      \"userAgent\":\"Agent\"," + 
    152191            "      \"title\":\"Title\"," + 
    153192            "      \"url\":\"http://host/path\"" + 
    154193            "    }," + 
     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            "    }," + 
    155250            "    \"events\":" + 
    156             "    [" + 
    157             "      {" + 
     251            "    [ {" + 
    158252            "        \"time\":\"1\"," + 
    159             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input1)\"," + 
     253            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input1)\"," + 
    160254            "        \"eventType\":\"onclick\"," + 
    161255            "        \"coordinates\": [\"194\", \"7\"]" + 
     
    163257            "      {" + 
    164258            "        \"time\":\"2\"," + 
    165             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input2)\"," + 
     259            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input2)\"," + 
    166260            "        \"eventType\":\"ondblclick\"," + 
    167261            "        \"coordinates\": [\"194\", \"7\"]" + 
     
    169263            "      {" + 
    170264            "        \"time\":\"3\"," + 
    171             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input3)\"," + 
     265            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input3)\"," + 
    172266            "        \"eventType\":\"onfocus\"" + 
    173267            "      }," + 
    174268            "      {" + 
    175269            "        \"time\":\"4\"," + 
    176             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input4)\"," + 
     270            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input4)\"," + 
    177271            "        \"eventType\":\"onclick\"," + 
    178272            "        \"coordinates\": [\"125\", \"14\"]" + 
     
    180274            "      {" + 
    181275            "        \"time\":\"5\"," + 
    182             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input5)\"," + 
     276            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input5)\"," + 
    183277            "        \"eventType\":\"onfocus\"" + 
    184278            "      }," + 
    185279            "      {" + 
    186280            "        \"time\":\"6\"," + 
    187             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input6)\"," + 
     281            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input6)\"," + 
    188282            "        \"eventType\":\"onfocus\"" + 
    189283            "      }," + 
    190284            "      {" + 
    191285            "        \"time\":\"7\"," + 
    192             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input7)\"," + 
     286            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input7)\"," + 
    193287            "        \"eventType\":\"onfocus\"" + 
    194288            "      }," + 
    195289            "      {" + 
    196290            "        \"time\":\"8\"," + 
    197             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input8)\"," + 
     291            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input8)\"," + 
    198292            "        \"eventType\":\"onclick\"," + 
    199293            "        \"coordinates\": [\"255\", \"4\"]" + 
     
    201295            "      {" + 
    202296            "        \"time\":\"9\"," + 
    203             "        \"path\":\"/html[0]/body(id=gsr)\"," + 
     297            "        \"path\":\"/html[0]/body(htmlId=gsr)\"," + 
    204298            "        \"eventType\":\"onscroll\"," + 
    205299            "        \"scrollPosition\": [\"23\", \"567\"]" + 
     
    207301            "      {" + 
    208302            "        \"time\":\"10\"," + 
    209             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input10)\"," + 
     303            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input10)\"," + 
    210304            "        \"eventType\":\"onclick\"," + 
    211305            "        \"coordinates\": [\"516\", \"154\"]" + 
     
    214308            "  }" + 
    215309            "}"; 
    216          
     310  
    217311        sendMessageAndAssertResponse(message); 
    218312         
     
    221315        } 
    222316         
     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 
    223345        assertNotNull(events); 
    224346        assertEquals(10, events.length); 
    225347 
    226348        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; 
    228352             
    229353            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 }; 
    231357            } 
    232358            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; 
    237365            if ((i == 1)) { 
    238                 assertEquals("event " + i, "ondblclick", events[i].getEventType()); 
     366                eventType = "ondblclick"; 
    239367            } 
    240368            else if ((i == 2) || ((4 <= i) && (i <= 6))) { 
    241                 assertEquals("event " + i, "onfocus", events[i].getEventType()); 
     369                eventType = "onfocus"; 
    242370            } 
    243371            else if ((i == 8)) { 
    244                 assertEquals("event " + i, "onscroll", events[i].getEventType()); 
     372                eventType = "onscroll"; 
    245373            } 
    246374            else { 
    247                 assertEquals("event " + i, "onclick", events[i].getEventType()); 
     375                eventType = "onclick"; 
    248376            } 
    249377             
    250378            assertNull("event " + i, events[i].getKey()); 
    251379             
    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             
    274398        } 
    275399    } 
     
    310434            "      \"url\":\"http://host/path\"" + 
    311435            "    }," + 
     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            "    }," + 
    312450            "    \"events\":" + 
    313451            "    [ {" + 
    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\"," + 
    317455            "      }" + 
    318456            "    ]" + 
     
    337475            "      \"url\":\"http://host/path\"" + 
    338476            "    }," + 
     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            "    }," + 
    339491            "    \"events\":" + 
    340492            "    [ {" + 
    341493            "        \"time\":\"12345\"," + 
    342             "        \"path\":\"/html[0]/body(id=gsr)\"," + 
     494            "        \"path\":\"/html[0]/body(htmlId=gsr)\"," + 
    343495            "        \"eventType\":\"onunload\"" + 
    344496            "      }" + 
     
    365517            "      \"url\":\"http://host/path\"" + 
    366518            "    }," + 
     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            "    }," + 
    367533            "    \"events\":" + 
    368534            "    [ {" + 
    369535            "        \"time\":\"blub\"," + 
    370             "        \"path\":\"/html[0]/body(id=gsr)\"," + 
     536            "        \"path\":\"/html[0]/body(htmlId=gsr)\"," + 
    371537            "        \"eventType\":\"onunload\"" + 
    372538            "      }" + 
     
    389555     */ 
    390556    @Override 
    391     public void handleMessage(HtmlClientInfos clientInfos, HtmlEvent[] events) { 
     557    public void handleMessage(HtmlClientInfos clientInfos, 
     558                              HtmlGUIElement  guiStructure, 
     559                              HtmlEvent[]     events) 
     560    { 
    392561        if (clientInfos == null) { 
    393562            eventHandlingError = "client infos were null"; 
     563        } 
     564        else if (guiStructure == null) { 
     565            eventHandlingError = "gui structure was null"; 
    394566        } 
    395567        else if (events == null) { 
     
    404576             
    405577            this.events = events; 
     578            this.guiStructure = guiStructure; 
    406579        } 
    407580    } 
     
    435608    } 
    436609 
     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 
    437675} 
  • trunk/autoquest-htmlmonitor-test/src/test/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorTest.java

    r943 r1069  
    1717import static org.junit.Assert.*; 
    1818 
    19 import java.io.BufferedReader; 
    2019import java.io.File; 
    21 import java.io.FileInputStream; 
    22 import java.io.InputStreamReader; 
    23 import java.util.ArrayList; 
     20import java.util.Collection; 
     21import java.util.Iterator; 
    2422import java.util.List; 
    2523 
     
    3432import org.junit.Test; 
    3533 
     34import de.ugoe.cs.autoquest.eventcore.Event; 
     35import de.ugoe.cs.autoquest.eventcore.IEventType; 
     36import de.ugoe.cs.autoquest.eventcore.gui.KeyboardFocusChange; 
     37import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction; 
     38import de.ugoe.cs.autoquest.eventcore.gui.MouseClick; 
     39import de.ugoe.cs.autoquest.eventcore.gui.MouseDoubleClick; 
     40import de.ugoe.cs.autoquest.eventcore.gui.Scroll; 
     41import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel; 
     42import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; 
     43import de.ugoe.cs.autoquest.plugin.html.HTMLLogParser; 
     44import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLDocument; 
     45import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPageElement; 
     46import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLServer; 
    3647import de.ugoe.cs.util.console.TextConsole; 
    3748 
     
    108119            "      \"url\":\"http://host/path\"" + 
    109120            "    }," + 
     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            "    }," + 
    110135            "    \"events\":" + 
    111136            "    [ {" + 
    112137            "        \"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\"]" + 
    115141            "      }" + 
    116142            "    ]" + 
     
    120146        sendMessageAndAssertResponse(message); 
    121147         
     148        htmlMonitor.stop(); 
     149        htmlMonitor = null; 
     150 
    122151        File logFile = new File(LOG_FILE_DIR + File.separator + clientId + File.separator + 
    123                                 "htmlmonitor_" + clientId + ".log"); 
     152                                "htmlmonitor_" + clientId + "_000.log"); 
    124153         
    125154        assertTrue(logFile.exists()); 
    126155         
    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); 
    132227    } 
    133228 
     
    148243            "      \"url\":\"http://host/path\"" + 
    149244            "    }," + 
     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            "    }," + 
    150301            "    \"events\":" + 
    151             "    [" + 
    152             "      {" + 
     302            "    [ {" + 
    153303            "        \"time\":\"1\"," + 
    154             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input1)\"," + 
     304            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input1)\"," + 
    155305            "        \"eventType\":\"onclick\"," + 
    156306            "        \"coordinates\": [\"194\", \"7\"]" + 
     
    158308            "      {" + 
    159309            "        \"time\":\"2\"," + 
    160             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input2)\"," + 
     310            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input2)\"," + 
    161311            "        \"eventType\":\"ondblclick\"," + 
    162312            "        \"coordinates\": [\"194\", \"7\"]" + 
     
    164314            "      {" + 
    165315            "        \"time\":\"3\"," + 
    166             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input3)\"," + 
     316            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input3)\"," + 
    167317            "        \"eventType\":\"onfocus\"" + 
    168318            "      }," + 
    169319            "      {" + 
    170320            "        \"time\":\"4\"," + 
    171             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input4)\"," + 
     321            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input4)\"," + 
    172322            "        \"eventType\":\"onclick\"," + 
    173323            "        \"coordinates\": [\"125\", \"14\"]" + 
     
    175325            "      {" + 
    176326            "        \"time\":\"5\"," + 
    177             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input5)\"," + 
     327            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input5)\"," + 
    178328            "        \"eventType\":\"onfocus\"" + 
    179329            "      }," + 
    180330            "      {" + 
    181331            "        \"time\":\"6\"," + 
    182             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input6)\"," + 
     332            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input6)\"," + 
    183333            "        \"eventType\":\"onfocus\"" + 
    184334            "      }," + 
    185335            "      {" + 
    186336            "        \"time\":\"7\"," + 
    187             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input7)\"," + 
     337            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input7)\"," + 
    188338            "        \"eventType\":\"onfocus\"" + 
    189339            "      }," + 
    190340            "      {" + 
    191341            "        \"time\":\"8\"," + 
    192             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input8)\"," + 
     342            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input8)\"," + 
    193343            "        \"eventType\":\"onclick\"," + 
    194344            "        \"coordinates\": [\"255\", \"4\"]" + 
     
    196346            "      {" + 
    197347            "        \"time\":\"9\"," + 
    198             "        \"path\":\"/html[0]/body(id=gsr)\"," + 
     348            "        \"path\":\"/html[0]/body(htmlId=gsr)\"," + 
    199349            "        \"eventType\":\"onscroll\"," + 
    200350            "        \"scrollPosition\": [\"23\", \"567\"]" + 
     
    202352            "      {" + 
    203353            "        \"time\":\"10\"," + 
    204             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input10)\"," + 
     354            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input10)\"," + 
    205355            "        \"eventType\":\"onclick\"," + 
    206356            "        \"coordinates\": [\"516\", \"154\"]" + 
     
    212362        sendMessageAndAssertResponse(message); 
    213363         
     364        htmlMonitor.stop(); 
     365        htmlMonitor = null; 
     366 
    214367        File logFile = new File(LOG_FILE_DIR + File.separator + clientId + File.separator + 
    215                                 "htmlmonitor_" + clientId + ".log"); 
     368                                "htmlmonitor_" + clientId + "_000.log"); 
    216369         
    217370        assertTrue(logFile.exists()); 
    218371         
    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 
    242471    } 
    243472 
     
    258487            "      \"url\":\"http://host/path\"" + 
    259488            "    }," + 
     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            "    }," + 
    260503            "    \"events\":" + 
    261504            "    [ {" + 
    262505            "        \"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\"]" + 
    265509            "      }" + 
    266510            "    ]" + 
     
    279523        } 
    280524         
     525        htmlMonitor.stop(); 
     526        htmlMonitor = null; 
     527         
     528        HTMLLogParser parser = new HTMLLogParser(); 
     529         
    281530        // assert 9 already rotated log files 
    282         for (int i = 0; i < (numberOfSessions - 1); i++) { 
     531        for (int i = 0; i < numberOfSessions; i++) { 
    283532            File logFile = new File(LOG_FILE_DIR + File.separator + clientId + File.separator + 
    284533                                    "htmlmonitor_" + clientId + "_00" + i + ".log"); 
     
    286535            assertTrue(logFile.exists()); 
    287536        
    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()); 
    290605        
    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        } 
    306608    } 
    307609 
     
    335637 
    336638    /** 
    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) 
    371647    { 
    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        } 
    385656    } 
    386657 
  • trunk/autoquest-htmlmonitor-test/src/test/resources/test.html

    r1000 r1069  
    55<script type="text/javascript" 
    66        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> 
    79 
    810<style type="text/css"> 
     
    1618 
    1719</style> 
    18  
     20<meta http-equiv="Content-type" content="text/html;charset=UTF-8"> 
    1921</head> 
    2022 
     
    3032      <tr> 
    3133        <td class="label">input type text</td> 
    32         <td><input type="text"></input></td> 
     34        <td><input type="text" /></td> 
    3335      </tr> 
    3436      <tr> 
     
    3840      <tr> 
    3941        <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> 
    4143      </tr> 
    4244    </table> 
Note: See TracChangeset for help on using the changeset viewer.