Saturday, May 12, 2012

Generate TestNG-xslt report using Maven

Earlier I had covered in my blog on how to generate a TestNG-xslt report for your TestNG test-case execution using Ant. Following is the link to it:
http://blog.varunin.com/2010/05/generating-selenium-reports-using.html

As many of the recent projects are now using maven as their build tool ,test-cases are also required to integrate itself to the existing build. In this blog I will mention about how to generate a TestNG-xslt report for your TestNG test-case execution using Maven.
Following is the "pom.xml" file for executing TestNG test-cases and to generate a "TestNG-xslt" report for the same:

Run the following command in terminal/command prompt to run your test cases and generate the TestNG-xslt report. The report will be generated under folder named "testng-xslt-report" inside the "target" folder under your build directory.

mvn clean test site org.reportyng:reporty-ng:1.2:reportyng

Note: In case the "test" task of mvn fails the report task of xslt will not be executed. You can apply any of the strategies mentioned in the following url to achieve the same as part of a single execution:

http://stackoverflow.com/questions/4174696/making-maven-run-all-tests-even-when-some-fail

Else 2 different commands have be run for test execution and report generation separately.

To know more about the TestNG-xslt configuration parameters please refer to my earlier blog post:
http://blog.varunin.com/2010/05/generating-selenium-reports-using.html

