Odin Technology - Automated Software Testing

Axe Test Automation Platform

General discussion relating to the Axe Test Automation Platform from Odin Technology

Posts by Odin employees marked:

Capture HTML source on failure

Hi

Using: AXE v3.1/ Selenium (Java)

I'd like to capture the HTML Source on test abort in addition to the screenshot.

Selenium has the method selenium.getHtmlSource() however following the call to "Test Abort" in the Selenium Java Action Map, I use the code:

selenium.captureEntirePageScreenshot("%^RESULTDIR%/images/%TESTID%_Abort.jpg", "");

Is there a way to link to the HTML source also from within the results file?

Thanks

Mark

Tuesday, August 30, 2011
 
 
nb - code used:

String browser = selenium.getEval("navigator.userAgent");
                if (browser.contains("Firefox") || browser.contains("MSIE"))
                {
                            selenium.captureEntirePageScreenshot("%^RESULTDIR%/images/%TESTID%_Abort.jpg", "");
                }
                String pageSource = selenium.getHtmlSource();
                File file = new File("%^RESULTDIR%/images/%TESTID%_Source.html");
                Writer writer = null;
                try{
                  writer = new OutputStreamWriter(new FileOutputStream(file),"UTF-8");
                  writer.write(pageSource);
                  writer.flush();
                } catch (UnsupportedEncodingException e) {
                throw new RuntimeException(e);
    } catch (IOException e) {
                throw new RuntimeException(e);
    }finally{
                    if(writer!=null){
                      try{
                      writer.close();
                      }catch(IOException e){
                      }
                    }
                }

Tuesday, August 30, 2011
 
 
Code updated to also capture the URL being accessed at point of abort:

File file = new File("%^RESULTDIR%/images/%TESTID%_Source.html");
                Writer writer = null;
                try{
                  writer = new OutputStreamWriter(new FileOutputStream(file),"UTF-8");
                  writer.write(selenium.getLocation()+"\r\n");
                  writer.write(selenium.getHtmlSource());
                  writer.flush();
                  } catch (UnsupportedEncodingException e) {
                      throw new RuntimeException(e);
                } catch (IOException e) {
                  throw new RuntimeException(e);
                }finally{
                    if(writer!=null){
                      try{
                      writer.close();
                      }catch(IOException e){
                      }
                    }
                }
Mark Winspear Send private email
Tuesday, August 30, 2011
 
 
Hi Mark,

Many thanks for sharing this code sample on the Axe forum.

Regarding linking this in to the Axe results; I am afraid that there is no specific feature in Axe to provide this level of customisation. However, if you dont mind getting your hands dirty with some xslt you could achieve it. I would suggest that you use the StepInfo method in the Axe api to write out some kind of custom tag or message to the Axe results file. Then modify the results.xslt template to search for it and provide an appropriate link for the Axe web results.

Sam
Sam Warwick Send private email
Wednesday, August 31, 2011
 
 
Thanks Sam - I think this is beyond me unfortunately.

Is this something you would consider adding to a future version of AXE?  perhaps you could set options in the config files to capture the source and URL?

Incidentally, looking at my code, is there an easy way to return the URL in addition to any other error code AXE returns in the results html file?
Mark Winspear Send private email
Wednesday, August 31, 2011
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics