Changeset 1059


Ignore:
Timestamp:
02/05/13 14:17:26 (11 years ago)
Author:
fglaser
Message:
  • Further works on NewHTMLLogParser to parse testtrace without errors
  • Test for NewHTMLLogParser added
  • dummy mapping for html added that contains unmapped elements
Location:
trunk
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/NewHTMLLogParser.java

    r1051 r1059  
    3838 
    3939import de.ugoe.cs.autoquest.eventcore.Event; 
     40import de.ugoe.cs.autoquest.eventcore.IEventType; 
    4041import de.ugoe.cs.autoquest.eventcore.guimodel.GUIElementTree; 
    4142import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel; 
     
    4445import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLGUIElement; 
    4546import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLGUIElementSpec; 
     47import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPageElementSpec; 
     48import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPageSpec; 
     49import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLServerSpec; 
    4650import de.ugoe.cs.util.console.Console; 
    4751 
     
    7276     */ 
    7377    private Collection<List<Event>> sequences; 
    74      
     78 
    7579    /** 
    7680     * <p> 
     
    7983     */ 
    8084    private GUIElementTree<String> currentGUIElementTree; 
    81      
     85 
    8286    /** 
    8387     * <p> 
     
    8690     */ 
    8791    private String currentGUIElementPath; 
    88      
     92 
    8993    /** 
    9094     * <p> 
     
    9397     */ 
    9498    private String currentParentPath; 
    95      
     99 
    96100    /** 
    97101     * <p> 
     
    100104     */ 
    101105    private String currentEventSource; 
    102      
     106 
    103107    /** 
    104108     * <p> 
     
    107111     */ 
    108112    private Long currentEventTimestamp; 
    109      
     113 
    110114    /** 
    111115     * <p> 
     
    114118     */ 
    115119    private Map<String, String> currentEventParameters; 
    116      
     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; 
    117127    /** 
    118128     * <p> 
     
    121131     */ 
    122132    private List<Event> currentSequence; 
    123      
     133 
    124134    /** 
    125135     * <p> 
     
    128138     */ 
    129139    private String currentEventType; 
    130      
     140 
    131141    /** 
    132142     * <p> 
     
    135145     */ 
    136146    private String currentGUIElementClass; 
    137      
     147 
    138148    /** 
    139149     * <p> 
     
    142152     */ 
    143153    private String currentGUIElementIndex; 
    144      
    145     /** 
    146      * Internal handle to the specification of the GUI element currently being parsed. 
    147      */ 
    148     private HTMLGUIElementSpec currentGUIElementSpec; 
    149      
     154 
    150155    /** 
    151156     * <p> 
     
    155160     */ 
    156161    private IGUIElement lastGUIElement; 
    157      
     162 
     163    /** 
     164     * <p> 
     165     * internal handle to the server specification currently being used. 
     166     * </p> 
     167     */ 
     168    private HTMLServerSpec currentServerSpec; 
     169 
    158170    /** 
    159171     * <p> 
     
    162174     *  
    163175     * @param filename 
    164      *          name and path of the log file 
     176     *            name and path of the log file 
    165177     */ 
    166178    public void parseFile(String filename) { 
    167         if (filename == null){ 
     179        if (filename == null) { 
    168180            throw new IllegalArgumentException("filename must not be null"); 
    169181        } 
    170          
     182 
    171183        parseFile(new File(filename)); 
    172184    } 
     185 
    173186    /** 
    174187     * <p> 
    175188     * Parses a log file written by the HTMLMonitor and creates a collection of event sequences. 
    176189     * </p> 
     190     *  
    177191     * @param file 
    178      *          file to be parsed 
     192     *            file to be parsed 
    179193     */ 
    180194    public void parseFile(File file) { 
    181         if (file == null){ 
     195        if (file == null) { 
    182196            throw new IllegalArgumentException("file must not be null"); 
    183197        } 
     
    186200        SAXParser saxParser = null; 
    187201        InputSource inputSource = null; 
    188         try{ 
     202        try { 
    189203            saxParser = spf.newSAXParser(); 
    190204            inputSource = 
    191                     new InputSource(new InputStreamReader(new FileInputStream(file), "UTF-8")); 
    192         } 
    193         catch (UnsupportedEncodingException e){ 
     205                new InputSource(new InputStreamReader(new FileInputStream(file), "UTF-8")); 
     206        } 
     207        catch (UnsupportedEncodingException e) { 
    194208            Console.printerr("Error parsing file " + file.getName()); 
    195209            Console.logException(e); 
    196210            return; 
    197211        } 
    198         catch (ParserConfigurationException e){ 
     212        catch (ParserConfigurationException e) { 
    199213            Console.printerr("Error parsing file " + file.getName()); 
    200214            Console.logException(e); 
    201215            return; 
    202216        } 
    203         catch (SAXException e){ 
     217        catch (SAXException e) { 
    204218            Console.printerr("Error parsing file " + file.getName()); 
    205219            Console.logException(e); 
    206220        } 
    207         catch (FileNotFoundException e){ 
     221        catch (FileNotFoundException e) { 
    208222            Console.printerr("Error parsing file " + file.getName()); 
    209223            Console.logException(e); 
    210224        } 
    211         if (inputSource != null){ 
    212            inputSource.setSystemId("file://" + file.getAbsolutePath()); 
    213            try{ 
    214                if (saxParser == null){ 
    215                    throw new RuntimeException("SaxParser creation failed"); 
    216                } 
    217                saxParser.parse(inputSource, this); 
    218            } 
    219            catch (SAXParseException e){ 
    220                Console.printerrln("Failure parsing file in line " + e.getLineNumber() + 
    221                                   ", column " + e.getColumnNumber() + "."); 
    222                Console.logException(e); 
    223            } 
    224            catch (SAXException e){ 
    225                Console.printerr("Error parsing file " + file.getName()); 
    226                Console.logException(e); 
    227                return; 
    228            } 
    229            catch (IOException e){ 
    230                Console.printerr("Error parsing file " + file.getName()); 
    231                Console.logException(e); 
    232                return; 
    233            } 
    234         }   
    235     } 
    236  
    237     /* (non-Javadoc) 
    238      * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) 
     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) 
    239256     */ 
    240257    @Override 
     
    243260    { 
    244261        if (qName.equals("session")) { 
    245              currentSequence = new LinkedList<Event>(); 
    246              if (currentGUIElementTree == null) 
    247                      currentGUIElementTree = new GUIElementTree<String>(); 
     262            currentSequence = new LinkedList<Event>(); 
     263            if (currentGUIElementTree == null) 
     264                currentGUIElementTree = new GUIElementTree<String>(); 
    248265        } 
    249266        else if (qName.equals("component")) { 
    250267            currentGUIElementPath = atts.getValue("path"); 
     268            currentGUIElementParameters = new HashMap<String, String>(); 
    251269        } 
    252270        else if (qName.equals("event")) { 
     
    254272            currentEventParameters = new HashMap<String, String>(); 
    255273        } 
    256         else if (qName.equals("param")){ 
     274        else if (qName.equals("param")) { 
    257275            String paramName = atts.getValue("name"); 
    258             if (currentGUIElementPath != null){ 
    259                 if ("parent".equals(paramName)){ 
     276            if (currentGUIElementPath != null) { 
     277                if ("parent".equals(paramName)) { 
    260278                    currentParentPath = atts.getValue("value"); 
    261279                } 
    262                 if ("class".equals(paramName)){ 
     280                if ("class".equals(paramName)) { 
    263281                    currentGUIElementClass = atts.getValue("value"); 
    264282                } 
    265                 if ("index".equals(paramName)){ 
     283                if ("index".equals(paramName)) { 
    266284                    currentGUIElementIndex = atts.getValue("value"); 
    267285                } 
    268             } 
    269             else if (currentEventType != null){ 
    270                 if ("target".equals(paramName)){ 
     286                currentGUIElementParameters.put(paramName, atts.getValue("value")); 
     287            } 
     288            else if (currentEventType != null) { 
     289                if ("target".equals(paramName)) { 
    271290                    currentEventSource = atts.getValue("value"); 
    272291                } 
    273                 if ("timestamp".equals(paramName)){ 
     292                if ("timestamp".equals(paramName)) { 
    274293                    currentEventTimestamp = Long.parseLong(atts.getValue("value")); 
    275294                } 
    276295                currentEventParameters.put(paramName, atts.getValue("value")); 
    277296            } 
    278             else{ 
     297            else { 
    279298                throw new SAXException("param tag found where it should not be."); 
    280299            } 
    281300        } 
    282         else{ 
     301        else { 
    283302            throw new SAXException("unknown tag found: " + qName); 
    284303        } 
     
    286305    } 
    287306 
    288     /* (non-Javadoc) 
    289      * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String) 
     307    /* 
     308     * (non-Javadoc) 
     309     *  
     310     * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, 
     311     * java.lang.String) 
    290312     */ 
    291313    @Override 
    292314    public void endElement(String uri, String localName, String qName) throws SAXException { 
    293315        if (qName.equals("session")) { 
    294             if (currentSequence != null && !currentSequence.isEmpty()){ 
     316            if (currentSequence != null && !currentSequence.isEmpty()) { 
    295317                sequences.add(currentSequence); 
    296318            } 
     
    298320        } 
    299321        else if (qName.equals("component") && currentGUIElementPath != null) { 
    300             HTMLGUIElementSpec guiElementSpec = new HTMLGUIElementSpec(currentGUIElementClass); 
     322            HTMLGUIElementSpec guiElementSpec = 
     323                getGUIElementSpec(currentGUIElementClass, currentGUIElementParameters); 
    301324            currentGUIElementTree.add(currentGUIElementPath, currentParentPath, guiElementSpec); 
    302              
     325 
    303326            currentParentPath = null; 
    304327            currentGUIElementPath = null; 
     328            currentGUIElementParameters = null; 
    305329        } 
    306330        else if (qName.equals("event")) { 
    307331            IGUIElement currentGUIElement; 
    308332            currentGUIElement = currentGUIElementTree.find(currentEventSource); 
    309              
    310             Event event = new Event(HTMLEventTypeFactory. 
    311                                     getInstance().getEventType(currentEventType, currentEventParameters), 
    312                                     (currentGUIElement == null ? lastGUIElement : currentGUIElement)); 
    313              
     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 
    314342            event.setTimestamp(currentEventTimestamp); 
    315343            HTMLGUIElement currentEventTarget = (HTMLGUIElement) event.getTarget(); 
    316344            currentEventTarget.markUsed(); 
    317345            currentSequence.add(event); 
    318              
     346 
    319347            currentEventSource = null; 
    320348            currentEventTimestamp = -1l; 
    321349            currentEventParameters = null; 
    322350            currentEventType = null; 
    323              
    324             if (currentGUIElement != null){ 
     351 
     352            if (currentGUIElement != null) { 
    325353                lastGUIElement = currentGUIElement; 
    326354            } 
    327              
     355 
    328356            currentGUIElement = null; 
    329357        } 
    330358    } 
    331     
     359 
    332360    /** 
    333361     * <p> 
    334362     * Returns a collection of event sequences that was obtained from parsing log files. 
    335363     * </p> 
     364     *  
    336365     * @return 
    337366     */ 
    338     public Collection<List<Event>> getSequences(){ 
     367    public Collection<List<Event>> getSequences() { 
    339368        return sequences; 
    340369    } 
    341      
     370 
    342371    /** 
    343372     * <p> 
     
    347376     * @return GUIModel 
    348377     */ 
    349     public GUIModel getGuiModel(){ 
     378    public GUIModel getGuiModel() { 
    350379        return currentGUIElementTree.getGUIModel(); 
    351380    } 
    352381 
     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    } 
    353421} 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/eventcore/HTMLEventTypeFactory.java

    r1054 r1059  
    2424import de.ugoe.cs.autoquest.eventcore.gui.MouseClick; 
    2525import de.ugoe.cs.autoquest.eventcore.gui.Scroll; 
     26import de.ugoe.cs.autoquest.eventcore.gui.TextInput; 
     27import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; 
     28import de.ugoe.cs.autoquest.eventcore.guimodel.ITextArea; 
     29import de.ugoe.cs.autoquest.eventcore.guimodel.ITextField; 
    2630import de.ugoe.cs.util.console.Console; 
    2731 
     
    3236 *  
    3337 * @author Patrick Harms 
     38 * @author Fabian Glaser 
    3439 */ 
    3540public class HTMLEventTypeFactory { 
     
    6671     * @return 
    6772     */ 
    68     public IEventType getEventType(String eventName, Map<String, String> eventParameters) { 
     73    public IEventType getEventType(String eventName, Map<String, String> eventParameters,  
     74                                   IGUIElement guiElement) { 
    6975        IInteraction result = null; 
    7076 
     
    7985        } 
    8086        else if ("onchange".equals(eventName)) { 
    81             // TODO: Implement "onchange" event handling 
    82             Console.traceln(Level.FINE, "Unhandled event of type \"" + eventName + "\""); 
     87            String value = eventParameters.get("selectedValue"); 
     88             
     89            if ((guiElement instanceof ITextArea) || (guiElement instanceof ITextField)) { 
     90                result = new TextInput(value, null); 
     91            } 
     92            else { 
     93                throw new IllegalArgumentException("can not handle onchange events on GUI " + 
     94                                                   "elements of type " + guiElement.getClass());  
     95            } 
    8396        } 
    8497        else if ("onfocus".equals(eventName)) { 
     
    125138        } 
    126139    } 
     140     
     141     
     142     
    127143} 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLPageElementSpec.java

    r961 r1059  
    106106     * @return 
    107107     */ 
    108     HTMLPageSpec getPage() { 
     108    public HTMLPageSpec getPage() { 
    109109        return page; 
    110110    } 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLPageSpec.java

    r961 r1059  
    5858            throw new IllegalArgumentException("pagePath must not be null"); 
    5959        } 
    60         else if (pageTitle == null) { 
    61             throw new IllegalArgumentException("pageTitle must not be null"); 
    62         } 
     60//        else if (pageTitle == null) { 
     61//            throw new IllegalArgumentException("pageTitle must not be null"); 
     62//        } 
    6363         
    6464        this.server = server; 
     
    134134     * @return 
    135135     */ 
    136     String getPagePath() { 
     136    public String getPagePath() { 
    137137        return pagePath; 
    138138    } 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLServerSpec.java

    r961 r1059  
    4545     * @param port 
    4646     */ 
    47     HTMLServerSpec(String host, int port) { 
     47    public HTMLServerSpec(String host, int port) { 
    4848        super("server"); 
    4949         
     
    6767     * @param pageURL 
    6868     */ 
    69     HTMLServerSpec(URL pageURL) { 
     69    public HTMLServerSpec(URL pageURL) { 
    7070        super("server"); 
    7171 
Note: See TracChangeset for help on using the changeset viewer.