Tuesday, 13 March 2012

TestNG XSLT Report Generation

Reports are vital part of any automation testing and with Selenium+TestNG framework we have the default TestNG reports, which some consider to be a little out of date... to over come this, we have a add on report for TestNG know as TestNG-XSLT which gives good graphical representation of the generated report.

TestNG-xslt generates user friendly reports using the TestNG results output (testng-results.xml). Its uses the pure XSL for report generation and Saxon as an XSL2.0 implementation.


For generating testng-xslt report for your project do the following:
1. Download the testng-xslt from

     http://code.google.com/p/testng-xslt/
2. Unzip and copy the testng-results.xsl from the testng-xslt folder(testng-xslt-1.1\src\main\resources) to your own project folder.
3. Now copy the saxon library from (testng-xslt-1.1\lib\saxon-8.7.jar)to your project lib folder.
4. Modify your build.xml of ant and add the following target to it.


<project name="test" basedir=".">
    <property name="LIB" value="${basedir}/libs" />
    <property name="BIN" value="${basedir}/bin" />
    <path id="master-classpath">
            <pathelement location="${BIN}" />
            <fileset dir="${LIB}">
                <include name="**/*.jar" />
            </fileset>
        </path>
    <target name="testng-xslt-report">
        <delete dir="${basedir}/testng-xslt">
        </delete>
        <mkdir dir="${basedir}/testng-xslt">
        </mkdir>
        <xslt in="${basedir}/test-output/testng-results.xml" style="${basedir}/testng-results.xsl" out="${basedir}/testng-xslt/index.html">
            <param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir" />

            <param expression="true" name="testNgXslt.sortTestCaseLinks" />

            <param expression="FAIL,SKIP,PASS,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter" />

            <param expression="true" name="testNgXslt.showRuntimeTotals" />

            <classpath refid="master-classpath">
            </classpath>
        </xslt>
    </target>
</project>

You need to provide the testng-xslt stylesheet the TestNG results xml(testng-results.xml) , the path to the style sheet testng-results.xsl and the output index.html path.

Also dont forget to add the saxon library to your target classpath else you will get an error. In my case it is the master-classpath.