29 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. thanks .... lot varun.. keep doing this kind work.. its really helped me... but one thing i have noticed here is there were some syntax mistakes in ur POM.xml e.g "groupid" it should be groupId.... once again thank u very much...

    ReplyDelete
    Replies
    1. Thanks Janardhan. The problem is corrected now. Its with the Syntaxhighlighter that I am using to show my code.

      Delete
  3. hi varun, i am facing one problem.. Actually i have created the test-xslt report using maven(3.0.4) by using ur POM.xml in my local system. But if i go for implementing the same thing in remote machine, its not possible to create testng xslt report. Its showing like testng-xslt plugin not found.I am using maven(3.0.3) in my remote machine and i have used same POM.xml which u have provided here... Can u tell me what could be the reason for this ?

    ReplyDelete
    Replies
    1. One possibility that I can think of is the remote machine is unable to download the test-ng-plugin from the repository : http://www.cosminaru.ro/maven/.
      Check that the following section is present in pom.xml


      testng-xslt-plugin
      http://www.cosminaru.ro/maven/



      Another thing that you can do is copying the testng-xslt-plugin from your local maven repo to the remote machine maven repo.

      Delete
    2. Hi, varun thanx for ur reply... same problem is occuring in all of my teammates systems... but in my system every thing is working fine. I have followed ur suggestions even though i am not able not resolve that .. could u think of any thing else ?

      Delete
    3. i think they may have problem in downloading the lib from the remote repo. Try once accessing the repo:
      http://www.cosminaru.ro/maven/

      Delete
    4. where to run this command "mvn clean test site" .

      Delete
    5. under test project where u have created the maven pom.xml

      Delete
  4. Hi, Varun,

    I don't think http://www.cosminaru.ro/maven/ is accessible anymore. Do you know the alternate source URL or can give provide the content that should be in maven repository.

    ReplyDelete
    Replies
    1. Hi Gaurav,

      Did you find any solution for your problem..?

      Delete
    2. Please find the download link for the testngxslt jar below:
      https://docs.google.com/open?id=0B3OQaZlrVrdJRndLZWhrcDBzaFU

      You can use any of the following method mentioned in following links to include it in your classpath:
      http://stackoverflow.com/questions/1164043/maven-how-to-include-jars-which-are-not-available-in-reps-into-a-j2ee-project

      http://www.roseindia.net/answers/viewqa/Maven/11659-including-jar-file-in-maven-pom.xml-.html

      Delete
    3. Heyy Varun, Thanx a lot!!!

      I just located that mvn site is working fine. Generating index.html for testng-xslt.

      Running 'mvn clean test site'
      The problem is that if Test Run is ok (i.e. with no failures, skipped etc) site generates XSLT index.html report but
      if it get fails it does not execute 'site' command

      Not able to make out the problem :(
      pls suggest!!!!

      Regards
      Somesh

      Delete
  5. Hi Varun,

    I am unable to generate XSLT reports for my test run using 'mvn test site' command but the same is generated for 'mvn site' command

    It generates surefire reports, but not XSLT

    Please help

    Somesh

    ReplyDelete
  6. I get the same error as Somesh Bansal

    I generate surefire reports , not XSLT

    ReplyDelete
    Replies
    1. This issue exists with maven itself. If someone can try "mvn test" first and then "mvn site" it may work. I dont have a mvn project in-place , i will try and let you know.

      Delete
    2. To overcome the above mentioned issue there are 2 ways:
      1. Run "mvn test" and "mvn site" as separate tasks.
      2. Configure "mvn test" to not fail the build when a test-case fails. This will generate the testng-xslt report when you run "mvn test site".
      To skip build failure when any test fails add the following line to the configuration section of "maven-surefire-plugin":
      <testFailureIgnore> true </testFailureIgnore>

      Delete
    3. Hi Varun Menon,
      thanks for your quick reply
      I resolve this problem by change maven version to 2.x /xslt version 1.1.2
      but I confused why maven 3.x do not support
      I get info from google group :
      if you're using Maven 3 and you're not getting any site output this
      could be of help for you:
      https://cwiki.apache.org/MAVEN/maven-3x-and-site-plugin.html

      hope this info will help guys who learning testng-xslt-report from your blog

      Delete
    4. @XiangLong Meng: Thanks for the info.

      Delete
  7. Hi Varun,

    Query: Can we add new column to xslt report generated with testNg?

    I have a requirement to email the test reports with severity of testcases failed . Means supposes one testcases is failed during execution and it have high severity then that should also be printed in XSLT reports generated by testNg.(Although I am able to create XSLT reports using following ant:













    Can we achieve this or can we set out customized variable/message in to the reports?
    Or any thoughts on this is really appreciable.


    Thanks
    -Amit

    ReplyDelete
    Replies
    1. You may need to study the testng.xsl file which does the transformation of the report xml to the html report

      Delete
  8. hi ,i am very new to jenkins. I am able to get xslt report , if i run mvn clear test site. But, how can i run same command from jenkins. Please help me

    ReplyDelete
    Replies
    1. Use the maven plugin in Jenkins and run the said command there.
      Or create a new job in jenkins to execute the maven command.

      Delete
  9. Hi Varun,

    Unable to generate testng xslt report using maven.
    1) Does .xsl and .css files required to generate xslt report?if yes where to add
    2) http://uhftopic.com/maven/ and http://www.cosminaru.ro/maven both urls are now outdated.. What is the alternate way to download and link to the project?

    3) Can you please update your pom.xml in the main post.


    Following is my pom.xml


    4.0.0

    org.testng.xslt
    testng-xslt
    0.0.1-SNAPSHOT
    jar

    testng-xslt
    http://maven.apache.org




    org.testng
    testng
    6.1.1
    test



    org.seleniumhq.selenium.client-drivers
    selenium-java-client-driver
    1.0.1
    test



    org.testng.xslt
    testng-xslt-plugin
    1.1
    system
    ${basedir}/lib/testng-xslt-plugin-1.1.jar









    maven-compiler-plugin

    iso-8859-1
    1.6
    1.6




    org.apache.maven.plugins
    maven-site-plugin
    2.X

    true
    UTF-8
    UTF-8



    org.codehaus.mojo
    openjpa-maven-plugin
    1.2


    enhancer
    process-classes,process-test-classes

    enhance








    org.apache.maven.plugins
    maven-resources-plugin
    2.5


    features
    generate-resources

    copy-resources




    src/main/features
    true


    target/features





    org.codehaus.mojo
    build-helper-maven-plugin
    1.7


    attach-artifacts
    package

    attach-artifact




    target/features/features.xml
    xml
    features











    org.testng.xslt
    testng-xslt-plugin
    1.1.2


    ${project.basedir}/target/site/testng-xslt-report/index.html

    true

    true
    FAIL,PASS,SKIP,CONF



    org.apache.maven.plugins
    maven-surefire-report-plugin
    2.12.4

    TestNgreport



    org.apache.maven.plugins
    maven-site-plugin
    2.1

    ${basedir}/target/newsite





    UTF-8



    my-local-repo
    file://${basedir}/lib






    ReplyDelete
    Replies
    1. Some problem with the config i believe.

      Delete
  10. This process has become hit and try, because I was able to generate the reports (reportng not xslt) just once. The report appeared under surefire-reports/html directory. But after that after many times I have tried but it didnt give any report but simple testng report.
    @Somesh/Varun/XiangLong Meng if you are able to generate the report please share your pom.xml or simply modify the given pom above with M2 or M3

    ReplyDelete
    Replies
    1. Please look at the post:

      http://blog.varunin.com/2013/10/generate-reportng-report-using-maven.html

      I tried it myself and it always generate a ReportNG report

      Delete
    2. I had updated the pom file to use the latest testng xslt now called "reporty-ng"

      Delete
  11. Hi Varun,
    Is there any other source apart from github where I can get reporting plugin?

    ReplyDelete