Changeset 1069 for trunk


Ignore:
Timestamp:
02/14/13 15:20:07 (11 years ago)
Author:
pharms
Message:
  • support of new HTML logging format
Location:
trunk
Files:
13 added
6 deleted
22 edited
2 moved

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> 
  • trunk/autoquest-htmlmonitor/.settings/org.eclipse.core.resources.prefs

    r918 r1069  
    11eclipse.preferences.version=1 
     2encoding//src/main/java=UTF-8 
     3encoding//src/main/js=UTF-8 
    24encoding/<project>=UTF-8 
  • trunk/autoquest-htmlmonitor/pom.xml

    r938 r1069  
    5656            <artifactId>json-simple</artifactId> 
    5757            <version>1.1.1</version> 
     58        </dependency> 
     59        <dependency> 
     60            <groupId>commons-codec</groupId> 
     61            <artifactId>commons-codec</artifactId> 
     62            <version>1.7</version> 
    5863        </dependency> 
    5964    </dependencies> 
     
    118123                    <descriptors> 
    119124                        <descriptor>src/main/assembly/bin.xml</descriptor> 
     125                        <descriptor>src/main/assembly/config.xml</descriptor> 
    120126                    </descriptors> 
    121127                </configuration> 
  • trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlEvent.java

    r942 r1069  
    3838 
    3939    /** 
    40      * the path in the HTML DOM to the object on which the event was executed 
    41      */ 
    42     private String path; 
     40     * the HTML element on which the event was executed 
     41     */ 
     42    private HtmlPageElement target; 
     43 
     44    /** 
     45     * the document to which the HTML element on which the event was executed belongs 
     46     */ 
     47    private HtmlDocument targetDocument; 
     48 
     49    /** 
     50     * the targets DOM path through the document to which it belongs 
     51     */ 
     52    private String targetDOMPath; 
    4353 
    4454    /** 
     
    6979    /** 
    7080     * <p> 
    71      * initializes the event with all relevantinfos 
     81     * initializes the event with all relevant infos 
    7282     * </p> 
    7383     * 
    7484     * @param clientInfos    infos about the client that caused the event 
    7585     * @param time           the time stamp of the event 
    76      * @param path           the path in the HTML DOM to the object on which the event was executed 
     86     * @param target         the HTML element on which the event was executed 
    7787     * @param eventType      the type of the event, e.g. onclick 
    7888     * @param coordinates    the coordinates of the event, usually an array with two values 
     
    8696    HtmlEvent(HtmlClientInfos clientInfos, 
    8797              Long            time, 
    88               String          path, 
     98              HtmlPageElement target, 
    8999              String          eventType, 
    90100              Integer[]       coordinates, 
     
    95105        this.clientInfos = clientInfos; 
    96106        this.time = time; 
    97         this.path = path; 
     107        this.target = target; 
     108        this.targetDocument = target.getDocument(); 
     109        this.targetDOMPath = target.getDOMPath(); 
    98110        this.eventType = eventType; 
    99111        this.coordinates = coordinates; 
     
    104116 
    105117    /** 
     118     * <p> 
     119     * initializes the event for which the id of the target is not known yet. In this case 
     120     * the document and DOM path for the target are provided 
     121     * </p> 
     122     * 
     123     * @param clientInfos    infos about the client that caused the event 
     124     * @param time           the time stamp of the event 
     125     * @param targetDocument the document to which the HTML element belongs on which the event was 
     126     *                       executed 
     127     * @param targetDOMPath  the path through the DOM of the document of the HTML element on which 
     128     *                       the event was executed 
     129     * @param eventType      the type of the event, e.g. onclick 
     130     * @param coordinates    the coordinates of the event, usually an array with two values 
     131     *                       (x and y) 
     132     * @param key            if the event is a key event, the key that was pressed or released 
     133     * @param scrollPosition if the event is a scroll event, the resulting position of the 
     134     *                       scrolled element 
     135     * @param selectedValue  if the event is an on change event, the value to which the changed 
     136     *                       element is changed 
     137     */ 
     138    HtmlEvent(HtmlClientInfos clientInfos, 
     139              Long            time, 
     140              HtmlDocument    targetDocument, 
     141              String          targetDOMPath, 
     142              String          eventType, 
     143              Integer[]       coordinates, 
     144              Integer         key, 
     145              Integer[]       scrollPosition, 
     146              String          selectedValue) 
     147    { 
     148        this.clientInfos = clientInfos; 
     149        this.time = time; 
     150        this.targetDocument = targetDocument; 
     151        this.targetDOMPath = targetDOMPath; 
     152        this.eventType = eventType; 
     153        this.coordinates = coordinates; 
     154        this.key = key; 
     155        this.scrollPosition = scrollPosition; 
     156        this.selectedValue = selectedValue; 
     157    } 
     158 
     159    /** 
    106160     * @return the clientInfos 
    107161     */ 
     
    118172 
    119173    /** 
    120      * @return the path 
    121      */ 
    122     String getPath() { 
    123         return path; 
     174     * @return the target 
     175     */ 
     176    HtmlPageElement getTarget() { 
     177        return target; 
     178    } 
     179 
     180    /** 
     181     * @return the targetDocument 
     182     */ 
     183    HtmlDocument getTargetDocument() { 
     184        return targetDocument; 
     185    } 
     186 
     187    /** 
     188     * @return the targetDOMPath 
     189     */ 
     190    String getTargetDOMPath() { 
     191        return targetDOMPath; 
    124192    } 
    125193 
  • trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorLogManager.java

    r1019 r1069  
    116116    @Override 
    117117    public void handleMessage(HtmlClientInfos clientInfos, 
    118                               HtmlPageElement guiStructure, 
     118                              HtmlGUIElement guiStructure, 
    119119                              HtmlEvent[]     events) 
    120120    { 
     
    140140            Console.printerrln("could not handle message of client " + clientInfos.getClientId() + 
    141141                               ": " + e); 
     142            e.printStackTrace(); 
    142143            Console.logException(e); 
    143144             
  • trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorMessageListener.java

    r1022 r1069  
    3636     */ 
    3737    void handleMessage(HtmlClientInfos clientInfos, 
    38                        HtmlPageElement guiStructure, 
     38                       HtmlGUIElement guiStructure, 
    3939                       HtmlEvent[]     events); 
    4040 
  • trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorOutputWriter.java

    r1022 r1069  
    179179    @Override 
    180180    public void handleMessage(HtmlClientInfos clientInfos, 
    181                               HtmlPageElement guiStructure, 
     181                              HtmlGUIElement guiStructure, 
    182182                              HtmlEvent[]     events) 
    183183    { 
     
    214214     * @param guiStructure the GUI structure to be logged 
    215215     */ 
    216     private void dumpGuiStructure(HtmlPageElement guiStructure) { 
    217         outputWriter.print("<component path=\""); 
    218         outputWriter.print(guiStructure.getPath()); 
     216    private void dumpGuiStructure(HtmlGUIElement guiStructure) { 
     217        outputWriter.print("<component id=\""); 
     218        outputWriter.print(guiStructure.getId()); 
    219219        outputWriter.println("\">"); 
    220220         
    221         dumpParam("class", guiStructure.getTagName()); 
    222         dumpParam("htmlId", guiStructure.getId()); 
    223         dumpParam("title", guiStructure.getTitle()); 
    224         dumpParam("index", guiStructure.getIndex()); 
    225         dumpParam("parent", guiStructure.getParentPath()); 
     221        if (guiStructure instanceof HtmlServer) { 
     222            dumpParam("host", ((HtmlServer) guiStructure).getName()); 
     223            dumpParam("port", ((HtmlServer) guiStructure).getPort()); 
     224        } 
     225        else if (guiStructure instanceof HtmlDocument) { 
     226            dumpParam("path", ((HtmlDocument) guiStructure).getPath()); 
     227            dumpParam("query", ((HtmlDocument) guiStructure).getQuery()); 
     228            dumpParam("title", ((HtmlDocument) guiStructure).getTitle()); 
     229        } 
     230        else if (guiStructure instanceof HtmlPageElement) { 
     231            dumpParam("tagname", ((HtmlPageElement) guiStructure).getTagName()); 
     232            dumpParam("htmlid", ((HtmlPageElement) guiStructure).getHtmlId()); 
     233            dumpParam("index", ((HtmlPageElement) guiStructure).getIndex()); 
     234        } 
     235         
     236        dumpParam("parent", guiStructure.getParentId()); 
    226237         
    227238        outputWriter.println("</component>"); 
    228239         
    229240        if (guiStructure.getChildren() != null) { 
    230             for (HtmlPageElement child : guiStructure.getChildren()) { 
     241            for (HtmlGUIElement child : guiStructure.getChildren()) { 
    231242                dumpGuiStructure(child); 
    232243            } 
     
    260271 
    261272        dumpParam("selectedValue", event.getSelectedValue()); 
    262         dumpParam("target", event.getPath()); 
     273         
     274        if (event.getTarget() != null) { 
     275            dumpParam("target", event.getTarget().getId()); 
     276        } 
     277        else { 
     278            dumpParam("targetDocument", event.getTargetDocument().getId()); 
     279            dumpParam("targetDOMPath", event.getTargetDOMPath()); 
     280        } 
    263281        dumpParam("timestamp", event.getTime()); 
    264282         
  • trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorServlet.java

    r1022 r1069  
    7878     * the message listener to forward received messages to. 
    7979     */ 
     80    private HtmlGUIElementManager guiElementManager = new HtmlGUIElementManager(); 
     81 
     82    /** 
     83     * the message listener to forward received messages to. 
     84     */ 
    8085    private transient HtmlMonitorMessageListener messageListener; 
    8186 
     
    199204            } 
    200205            else { 
    201                 HtmlPageElement guiStructure = extractHtmlPageElements(message, clientInfos); 
     206                HtmlGUIElement guiStructure = extractHtmlPageElements(message, clientInfos); 
    202207                HtmlEvent[] events = extractHtmlEvents(message, clientInfos); 
    203208                 
     
    275280            events = new ArrayList<HtmlEvent>(); 
    276281             
    277             HtmlPageElement server = getServerElement(clientInfos); 
    278             HtmlPageElement page = getPageElementRepresentingWebPage(clientInfos, server); 
     282            HtmlServer server = getServerElement(clientInfos); 
     283            HtmlDocument document = getPageElementRepresentingWebPage(clientInfos, server); 
    279284 
    280285            for (int i = 0; i < eventArray.size(); i++) { 
     
    285290                else { 
    286291                    Long time = assertValue(((JSONObject) eventObj), "time", Long.class); 
    287                     String path = assertValue(((JSONObject) eventObj), "path", String.class); 
     292                    String domPath = assertValue(((JSONObject) eventObj), "path", String.class); 
    288293                    String eventType = 
    289294                        assertValue(((JSONObject) eventObj), "eventType", String.class); 
     
    302307                        Console.printerrln(eventType + " event has no valid timestamp"); 
    303308                    } 
    304                     else if (path == null) { 
    305                         Console.printerrln(eventType + " event has no valid path"); 
     309                    else if (domPath == null) { 
     310                        Console.printerrln(eventType + " event has no valid DOM path"); 
    306311                    } 
    307312                    else if ((coordinates != null) && (coordinates.length != 2)) { 
     
    311316                                (eventType, coordinates, key, scrollPosition, selectedValue)) 
    312317                    { 
    313                         path = page.getPath() + path; 
    314                         events.add(new HtmlEvent(clientInfos, time, path, eventType, 
    315                                                  coordinates, key, scrollPosition, selectedValue)); 
     318                        HtmlPageElement target = 
     319                            guiElementManager.getPageElement(document, domPath); 
     320                         
     321                        if (target != null) { 
     322                            events.add(new HtmlEvent(clientInfos, time, target, eventType, 
     323                                                     coordinates, key, scrollPosition, 
     324                                                     selectedValue)); 
     325                        } 
     326                        else { 
     327                            events.add(new HtmlEvent(clientInfos, time, document, domPath, 
     328                                                     eventType, coordinates, key, scrollPosition, 
     329                                                     selectedValue)); 
     330                        } 
    316331                    } 
    317332                    else { 
     
    342357     *         representation of the server of the HTML page that was observed  
    343358     */ 
    344     private HtmlPageElement extractHtmlPageElements(JSONObject      object, 
    345                                                     HtmlClientInfos clientInfos) 
     359    private HtmlServer extractHtmlPageElements(JSONObject      object, 
     360                                               HtmlClientInfos clientInfos) 
    346361    { 
    347         HtmlPageElement server = getServerElement(clientInfos); 
    348         HtmlPageElement page = getPageElementRepresentingWebPage(clientInfos, server); 
     362        HtmlServer server = getServerElement(clientInfos); 
     363        HtmlDocument document = getPageElementRepresentingWebPage(clientInfos, server); 
    349364 
    350365        JSONObject jsonPageElement = assertValue(object, "guiModel", JSONObject.class); 
    351         page.addChild(convert(jsonPageElement, page.getPath())); 
     366        document.addChild(convert(jsonPageElement, document, null)); 
    352367         
    353368        return server; 
     
    364379     * @return as described 
    365380     */ 
    366     private HtmlPageElement getServerElement(HtmlClientInfos clientInfos) { 
    367         String id = clientInfos.getUrl().getHost(); 
     381    private HtmlServer getServerElement(HtmlClientInfos clientInfos) { 
     382        String host = clientInfos.getUrl().getHost(); 
     383        int port = 80; 
     384         
    368385        if (clientInfos.getUrl().getPort() > -1) { 
    369             id += ":" + clientInfos.getUrl().getPort(); 
    370         } 
    371          
    372         return new HtmlPageElement(null, "server", id, 0); 
     386            port = clientInfos.getUrl().getPort(); 
     387        } 
     388         
     389        return guiElementManager.createHtmlServer(host, port); 
    373390    } 
    374391 
     
    384401     * @return as described 
    385402     */ 
    386     private HtmlPageElement getPageElementRepresentingWebPage(HtmlClientInfos clientInfos, 
    387                                                               HtmlPageElement server) 
     403    private HtmlDocument getPageElementRepresentingWebPage(HtmlClientInfos clientInfos, 
     404                                                           HtmlServer      server) 
    388405    { 
    389         String id = clientInfos.getUrl().getPath(); 
     406        String path = clientInfos.getUrl().getPath(); 
     407        String query = null; 
    390408         
    391409        if (clientInfos.getUrl().getQuery() != null) { 
    392             id += "?" + clientInfos.getUrl().getQuery(); 
    393         } 
    394          
    395         HtmlPageElement page = 
    396             new HtmlPageElement(server.getPath(), "document", id, clientInfos.getTitle(), 0); 
    397          
    398         server.addChild(page); 
    399          
    400         return page; 
     410            query = "?" + clientInfos.getUrl().getQuery(); 
     411        } 
     412         
     413        HtmlDocument document = guiElementManager.createHtmlDocument 
     414            (server, path, query, clientInfos.getTitle()); 
     415         
     416        server.addChild(document); 
     417         
     418        return document; 
    401419    } 
    402420 
     
    408426     * 
    409427     * @param jsonPageElement the JSON object to be converted 
    410      * @param parentPath      the path through the DOM of the parent HTML page element of the 
    411      *                        converted one 
     428     * @param document        the document to which the page element belongs 
     429     * @param parent          the parent page element of the converted element, of null, if none 
     430     *                        is present. In this case the document is considered the parent 
     431     *                        element. 
    412432     *                         
    413433     * @return as described. 
    414434     */ 
    415     private HtmlPageElement convert(JSONObject jsonPageElement, String parentPath) { 
     435    private HtmlPageElement convert(JSONObject      jsonPageElement, 
     436                                    HtmlDocument    document, 
     437                                    HtmlPageElement parent) 
     438    { 
    416439        HtmlPageElement result = null; 
    417440 
    418441        if (jsonPageElement != null) { 
    419442            String tagName = assertValue(jsonPageElement, "tagName", String.class); 
    420             String id = assertValue(jsonPageElement, "id", String.class); 
     443            String htmlid = assertValue(jsonPageElement, "htmlId", String.class); 
    421444            Integer index = assertValue(jsonPageElement, "index", Integer.class); 
    422445 
    423             result = new HtmlPageElement(parentPath, tagName, id, index); 
     446            result = guiElementManager.createHtmlPageElement 
     447                (document, parent, tagName, htmlid, index); 
    424448 
    425449            JSONArray childElements = assertValue(jsonPageElement, "children", JSONArray.class); 
     
    435459                    } 
    436460                    else { 
    437                         result.addChild(convert((JSONObject) jsonChild, result.getPath())); 
     461                        result.addChild(convert((JSONObject) jsonChild, document, result)); 
    438462                    } 
    439463                } 
  • trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlPageElement.java

    r1022 r1069  
    1515package de.ugoe.cs.autoquest.htmlmonitor; 
    1616 
    17 import java.util.ArrayList; 
    18 import java.util.List; 
    19  
    2017/** 
    2118 * <p> 
    22  * represents an element of an HTML GUI. This can be a server, which is usually the root of a 
    23  * GUI structure, a web page, or a tag within a web page. 
     19 * represents an element of an HTML GUI, i.e. a tag within a web page. 
    2420 * </p> 
    2521 *  
    2622 * @author Patrick Harms 
    2723 */ 
    28 class HtmlPageElement { 
    29  
    30     /** 
    31      * path to the parent of this page element or null, if this is the root element 
    32      */ 
    33     private String parentPath; 
    34      
    35     /** 
    36      * the name of the tag represented by this page element. May also be the name of the server 
    37      * or the page. 
     24class HtmlPageElement extends HtmlGUIElement { 
     25 
     26    /** 
     27     * the document to which the represented tag belongs 
     28     */ 
     29    private HtmlDocument document; 
     30     
     31    /** 
     32     * the parent page element; if null, the document is considered the parent 
     33     */ 
     34    private HtmlPageElement parent; 
     35     
     36    /** 
     37     * the name of the tag represented by this page element. 
    3838     */ 
    3939    private String tagName; 
    4040     
    4141    /** 
    42      * the id of the page element. May also be the name of the server including port number or the 
    43      * URL of the page 
    44      */ 
    45     private String id; 
    46      
    47     /** 
    48      * the title of the page if a page is represented through this element 
    49      */ 
    50     private String title; 
     42     * the id of the page element inside the DOM. 
     43     */ 
     44    private String htmlId; 
    5145     
    5246    /** 
     
    5751     
    5852    /** 
    59      * the children of this element 
    60      */ 
    61     private List<HtmlPageElement> children; 
    62  
    63     /** 
    6453     * <p> 
    6554     * instantiates a new element representing a tag in an HTML page 
    6655     * </p> 
    6756     * 
    68      * @param parentPath the path through the DOM to the parent node of the represented tag  
    69      * @param tagName    the name of the represented tag 
    70      * @param id         the id of the tag in the DOM 
    71      * @param index      the index of the represented tag regarding all tags with the same tag name 
    72      *                   in the list of children of the parent tag 
    73      */ 
    74     HtmlPageElement(String parentPath, String tagName, String id, Integer index) { 
    75         this.parentPath = parentPath; 
     57     * @param id       the id of the page element 
     58     * @param document the document to which the represented tag belongs 
     59     * @param parent   the parent page element; if null, the document is considered the parent 
     60     * @param tagName  the name of the represented tag 
     61     * @param htmlId   the id of the tag in the DOM 
     62     * @param index    the index of the represented tag regarding all tags with the same 
     63     *                 tag name in the list of children of the parent tag 
     64     */ 
     65    HtmlPageElement(String          id, 
     66                    HtmlDocument    document, 
     67                    HtmlPageElement parent, 
     68                    String          tagName, 
     69                    String          htmlId, 
     70                    Integer         index) 
     71    { 
     72        super(id, parent == null ? document : parent); 
     73         
     74        if (document == null) { 
     75            throw new IllegalArgumentException("document must not be null"); 
     76        } 
     77 
     78        if (tagName == null) { 
     79            throw new IllegalArgumentException("tagName must not be null"); 
     80        } 
     81         
     82        if ((htmlId == null) && (index == null)) { 
     83            throw new IllegalArgumentException("either one of htmlId and index must not be null"); 
     84        } 
     85         
     86        this.document = document; 
     87        this.parent = parent; 
    7688        this.tagName = tagName; 
    77         this.id = id; 
     89        this.htmlId = htmlId; 
    7890        this.index = index; 
    7991    } 
     
    8193    /** 
    8294     * <p> 
    83      * instantiates a new element representing an HTML page 
     95     * returns the document to which the represented tag belongs 
    8496     * </p> 
    8597     * 
    86      * @param parentPath the path through the DOM to the parent node of the represented tag which is 
    87      *                   usually a server 
    88      * @param tagName    the name of the represented tag which is the path of the web page 
    89      * @param title      the title of the web page 
    90      * @param id         the id of the web page which is its path 
    91      * @param index      usually 0 
    92      */ 
    93     HtmlPageElement(String parentPath, String tagName, String id, String title, Integer index) { 
    94         this(parentPath, tagName, id, index); 
    95         this.title = title; 
    96     } 
    97  
    98     /** 
    99      * <p> 
    100      * returns the name of the tag represented by this page element. May also be the name of the 
    101      * server or the page. 
     98     * @return the document 
     99     */ 
     100    HtmlDocument getDocument() { 
     101        return document; 
     102    } 
     103 
     104    /** 
     105     * <p> 
     106     * returns the name of the tag represented by this page element. 
    102107     * </p> 
    103108     *  
     
    110115    /** 
    111116     * <p> 
    112      * returns the id of the page element. May also be the name of the server including port 
    113      * number or the URL of the page 
     117     * returns the id of the page element. 
    114118     * </p> 
    115119     *  
    116120     * @return the id 
    117121     */ 
    118     String getId() { 
    119         return id; 
    120     } 
    121  
    122     /** 
    123      * <p> 
    124      * returns the title of the page if a page is represented through this element 
    125      * </p> 
    126      *  
    127      * @return the title 
    128      */ 
    129     String getTitle() { 
    130         return title; 
     122    String getHtmlId() { 
     123        return htmlId; 
    131124    } 
    132125 
     
    141134    Integer getIndex() { 
    142135        return index; 
    143     } 
    144  
    145     /** 
    146      * <p> 
    147      * returns the children of this element if any, null else 
    148      * </p> 
    149      *  
    150      * @return the children 
    151      */ 
    152     List<HtmlPageElement> getChildren() { 
    153         return children; 
    154     } 
    155  
    156  
    157     /** 
    158      * adds a child to this element 
    159      *  
    160      * @param child the child to be added 
    161      */ 
    162     void addChild(HtmlPageElement child) { 
    163         if (child != null) { 
    164             if (children == null) { 
    165                 children = new ArrayList<HtmlPageElement>(); 
    166             } 
    167              
    168             children.add(child); 
    169         } 
    170     } 
    171  
    172     /** 
    173      * <p> 
    174      * returns the path to the parent of this page element or null, if this is the root element 
    175      * </p> 
    176      * 
    177      * @return as described 
    178      */ 
    179     String getParentPath() { 
    180         return parentPath; 
    181136    } 
    182137 
     
    190145     * @return as described 
    191146     */ 
    192     String getPath() { 
     147    String getDOMPath() { 
    193148        StringBuffer result = new StringBuffer(); 
    194         if (parentPath != null) { 
    195             result.append(parentPath); 
     149        if (parent != null) { 
     150            result.append(parent.getDOMPath()); 
    196151        } 
    197152 
     
    199154        result.append(tagName); 
    200155         
    201         if ((id != null) && (!"".equals(id))) { 
    202             result.append("(id="); 
    203             result.append(id); 
     156        if ((htmlId != null) && (!"".equals(htmlId))) { 
     157            result.append("(htmlId="); 
     158            result.append(htmlId); 
    204159            result.append(")"); 
    205160        } 
     
    213168    } 
    214169 
     170    /* (non-Javadoc) 
     171     * @see de.ugoe.cs.autoquest.htmlmonitor.HtmlGUIElement#equals(de.ugoe.cs.autoquest.htmlmonitor.HtmlGUIElement) 
     172     */ 
     173    @Override 
     174    public boolean equals(HtmlGUIElement obj) { 
     175        if (this == obj) { 
     176            return true; 
     177        } 
     178        else if (obj instanceof HtmlPageElement) { 
     179            return equals((HtmlPageElement) obj); 
     180        } 
     181        else { 
     182            return false; 
     183        } 
     184    } 
     185 
     186    /* (non-Javadoc) 
     187     * @see de.ugoe.cs.autoquest.htmlmonitor.HtmlGUIElement#equals(de.ugoe.cs.autoquest.htmlmonitor.HtmlGUIElement) 
     188     */ 
     189    public boolean equals(HtmlPageElement other) { 
     190        if (this == other) { 
     191            return true; 
     192        } 
     193 
     194        return (document.equals(other.document) && tagName.equals(other.tagName) && 
     195                (parent != null ? parent.equals(other.parent) : other.parent == null) && 
     196                (htmlId != null ? htmlId.equals(other.htmlId) : other.htmlId == null) && 
     197                (index != null ? index.equals(other.index) : other.index == null)); 
     198    } 
     199 
     200    /* (non-Javadoc) 
     201     * @see java.lang.Object#hashCode() 
     202     */ 
     203    @Override 
     204    public int hashCode() { 
     205        return document.hashCode() + tagName.hashCode() + (parent != null ? parent.hashCode() : 0) + 
     206            (htmlId != null ? htmlId.hashCode() : 0) + (index != null ? index : 0); 
     207    } 
     208 
    215209} 
  • trunk/autoquest-htmlmonitor/src/main/js/autoquest-htmlmonitor.js

    r1023 r1069  
    305305         
    306306        if ((node.id) && (node.id !== "")) { 
    307             jsonRepresentation += "\"id\":\"" + node.id + "\""; 
     307            jsonRepresentation += "\"htmlId\":\"" + node.id + "\""; 
    308308        } 
    309309        else { 
  • trunk/autoquest-plugin-html-test/.classpath

    r953 r1069  
    1313                </attributes> 
    1414        </classpathentry> 
    15         <classpathentry kind="src" path="src/test/resources"/> 
     15        <classpathentry including="**/*.java" kind="src" path="src/test/resources"/> 
    1616        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"> 
    1717                <attributes> 
  • trunk/autoquest-plugin-html-test/pom.xml

    r953 r1069  
    2828                <executions> 
    2929                    <execution> 
    30                         <id>get-jfc-plugin-config</id> 
     30                        <id>get-html-plugin-config</id> 
    3131                        <phase>process-classes</phase> 
    3232                        <goals> 
  • trunk/autoquest-plugin-html-test/src/test/java/de/ugoe/cs/autoquest/plugin/html/HTMLLogParserTest.java

    r1066 r1069  
    1919import java.io.File; 
    2020import java.util.Collection; 
     21import java.util.Iterator; 
    2122import java.util.List; 
    2223import java.util.logging.Level; 
     
    5455   public void testParseFile() throws Exception { 
    5556       HTMLLogParser parser = new HTMLLogParser(); 
    56        parser.parseFile(new File(ClassLoader.getSystemResource("htmlmonitor_testtrace.xml").getFile())); 
     57       parser.parseFile(new File(ClassLoader.getSystemResource("htmlmonitor_testtrace_1.xml").getFile())); 
     58       parser.parseFile(new File(ClassLoader.getSystemResource("htmlmonitor_testtrace_2.xml").getFile())); 
    5759       Collection<List<Event>> events = parser.getSequences(); 
    5860 
    5961       assertNotNull(events); 
    60        assertTrue(events.size() > 0); 
     62       assertEquals(2, events.size()); 
     63        
     64       Iterator<List<Event>> iterator = events.iterator(); 
     65       assertNotNull(iterator); 
     66       assertEquals(1, iterator.next().size()); 
     67       assertEquals(3, iterator.next().size()); 
     68       assertFalse(iterator.hasNext()); 
    6169 
    6270       System.err.println("{"); 
  • trunk/autoquest-plugin-html/data/guimappings/guimapping-html.txt

    r1012 r1069  
    3030div = de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPanel 
    3131dl = de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPanel 
     32document = de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLDocument 
    3233dt = de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLText 
    3334 
     
    9091 
    9192p = de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPanel 
    92 page = de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPage 
    9393# param = 
    9494pre = de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLText 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/HTMLLogParser.java

    r1064 r1069  
    1515package de.ugoe.cs.autoquest.plugin.html; 
    1616 
    17 import java.io.File; 
    18 import java.io.FileInputStream; 
    19 import java.io.FileNotFoundException; 
    20 import java.io.IOException; 
    21 import java.io.InputStreamReader; 
    22 import java.io.UnsupportedEncodingException; 
    23 import java.util.Collection; 
    24 import java.util.HashMap; 
    25 import java.util.LinkedList; 
    2617import java.util.List; 
    2718import java.util.Map; 
    28  
    29 import javax.xml.parsers.ParserConfigurationException; 
    30 import javax.xml.parsers.SAXParser; 
    31 import javax.xml.parsers.SAXParserFactory; 
    32  
    33 import org.xml.sax.Attributes; 
    34 import org.xml.sax.InputSource; 
     19import java.util.regex.Matcher; 
     20import java.util.regex.Pattern; 
     21 
    3522import org.xml.sax.SAXException; 
    36 import org.xml.sax.SAXParseException; 
    37 import org.xml.sax.helpers.DefaultHandler; 
    3823 
    3924import de.ugoe.cs.autoquest.eventcore.Event; 
    4025import de.ugoe.cs.autoquest.eventcore.IEventType; 
    41 import de.ugoe.cs.autoquest.eventcore.guimodel.GUIElementTree; 
    4226import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel; 
    4327import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; 
    4428import de.ugoe.cs.autoquest.plugin.html.eventcore.HTMLEventTypeFactory; 
     29import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLDocumentSpec; 
    4530import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLGUIElement; 
    4631import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLGUIElementSpec; 
    4732import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPageElementSpec; 
    48 import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPageSpec; 
    4933import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLServerSpec; 
    50 import de.ugoe.cs.util.console.Console; 
    5134 
    5235/** 
    5336 * <p> 
    5437 * This class provides the functionality to parse XML log files generated by the HTMLMonitor of 
    55  * autoquest. The result of parsing a file is a collection of event sequences. 
     38 * AutoQUEST. The result of parsing a file is a collection of event sequences and a GUI model 
    5639 * </p> 
    5740 *  
    58  * @author Fabian Glaser 
     41 * @author Fabian Glaser, Patrick Harms 
    5942 * @version 1.0 
    6043 *  
    6144 */ 
    62 public class HTMLLogParser extends DefaultHandler { 
     45public class HTMLLogParser extends AbstractDefaultLogParser { 
     46     
     47    /** 
     48     * 
     49     */ 
     50    private Pattern htmlElementPattern = 
     51        Pattern.compile("(\\w+)(\\[(\\d+)\\]|\\(htmlId=([\\w-]+)\\))"); 
     52 
     53    /* (non-Javadoc) 
     54     * @see de.ugoe.cs.autoquest.plugin.html.AbstractDefaultLogParser#handleGUIElement(java.lang.String, java.util.Map) 
     55     */ 
     56    @Override 
     57    protected boolean handleGUIElement(String id, Map<String, String> parameters) 
     58        throws SAXException 
     59    { 
     60        HTMLGUIElementSpec specification = null; 
     61         
     62        String parentId = parameters.get("parent"); 
     63        IGUIElement parent = super.getGUIElementTree().find(parentId); 
     64 
     65        if (parameters.containsKey("host")) { 
     66            // this is a server specification 
     67            int port = 80; 
     68            String portStr = parameters.get(port); 
     69             
     70            if (portStr != null) { 
     71                port = Integer.parseInt(portStr); 
     72            } 
     73             
     74            specification = new HTMLServerSpec(parameters.get("host"), port); 
     75        } 
     76        else if (parameters.containsKey("path")) { 
     77            // this is a document specification 
     78             
     79            if (parent != null) { 
     80                if (!(parent.getSpecification() instanceof HTMLServerSpec)) { 
     81                    throw new SAXException 
     82                        ("invalid log: parent GUI element of a document is not of type server"); 
     83                } 
     84                 
     85                specification = new HTMLDocumentSpec 
     86                    ((HTMLServerSpec) parent.getSpecification(), parameters.get("path"), 
     87                     parameters.get("query"), parameters.get("title")); 
     88            } 
     89            else if (parentId == null) { 
     90                throw new SAXException("invalid log: a document has no parent id"); 
     91            } 
     92        } 
     93        else if (parameters.containsKey("tagname")) { 
     94            String tagName = parameters.get("tagname"); 
     95             
     96            if (!tagNameMustBeConsidered(tagName)) { 
     97                return true; 
     98            } 
     99 
     100            if (parent != null) { 
     101                IGUIElement document = parent; 
     102                 
     103                while ((document != null) && 
     104                       (!(document.getSpecification() instanceof HTMLDocumentSpec))) 
     105                { 
     106                    document = document.getParent(); 
     107                } 
     108                 
     109                if (document == null) { 
     110                    throw new SAXException 
     111                        ("invalid log: parent hierarchy of a page element does not contain a " + 
     112                         "document"); 
     113                } 
     114                 
     115                int index = -1; 
     116                String indexStr = parameters.get("index"); 
     117 
     118                if ((indexStr != null) && (!"".equals(indexStr))) { 
     119                    index = Integer.parseInt(indexStr); 
     120                } 
     121 
     122                specification = new HTMLPageElementSpec 
     123                    ((HTMLDocumentSpec) document.getSpecification(), tagName, 
     124                     parameters.get("htmlid"), index); 
     125            } 
     126            else if (parentId == null) { 
     127                throw new SAXException("invalid log: a page element has no parent id"); 
     128            } 
     129        } 
     130        else { 
     131            throw new SAXException("invalid log: unknown GUI element"); 
     132        } 
     133 
     134        if (specification != null) { 
     135            super.getGUIElementTree().add(id, parentId, specification); 
     136            return true; 
     137        } 
     138        else { 
     139            return false; 
     140        } 
     141    } 
     142 
     143    /* (non-Javadoc) 
     144     * @see de.ugoe.cs.autoquest.plugin.html.AbstractDefaultLogParser#handleEvent(java.lang.String, java.util.Map) 
     145     */ 
     146    @Override 
     147    protected boolean handleEvent(String type, Map<String, String> parameters) throws SAXException { 
     148        String targetId = parameters.get("target"); 
     149         
     150        if (targetId == null) { 
     151            String targetDocument = parameters.get("targetDocument"); 
     152            String targetDOMPath = parameters.get("targetDOMPath"); 
     153             
     154            if ((targetDocument == null) || (targetDOMPath == null)) { 
     155                throw new SAXException("event has no target defined"); 
     156            } 
     157             
     158            targetId = determineTargetId(targetDocument, targetDOMPath); 
     159             
     160            if (targetId == null) { 
     161                // the target id can not be determined yet 
     162                return false; 
     163            } 
     164        } 
     165         
     166        IGUIElement target = super.getGUIElementTree().find(targetId); 
     167         
     168        if (target == null) { 
     169            // event not processable yet 
     170            return false; 
     171        } 
     172 
     173        IEventType eventType = 
     174            HTMLEventTypeFactory.getInstance().getEventType(type, parameters, target); 
     175         
     176        Event event = new Event(eventType, target); 
     177 
     178        String timestampStr = parameters.get("timestamp"); 
     179         
     180        if (timestampStr != null) { 
     181            event.setTimestamp(Long.parseLong(timestampStr)); 
     182        } 
     183 
     184        ((HTMLGUIElement) event.getTarget()).markUsed(); 
     185         
     186        super.addToSequence(event); 
     187 
     188        return true; 
     189    } 
     190 
    63191    /** 
    64192     * <p> 
    65      * Constructor. Creates a new HTMLLogParser. 
     193     * TODO: comment 
    66194     * </p> 
    67      */ 
    68     public HTMLLogParser() { 
    69         sequences = new LinkedList<List<Event>>(); 
     195     * 
     196     * @param targetDocument 
     197     * @param targetDOMPath 
     198     * @return 
     199     */ 
     200    private String determineTargetId(String targetDocument, String targetDOMPath) 
     201        throws SAXException 
     202    { 
     203        IGUIElement document = super.getGUIElementTree().find(targetDocument); 
     204         
     205        if (document == null) { 
     206            return null; 
     207        } 
     208         
     209        if (!(document.getSpecification() instanceof HTMLDocumentSpec)) { 
     210            throw new SAXException("an id that should refer to an HTML document refers to" + 
     211                                   "something else"); 
     212        } 
     213         
     214        GUIModel model = super.getGUIElementTree().getGUIModel(); 
     215        IGUIElement child = document; 
     216        String[] pathElements = targetDOMPath.split("/"); 
     217        int pathIndex = 0; 
     218         
     219        HTMLPageElementSpec compareSpec; 
     220        String tagName; 
     221        int index; 
     222        String htmlId; 
     223         
     224        while ((pathIndex < pathElements.length) && (child != null)) { 
     225            if ((pathElements[pathIndex] != null) && (!"".equals(pathElements[pathIndex]))) {            
     226                Matcher matcher = htmlElementPattern.matcher(pathElements[pathIndex]); 
     227                if (!matcher.matches()) { 
     228                    throw new SAXException 
     229                        ("could not parse target DOM path element " + pathElements[pathIndex]); 
     230                } 
     231 
     232                tagName = matcher.group(1); 
     233                String indexStr = matcher.group(3); 
     234                htmlId = matcher.group(4); 
     235 
     236                index = -1; 
     237                if ((indexStr != null) && (!"".equals(indexStr))) { 
     238                    index = Integer.parseInt(indexStr); 
     239                } 
     240 
     241                compareSpec = new HTMLPageElementSpec 
     242                    ((HTMLDocumentSpec) document.getSpecification(), tagName, htmlId, index); 
     243 
     244                List<IGUIElement> children = model.getChildren(child); 
     245                child = null; 
     246 
     247                for (IGUIElement candidate : children) { 
     248                    if (compareSpec.getSimilarity(candidate.getSpecification())) { 
     249                        child = candidate; 
     250                        break; 
     251                    } 
     252                } 
     253            } 
     254             
     255            pathIndex++; 
     256        } 
     257         
     258        if (child != null) { 
     259            return super.getGUIElementTree().find(child); 
     260        } 
     261        else { 
     262            return null; 
     263        } 
    70264    } 
    71265 
    72266    /** 
    73267     * <p> 
    74      * Collection of event sequences that is contained in the parsed log file. 
     268     * checks if tags with the provided name must be handled in the GUI model. As an example, 
     269     * it is not necessary to handle "head" tags and anything included in them.  
    75270     * </p> 
    76      */ 
    77     private Collection<List<Event>> sequences; 
    78  
    79     /** 
    80      * <p> 
    81      * Internal handle to the parsed GUI structure, stored in a GUIElementTree 
    82      * </p> 
    83      */ 
    84     private GUIElementTree<String> currentGUIElementTree; 
    85  
    86     /** 
    87      * <p> 
    88      * Path of the GUI element currently being parsed. 
    89      * </p> 
    90      */ 
    91     private String currentGUIElementPath; 
    92  
    93     /** 
    94      * <p> 
    95      * Path of the parent of the GUI element currently being parsed. 
    96      * </p> 
    97      */ 
    98     private String currentParentPath; 
    99  
    100     /** 
    101      * <p> 
    102      * Source of the GUI element currently being parsed. 
    103      * </p> 
    104      */ 
    105     private String currentEventSource; 
    106  
    107     /** 
    108      * <p> 
    109      * Timestamp of the event currently being parsed. 
    110      * </p> 
    111      */ 
    112     private Long currentEventTimestamp; 
    113  
    114     /** 
    115      * <p> 
    116      * Internal handle to the parameters of the event currently being parsed. 
    117      * </p> 
    118      */ 
    119     private Map<String, String> currentEventParameters; 
    120  
    121     /** 
    122      * <p> 
    123      * Internal handle to the parameters of the GUI element currently being parsed. 
    124      * </p> 
    125      */ 
    126     private Map<String, String> currentGUIElementParameters; 
    127     /** 
    128      * <p> 
    129      * Internal handle to the sequence currently being parsed. 
    130      * </p> 
    131      */ 
    132     private List<Event> currentSequence; 
    133  
    134     /** 
    135      * <p> 
    136      * Internal handle to type of the event currently being parsed. 
    137      * </p> 
    138      */ 
    139     private String currentEventType; 
    140  
    141     /** 
    142      * <p> 
    143      * Class of the GUI element currently being parsed. 
    144      * </p> 
    145      */ 
    146     private String currentGUIElementClass; 
    147  
    148     /** 
    149      * <p> 
    150      * Index of the GUI element currently being parsed. 
    151      * </p> 
    152      */ 
    153     private String currentGUIElementIndex; 
    154  
    155     /** 
    156      * <p> 
    157      * internal handle to the GUI element of the previous event to be potentially reused for the 
    158      * current 
    159      * </p> 
    160      */ 
    161     private IGUIElement lastGUIElement; 
    162  
    163     /** 
    164      * <p> 
    165      * internal handle to the server specification currently being used. 
    166      * </p> 
    167      */ 
    168     private HTMLServerSpec currentServerSpec; 
    169  
    170     /** 
    171      * <p> 
    172      * Parses a log file written by the HTMLMonitor and creates a collection of event sequences. 
    173      * </p> 
    174      *  
    175      * @param filename 
    176      *            name and path of the log file 
    177      */ 
    178     public void parseFile(String filename) { 
    179         if (filename == null) { 
    180             throw new IllegalArgumentException("filename must not be null"); 
    181         } 
    182  
    183         parseFile(new File(filename)); 
    184     } 
    185  
    186     /** 
    187      * <p> 
    188      * Parses a log file written by the HTMLMonitor and creates a collection of event sequences. 
    189      * </p> 
    190      *  
    191      * @param file 
    192      *            file to be parsed 
    193      */ 
    194     public void parseFile(File file) { 
    195         if (file == null) { 
    196             throw new IllegalArgumentException("file must not be null"); 
    197         } 
    198         SAXParserFactory spf = SAXParserFactory.newInstance(); 
    199         spf.setValidating(true); 
    200         SAXParser saxParser = null; 
    201         InputSource inputSource = null; 
    202         try { 
    203             saxParser = spf.newSAXParser(); 
    204             inputSource = 
    205                 new InputSource(new InputStreamReader(new FileInputStream(file), "UTF-8")); 
    206         } 
    207         catch (UnsupportedEncodingException e) { 
    208             Console.printerr("Error parsing file " + file.getName()); 
    209             Console.logException(e); 
    210             return; 
    211         } 
    212         catch (ParserConfigurationException e) { 
    213             Console.printerr("Error parsing file " + file.getName()); 
    214             Console.logException(e); 
    215             return; 
    216         } 
    217         catch (SAXException e) { 
    218             Console.printerr("Error parsing file " + file.getName()); 
    219             Console.logException(e); 
    220         } 
    221         catch (FileNotFoundException e) { 
    222             Console.printerr("Error parsing file " + file.getName()); 
    223             Console.logException(e); 
    224         } 
    225         if (inputSource != null) { 
    226             inputSource.setSystemId("file://" + file.getAbsolutePath()); 
    227             try { 
    228                 if (saxParser == null) { 
    229                     throw new RuntimeException("SaxParser creation failed"); 
    230                 } 
    231                 saxParser.parse(inputSource, this); 
    232             } 
    233             catch (SAXParseException e) { 
    234                 Console.printerrln("Failure parsing file in line " + e.getLineNumber() + 
    235                     ", column " + e.getColumnNumber() + "."); 
    236                 Console.logException(e); 
    237             } 
    238             catch (SAXException e) { 
    239                 Console.printerr("Error parsing file " + file.getName()); 
    240                 Console.logException(e); 
    241                 return; 
    242             } 
    243             catch (IOException e) { 
    244                 Console.printerr("Error parsing file " + file.getName()); 
    245                 Console.logException(e); 
    246                 return; 
    247             } 
    248         } 
    249     } 
    250  
    251     /* 
    252      * (non-Javadoc) 
    253      *  
    254      * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, 
    255      * java.lang.String, org.xml.sax.Attributes) 
    256      */ 
    257     @Override 
    258     public void startElement(String uri, String localName, String qName, Attributes atts) 
    259         throws SAXException 
    260     { 
    261         if (qName.equals("session")) { 
    262             currentSequence = new LinkedList<Event>(); 
    263             if (currentGUIElementTree == null) 
    264                 currentGUIElementTree = new GUIElementTree<String>(); 
    265         } 
    266         else if (qName.equals("component")) { 
    267             currentGUIElementPath = atts.getValue("path"); 
    268             currentGUIElementParameters = new HashMap<String, String>(); 
    269         } 
    270         else if (qName.equals("event")) { 
    271             currentEventType = atts.getValue("type"); 
    272             currentEventParameters = new HashMap<String, String>(); 
    273         } 
    274         else if (qName.equals("param")) { 
    275             String paramName = atts.getValue("name"); 
    276             if (currentGUIElementPath != null) { 
    277                 if ("parent".equals(paramName)) { 
    278                     currentParentPath = atts.getValue("value"); 
    279                 } 
    280                 if ("class".equals(paramName)) { 
    281                     currentGUIElementClass = atts.getValue("value"); 
    282                 } 
    283                 if ("index".equals(paramName)) { 
    284                     currentGUIElementIndex = atts.getValue("value"); 
    285                 } 
    286                 currentGUIElementParameters.put(paramName, atts.getValue("value")); 
    287             } 
    288             else if (currentEventType != null) { 
    289                 if ("target".equals(paramName)) { 
    290                     currentEventSource = atts.getValue("value"); 
    291                 } 
    292                 if ("timestamp".equals(paramName)) { 
    293                     currentEventTimestamp = Long.parseLong(atts.getValue("value")); 
    294                 } 
    295                 currentEventParameters.put(paramName, atts.getValue("value")); 
    296             } 
    297             else { 
    298                 throw new SAXException("param tag found where it should not be."); 
    299             } 
    300         } 
    301         else { 
    302             throw new SAXException("unknown tag found: " + qName); 
    303         } 
    304  
    305     } 
    306  
    307     /* 
    308      * (non-Javadoc) 
    309      *  
    310      * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, 
    311      * java.lang.String) 
    312      */ 
    313     @Override 
    314     public void endElement(String uri, String localName, String qName) throws SAXException { 
    315         if (qName.equals("session")) { 
    316             if (currentSequence != null && !currentSequence.isEmpty()) { 
    317                 sequences.add(currentSequence); 
    318             } 
    319             currentSequence = null; 
    320         } 
    321         else if (qName.equals("component") && currentGUIElementPath != null) { 
    322             HTMLGUIElementSpec guiElementSpec = 
    323                 getGUIElementSpec(currentGUIElementClass, currentGUIElementParameters); 
    324             currentGUIElementTree.add(currentGUIElementPath, currentParentPath, guiElementSpec); 
    325  
    326             currentParentPath = null; 
    327             currentGUIElementPath = null; 
    328             currentGUIElementParameters = null; 
    329         } 
    330         else if (qName.equals("event")) { 
    331             IGUIElement currentGUIElement; 
    332             currentGUIElement = currentGUIElementTree.find(currentEventSource); 
    333  
    334             IEventType eventType = 
    335                 HTMLEventTypeFactory.getInstance().getEventType(currentEventType, 
    336                                                                 currentEventParameters, 
    337                                                                 currentGUIElement); 
    338             Event event = 
    339                 new Event(eventType, (currentGUIElement == null ? lastGUIElement 
    340                     : currentGUIElement)); 
    341  
    342             event.setTimestamp(currentEventTimestamp); 
    343             HTMLGUIElement currentEventTarget = (HTMLGUIElement) event.getTarget(); 
    344             currentEventTarget.markUsed(); 
    345             currentSequence.add(event); 
    346  
    347             currentEventSource = null; 
    348             currentEventTimestamp = -1l; 
    349             currentEventParameters = null; 
    350             currentEventType = null; 
    351  
    352             if (currentGUIElement != null) { 
    353                 lastGUIElement = currentGUIElement; 
    354             } 
    355  
    356             currentGUIElement = null; 
    357         } 
    358     } 
    359  
    360     /** 
    361      * <p> 
    362      * Returns a collection of event sequences that was obtained from parsing log files. 
    363      * </p> 
    364      *  
     271     * 
     272     * @param tagName 
    365273     * @return 
    366274     */ 
    367     public Collection<List<Event>> getSequences() { 
    368         return sequences; 
    369     } 
    370  
    371     /** 
    372      * <p> 
    373      * Returns the GUI model that is obtained from parsing log files. 
    374      * </p> 
    375      *  
    376      * @return GUIModel 
    377      */ 
    378     public GUIModel getGuiModel() { 
    379         return currentGUIElementTree.getGUIModel(); 
    380     } 
    381  
    382     /** 
    383      * Returns the HTMLGUIElementSpecification for a GUI Element described 
    384      * by its class name and its parameters. 
    385      * @param guiElementClass 
    386      * @param guiElementParameters 
    387      * @return 
    388      */ 
    389     private HTMLGUIElementSpec getGUIElementSpec(String guiElementClass, 
    390                                                  Map<String, String> guiElementParameters) 
    391     { 
    392         HTMLGUIElementSpec specification = null; 
    393         if ("server".equals(guiElementClass)) { 
    394             // TODO: add correct port handling 
    395             specification = new HTMLServerSpec(guiElementParameters.get("htmlId"), 0); 
    396             currentServerSpec = (HTMLServerSpec) specification; 
    397         } 
    398  
    399         else { 
    400             String id = guiElementParameters.get("htmlId"); 
    401             if (id == null) { 
    402                 HTMLPageElementSpec parentSpec = 
    403                     (HTMLPageElementSpec) currentGUIElementTree.find(currentParentPath) 
    404                         .getSpecification(); 
    405                 id = parentSpec.getPage().getPagePath(); 
    406             } 
    407  
    408             int index = -1; 
    409             String indexStr = guiElementParameters.get("index"); 
    410  
    411             if ((indexStr != null) && (!"".equals(indexStr))) { 
    412                 index = Integer.parseInt(indexStr); 
    413             } 
    414             String title = guiElementParameters.get("title"); 
    415             HTMLPageSpec page = new HTMLPageSpec(currentServerSpec, id, title); 
    416             specification = new HTMLPageElementSpec(page, guiElementClass, id, index); 
    417         } 
    418  
    419         return specification; 
    420     } 
     275    private boolean tagNameMustBeConsidered(String tagName) { 
     276        return 
     277            !"head".equals(tagName) && !"title".equals(tagName) && !"script".equals(tagName) && 
     278            !"style".equals(tagName) && !"link".equals(tagName) && !"meta".equals(tagName) && 
     279            !"iframe".equals(tagName) && !"input_hidden".equals(tagName) && 
     280            !"option".equals(tagName) && !"tt".equals(tagName) && !"br".equals(tagName) && 
     281            !"colgroup".equals(tagName) && !"col".equals(tagName); 
     282 
     283    } 
     284 
    421285} 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/eventcore/HTMLEventTypeFactory.java

    r1059 r1069  
    2323import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction; 
    2424import de.ugoe.cs.autoquest.eventcore.gui.MouseClick; 
     25import de.ugoe.cs.autoquest.eventcore.gui.MouseDoubleClick; 
    2526import de.ugoe.cs.autoquest.eventcore.gui.Scroll; 
    2627import de.ugoe.cs.autoquest.eventcore.gui.TextInput; 
     
    7677 
    7778        if ("onscroll".equals(eventName)) { 
    78             int[] coordinates = getCoordinateParameter(eventName, eventParameters); 
     79            int[] coordinates = 
     80                getCoordinateParameter("scrollX", "scrollY", eventName, eventParameters); 
     81             
    7982            result = new Scroll(coordinates[0], coordinates[1]); 
    8083        } 
    8184        else if ("onclick".equals(eventName)) { 
    82             int[] coordinates = getCoordinateParameter(eventName, eventParameters); 
     85            int[] coordinates = getCoordinateParameter("X", "Y", eventName, eventParameters); 
    8386            result = 
    8487                new MouseClick(MouseButtonInteraction.Button.LEFT, coordinates[0], coordinates[1]); 
     88        } 
     89        else if ("ondblclick".equals(eventName)) { 
     90            int[] coordinates = getCoordinateParameter("X", "Y", eventName, eventParameters); 
     91            result = new MouseDoubleClick 
     92                (MouseButtonInteraction.Button.LEFT, coordinates[0], coordinates[1]); 
    8593        } 
    8694        else if ("onchange".equals(eventName)) { 
     
    118126     * @return 
    119127     */ 
    120     private int[] getCoordinateParameter(String eventName, Map<String, String> eventParameters) { 
    121         String xCoord = eventParameters.get("X"); 
     128    private int[] getCoordinateParameter(String              xParamName, 
     129                                         String              yParamName, 
     130                                         String              eventName, 
     131                                         Map<String, String> eventParameters) 
     132    { 
     133        String xCoord = eventParameters.get(xParamName); 
    122134        if (xCoord == null) { 
    123             throw new IllegalArgumentException("eventParameters do not contain X coordinate."); 
     135            throw new IllegalArgumentException 
     136                ("eventParameters do not contain " + xParamName + " coordinate."); 
    124137        } 
    125138 
    126         String yCoord = eventParameters.get("Y"); 
     139        String yCoord = eventParameters.get(yParamName); 
    127140        if (yCoord == null) { 
    128             throw new IllegalArgumentException("eventParameters do not contain Y coordinate."); 
     141            throw new IllegalArgumentException 
     142                ("eventParameters do not contain " + yParamName + " coordinate."); 
    129143        } 
    130144 
     
    134148        } 
    135149        catch (NumberFormatException e) { 
    136             throw new IllegalArgumentException("the coordinates provided" + " of an " + eventName + 
     150            throw new IllegalArgumentException("the coordinates provided by an " + eventName + 
    137151                " event are no numbers"); 
    138152        } 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLDocument.java

    r1047 r1069  
    2424 * @author Patrick Harms 
    2525 */ 
    26 public class HTMLPage extends HTMLGUIElement implements IDialog { 
     26public class HTMLDocument extends HTMLGUIElement implements IDialog { 
    2727 
    2828    /**  */ 
     
    3737     * @param parent 
    3838     */ 
    39     public HTMLPage(HTMLPageSpec specification, HTMLServer parent) { 
     39    public HTMLDocument(HTMLDocumentSpec specification, HTMLServer parent) { 
    4040        super(specification, parent); 
    4141    } 
     
    4848    @Override 
    4949    public String toString() { 
    50         return "Page(" + getPagePath() + ", \"" + getPageTitle() + "\")"; 
     50        return "Document(" + getPath() + ", \"" + getTitle() + "\")"; 
    5151    } 
    5252 
     
    5858    @Override 
    5959    protected String getElementDescriptor() { 
    60         return "Page"; 
     60        return "Document"; 
    6161    } 
    6262 
     
    6969     */ 
    7070    HTMLServerSpec getServer() { 
    71         return ((HTMLPageSpec) super.getSpecification()).getServer(); 
     71        return ((HTMLDocumentSpec) super.getSpecification()).getServer(); 
    7272    } 
    7373 
     
    7979     * @return 
    8080     */ 
    81     String getPagePath() { 
    82         return ((HTMLPageSpec) super.getSpecification()).getPagePath(); 
     81    String getPath() { 
     82        return ((HTMLDocumentSpec) super.getSpecification()).getPath(); 
    8383    } 
    8484 
     
    9090     * @return 
    9191     */ 
    92     String getPageTitle() { 
    93         return ((HTMLPageSpec) super.getSpecification()).getPageTitle(); 
     92    String getTitle() { 
     93        return ((HTMLDocumentSpec) super.getSpecification()).getTitle(); 
    9494    } 
    9595 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLDocumentSpec.java

    r1047 r1069  
    1515package de.ugoe.cs.autoquest.plugin.html.guimodel; 
    1616 
    17 import java.net.URL; 
    18  
    1917import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec; 
    2018 
     
    2624 * @author Patrick Harms 
    2725 */ 
    28 public class HTMLPageSpec extends HTMLGUIElementSpec implements IGUIElementSpec { 
     26public class HTMLDocumentSpec extends HTMLGUIElementSpec implements IGUIElementSpec { 
    2927 
    3028    /**  */ 
     
    3533     
    3634    /** */ 
    37     private String pagePath; 
     35    private String path; 
    3836     
    3937    /** */ 
    40     private String pageTitle; 
     38    private String query; 
     39     
     40    /** */ 
     41    private String title; 
    4142     
    4243    /** 
     
    4950     * @param pageTitle 
    5051     */ 
    51     public HTMLPageSpec(HTMLServerSpec server, String pagePath, String pageTitle) { 
    52         super("page"); 
     52    public HTMLDocumentSpec(HTMLServerSpec server, String path, String query, String title) { 
     53        super("document"); 
    5354         
    5455        if (server == null) { 
    5556            throw new IllegalArgumentException("server must not be null"); 
    5657        } 
    57         else if (pagePath == null) { 
     58        else if (path == null) { 
    5859            throw new IllegalArgumentException("pagePath must not be null"); 
    59         } 
    60         else if (pageTitle == null) { 
    61             throw new IllegalArgumentException("pageTitle must not be null"); 
    6260        } 
    6361         
    6462        this.server = server; 
    65         this.pagePath = pagePath; 
    66         this.pageTitle = pageTitle; 
    67     } 
    68  
    69     /** 
    70      * <p> 
    71      * TODO: comment 
    72      * </p> 
    73      * 
    74      * @param server 
    75      * @param pagePath 
    76      * @param pageTitle 
    77      */ 
    78     public HTMLPageSpec(URL pageURL, String pageTitle) { 
    79         super("page"); 
    80          
    81         if (pageURL == null) { 
    82             throw new IllegalArgumentException("pageURL must not be null"); 
    83         } 
    84         else if (pageTitle == null) { 
    85             throw new IllegalArgumentException("pageTitle must not be null"); 
    86         } 
    87          
    88         this.server = new HTMLServerSpec(pageURL); 
    89         this.pagePath = pageURL.getPath(); 
    90         this.pageTitle = pageTitle; 
     63        this.path = path; 
     64        this.query = query; 
     65        this.title = title; 
    9166    } 
    9267 
     
    9671    @Override 
    9772    public boolean getSimilarity(IGUIElementSpec other) { 
    98         if (other instanceof HTMLPageSpec) { 
    99             HTMLPageSpec otherSpec = (HTMLPageSpec) other; 
     73        if (other instanceof HTMLDocumentSpec) { 
     74            HTMLDocumentSpec otherSpec = (HTMLDocumentSpec) other; 
    10075             
    10176            if (!super.getSimilarity(otherSpec)) { 
     
    10580                return false; 
    10681            } 
    107             else if (!pagePath.equals(otherSpec.pagePath)) { 
     82            else if (!path.equals(otherSpec.path)) { 
     83                return false; 
     84            } 
     85            else if (query != null ? !query.equals(otherSpec.query) : otherSpec.query != null) { 
    10886                return false; 
    10987            } 
    11088            else { 
    111                 return pageTitle.equals(otherSpec.pageTitle); 
     89                return (title != null ? title.equals(otherSpec.title) : otherSpec.title == null); 
    11290            } 
    11391        } 
     
    134112     * @return 
    135113     */ 
    136     String getPagePath() { 
    137         return pagePath; 
     114    String getPath() { 
     115        return path; 
    138116    } 
    139117 
     
    145123     * @return 
    146124     */ 
    147     String getPageTitle() { 
    148         return pageTitle; 
     125    String getQuery() { 
     126        return query; 
     127    } 
     128 
     129    /** 
     130     * <p> 
     131     * TODO: comment 
     132     * </p> 
     133     * 
     134     * @return 
     135     */ 
     136    String getTitle() { 
     137        return title; 
    149138    } 
    150139 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLPageElement.java

    r989 r1069  
    4747     * @param parent 
    4848     */ 
    49     public HTMLPageElement(HTMLPageElementSpec specification, HTMLPage parent) { 
     49    public HTMLPageElement(HTMLPageElementSpec specification, HTMLDocument parent) { 
    5050        super(specification, parent); 
    5151    } 
     
    5858    @Override 
    5959    public String toString() { 
    60         String str = getTag(); 
     60        String str = getTagName(); 
    6161         
    62         if ((getTagId() != null) && (!"".equals(getTagId()))) { 
    63             str += "(id=\"" + getTagId() + "\")"; 
     62        if ((getHtmlId() != null) && (!"".equals(getHtmlId()))) { 
     63            str += "(id=\"" + getHtmlId() + "\")"; 
    6464        } 
    6565        else { 
    66             str += "[" + getTagIndex() + "]"; 
     66            str += "[" + getIndex() + "]"; 
    6767        } 
    6868         
     
    7777    @Override 
    7878    protected String getElementDescriptor() { 
    79         return getTag(); 
     79        return getTagName(); 
    8080    } 
    8181 
     
    8787     * @return 
    8888     */ 
    89     HTMLPageSpec getPage() { 
     89    HTMLDocumentSpec getPage() { 
    9090        return ((HTMLPageElementSpec) super.getSpecification()).getPage(); 
    9191    } 
     
    9898     * @return 
    9999     */ 
    100     String getTag() { 
    101         return ((HTMLPageElementSpec) super.getSpecification()).getTag(); 
     100    String getTagName() { 
     101        return ((HTMLPageElementSpec) super.getSpecification()).getTagName(); 
    102102    } 
    103103 
     
    109109     * @return 
    110110     */ 
    111     String getTagId() { 
    112         return ((HTMLPageElementSpec) super.getSpecification()).getTagId(); 
     111    String getHtmlId() { 
     112        return ((HTMLPageElementSpec) super.getSpecification()).getHtmlId(); 
    113113    } 
    114114 
     
    120120     * @return 
    121121     */ 
    122     int getTagIndex() { 
    123         return ((HTMLPageElementSpec) super.getSpecification()).getTagIndex(); 
     122    int getIndex() { 
     123        return ((HTMLPageElementSpec) super.getSpecification()).getIndex(); 
    124124    } 
    125125 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLPageElementSpec.java

    r1059 r1069  
    3030     
    3131    /** */ 
    32     private HTMLPageSpec page; 
     32    private HTMLDocumentSpec page; 
    3333     
    3434    /** */ 
    35     private String tag; 
     35    private String tagName; 
    3636     
    3737    /** */ 
    38     private String id; 
     38    private String htmlId; 
    3939     
    4040    /** */ 
     
    5050     * @param id 
    5151     */ 
    52     public HTMLPageElementSpec(HTMLPageSpec page, String tag, String id, int index) { 
    53         super(tag); 
     52    public HTMLPageElementSpec(HTMLDocumentSpec page, String tagName, String htmlId, int index) { 
     53        super(tagName); 
    5454         
    5555        if (page == null) { 
    5656            throw new IllegalArgumentException("page must not be null"); 
    5757        } 
    58         else if (tag == null) { 
     58        else if (tagName == null) { 
    5959            throw new IllegalArgumentException("tag must not be null"); 
    6060        } 
    61         else if ((id == null) && (index < 0)) { 
     61        else if ((htmlId == null) && (index < 0)) { 
    6262            throw new IllegalArgumentException 
    6363                ("either id must not be null or the index must be greater or equal to 0"); 
     
    6565         
    6666        this.page = page; 
    67         this.tag = tag; 
    68         this.id = id; 
     67        this.tagName = tagName; 
     68        this.htmlId = htmlId; 
    6969        this.index = index; 
    7070    } 
     
    8484                return false; 
    8585            } 
    86             else if (!tag.equals(otherSpec.tag)) { 
     86            else if (!tagName.equals(otherSpec.tagName)) { 
    8787                return false; 
    8888            } 
    8989             
    90             if (id != null) { 
    91                 return id.equals(otherSpec.id); 
     90            if (htmlId != null) { 
     91                return htmlId.equals(otherSpec.htmlId); 
    9292            } 
    9393            else if (index >= 0) { 
     
    106106     * @return 
    107107     */ 
    108     public HTMLPageSpec getPage() { 
     108    HTMLDocumentSpec getPage() { 
    109109        return page; 
    110110    } 
     
    117117     * @return 
    118118     */ 
    119     String getTag() { 
    120         return tag; 
     119    String getTagName() { 
     120        return tagName; 
    121121    } 
    122122 
     
    128128     * @return 
    129129     */ 
    130     String getTagId() { 
    131         return id; 
     130    String getHtmlId() { 
     131        return htmlId; 
    132132    } 
    133133 
     
    139139     * @return 
    140140     */ 
    141     int getTagIndex() { 
     141    int getIndex() { 
    142142        return index; 
    143143    } 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLServerSpec.java

    r1059 r1069  
    1414 
    1515package de.ugoe.cs.autoquest.plugin.html.guimodel; 
    16  
    17 import java.net.URL; 
    1816 
    1917import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec; 
     
    5856        this.host = host; 
    5957        this.port = port; 
    60     } 
    61  
    62     /** 
    63      * <p> 
    64      * TODO: comment 
    65      * </p> 
    66      * 
    67      * @param pageURL 
    68      */ 
    69     public HTMLServerSpec(URL pageURL) { 
    70         super("server"); 
    71  
    72         if (pageURL == null) { 
    73             throw new IllegalArgumentException("page URL must not be null"); 
    74         } 
    75  
    76         this.host = pageURL.getHost(); 
    77         this.port = pageURL.getPort(); 
    7858    } 
    7959 
Note: See TracChangeset for help on using the changeset viewer.