Now run the ant target for report generation (in this case "testng-xslt-report
") and check the ouput folder configured by you for testng-xslt report.


35 comments:

  1. hai, can u tell me what are all the settings needs to be made in made in POM.xml while creating the testNG xslt report using maven alone.

    ReplyDelete
    Replies
    1. hi Janardhana,

      Can you please post your pom.xml here. I shall review it and try to help you..

      Delete
    2. This comment has been removed by the author.

      Delete
  2. HI NX, i m not able to post my entire POM.xml in ur site .its getting badly restructured after i posting it....

    ReplyDelete
  3. i shall get back to you... dont worry, we can over come the issue you are facing.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. here is the snippet of POM.xml. If i execute it only the sure fire report is created but not the testng-xslt report and also i dont know where exactly i sud put testng-xslt file. right now i put it in directory where POM.xml resides.




    org.testng.xslt
    testng-xslt-plugin
    1.1


    Maven-TestNG-Demo-1/target/site/


    true

    ReplyDelete
  6. Hello everybody, I need help, getting src\testng-results.xsl:690: Fatal Error! Failed to create output file file://///Suite.html Cause: java.io.IOException: The specified path is invalid

    ReplyDelete
    Replies
    1. Hi Maksim,

      when are you getting this error message? are you trying to run the scripts using suit xml or the build xml? please give more details, so that we can help you.

      Delete
    2. This error happen if we for get to mentioned param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir" this is mandatory and must be an absolute path.This is mandatory and must be an absolute path.

      For more details go this links: http://startingwithseleniumwebdriver.blogspot.in/2014/03/some-error-and-solution-for-testng-xslt.html

      Delete
  7. Ni NX,
    thanks a lot for response,
    I am running the build.xml I have changed the

    to my ...xsltRepors/output/Suite.html path and it does not throw an error I did the same for
    -overview.html
    -reporterOutput.html
    -navigation.html
    -style.css
    -main.js
    -overview-chart.svg

    and it saves all these files in ...xsltReports\output directory
    the second obstacle that I am getting: I do not see "Suite Name".html, "Groups".html, "Test Name".html also Reporter output page is blank.
    Any idea what I am doing wrong? Could you please help me?Thanks!

    ReplyDelete
    Replies
    1. Changed the absolute path of Suite.html and others to myProjectPath/xsltReports/output dir

      Delete
  8. xsl:result-document href="{testng:absolutePath('Suite.html')}" method="xhtml

    ReplyDelete
  9. Played with absolutePath, and now all looks good except Reporter Output, as I mentioned before it displays blank page

    ReplyDelete
  10. Can you please attach a screen shot of your framework pointing out the position of your Reporter out in the framework?

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. This comment has been removed by a blog administrator.

    ReplyDelete
  13. Hai i need Hybrid Driven frame work java code, its urgent and i need code how to crearte our own reports with Screen shots while error and how to mail our reports through our code. am struch in these areas, but now i need to do this very quickly. pls help me reg this. and one more thing is that i have excel read code and keywords.xls and data.xls but while ececuting am getting these error, and not able to proceed. pls help me reg this urgently pls. Here am posting the error also.

    Exception in thread "main" java.lang.RuntimeException: There are no support for this type of cell
    at WebdriverAutomation.firstautomation.cellToString(firstautomation.java:197)
    at WebdriverAutomation.firstautomation.excelRead(firstautomation.java:167)
    at WebdriverAutomation.firstautomation.main(firstautomation.java:33)

    ReplyDelete
  14. iam having excelRead()function with in the same class and am assign it to a 2 dimentional array called steps of type String[][]. like String[][] steps = excelRead(); here am getting error.

    ReplyDelete
    Replies
    1. Hi Gouri,
      Please give me some time, i am a little busy with my work now, will have a look at your issue by evening and get back.
      Thanks for the reading my blog.

      Delete
  15. Pls help me reg this issue am in very urgency, pls any one can help me pls

    ReplyDelete
  16. unable to access http://code.google.com/p/testng-xslt/ giving below error:

    403. That’s an error.

    Your client does not have permission to get URL /p/testng-xslt/ from this server. That’s all we know.

    ReplyDelete
  17. Hi , I am getting this error and following is the my code:

    411: Fatal Error! Failed to create output file file://///style.css Cause: java.io.IOException: The filename, directory name, or volume label syntax is incorrect..

    ReplyDelete
    Replies
    1. This error happen if we for get to mentioned param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir" this is mandatory and must be an absolute path.This is mandatory and must be an absolute path.

      For more details you can go this links http://startingwithseleniumwebdriver.blogspot.in/2014/03/some-error-and-solution-for-testng-xslt.html

      Delete
  18. hi..i am writing script in apache ant and my output is in the form of a text.. how can i convert it into xml and then modify the report using testng xslt..

    ReplyDelete
  19. Im trying to include xslt reports in my Testng framework with ant. When I try to execute the the MakeReport target in build.xml I get some error related to classpath saying Reference test.classpath not found for SaxonLiaison

    I have not gone with your method, because I Dont want to copy the SaxonLiaison Jar files to my project.

    Please help on how to solve this issue. i tried everything.

    ReplyDelete
  20. Can you please tell me which folder are you referencing to when you say "your project lib folder." I dont find any project lib folder to copy saxonLiaision

    ReplyDelete
  21. Can you post the exact error message that you are getting?

    ReplyDelete
  22. Hi.. I have created xslt reports using ant and build.xml
    However the reporter output is not clear. All the logs from different tests are logged continuously. Is there any way of sepearting it for different @Test.
    Also how to generate screen shots for failed testcases?

    ReplyDelete
  23. Can u please tell me how to add screenshots in detail(like folders we have to create and all those things )please help me out.

    Thanks in advance

    ReplyDelete
  24. Am using selenium webdriver (ANT+TestNG+Java).How do I save results of TestNG with time-stamp and build no.(testng-results-Build no:DD-MM-YYYY_HH-MM-SS.xml),without overwriting previous results. Could anyone share the build.xml code?

    ReplyDelete
  25. Hi NX,

    Can u plz tell me how to integrate POM.xml with testNG-xslt fro xslt reports

    ReplyDelete
    Replies
    1. hey Vishvajeet did you figure out how to integrate maven and xslt please update if you know how todo.

      Delete