Thursday, May 13, 2010

Generating selenium reports using TestNG-xslt through Ant

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.

Most of the material is taken from the original site.
 http://code.google.com/p/testng-xslt/


Alternative link to download. Please open the said link and download it by going to File -> Download option.

I will tell in this blog how to implement this report for your project. This implementation will tell you how to generate the testng-xslt report using ant. If your current project does not use ant build then you can use ant only for the report generation purpose.

If you dont know ant please check the Apache ant website http://ant.apache.org/.

For generating testng-xslt report for your project do the following:
1. Download the 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>


The XSL transformation can be configured using the parameters described below.

  • testNgXslt.outputDir - Sets the target output directory for the HTML content. This is mandatory and must be an absolute path. If you are using the Maven plugin this is set automatically so you don't have to provide it.
  • testNgXslt.cssFile - Specifies and alternative style sheet file overriding the default settings. This parameter is not required.
  • testNgXslt.showRuntimeTotals - Boolean flag indicating if the report should display the aggregated information about the methods durations. The information is displayed for each test case and aggregated for the whole suite. Non-mandatory parameter, defaults to false.
  • testNgXslt.reportTitle - Use this setting to specify a title for your HTML reports. This is not a mandatory parameter and defaults to "TestNG Results".
  • testNgXslt.sortTestCaseLinks - Indicates whether the test case links (buttons) in the left frame should be sorted alphabetically. By default they are rendered in the order they are generated by TestNG so you should set this to true to change this behavior.
  • testNgXslt.chartScaleFactor - A scale factor for the SVG pie chart in case you want it larger or smaller. Defaults to 1.
  • testNgXslt.testDetailsFilter - Specified the default settings for the checkbox filters at the top of the test details page. Can be any combination (comma-separated) of: FAIL,PASS,SKIP,CONF,BY_CLASS
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.

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

140 comments:

  1. Hi,

    I am using Ant to build testNG. But I don't get the test output as name in testng-results.xml. May I know how can I get the testng-results.xml file?

    THanks @!

    ReplyDelete
  2. What is ur "outputdir" configuration when u r using the testng configuration in ant?

    ReplyDelete
  3. when i past the about code into ant im getting an error at < delete dir="${basedir}/testng-xslt" />

    what should i do

    ReplyDelete
  4. "${basedir}/testng-xslt" is the directory where I am generating Testng-xslt report.
    If you run it for the first time you will get an error.
    You can either create a dir with the said name and then try running.
    Or can remove the following steps.
    < delete dir="${basedir}/testng-xslt" />
    < mkdir dir="${basedir}/testng-xslt" />

    ReplyDelete
  5. Hi Varun ,

    Thanks for ur reply.
    i will try as u said ..

    Please do ping me ur contact number to my mail id - i have some more doubts
    My Email_id is saikrishna321@yahoo.com

    Please varun.

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

    ReplyDelete
  7. The problem for test-results.xml might be a caused, if you not have testng-results.xml present with in your project directory.
    Whenever you run the test suite xml for testNG, a report folder for the test run will be generate in your project directory with the name of 'test-report' for every test run.You can search this folder name within your project folder you will find it definitely, if you ran the task at least once.
    Now you can find 'testng-results.xml' file within 'test-output' directory. You need to point testng-results.xml file to generate your xslt-report and need to specify the correct path for the testng-reports.xml file location as '/test-output/testng-results.xml'.
    - Praveen Ashapure

    ReplyDelete
  8. I am getting fatal error,



    BUILD FAILED
    C:\Users\Ask-SEM\Desktop\Eclipse\SEMAutomation\SEMAutomation\buildmm.xml:48: The
    following error occurred while executing this line:
    C:\Users\Ask-SEM\Desktop\Eclipse\SEMAutomation\SEMAutomation\buildmm.xml:104: Fa
    tal error during transformation

    ReplyDelete
  9. Hi Mari,
    You need to send me your build.xml file. Then only I can help u.
    The reason being, the error posted by you just show the line no. where the error is. But I dont knw whts there at that line.
    You can send a mail at mr.varun.menon@gmail.com

    ReplyDelete
  10. Iam getting this error,i used ur same code only..

    What is that ${REPORT}

    Iam fresher in selenium,can you help me



    BUILD FAILED
    C:\Documents and Settings\Administrator\workspace\Ant_Project\src\tests\build.xml:4: input file C:\Documents and Settings\Administrator\workspace\Ant_Project\src\tests\${REPORT}\testNG-report\testing-result.xml does not exist

    ReplyDelete
  11. Now iam getting this error

    C:\Documents and Settings\Administrator\workspace\Ant_Project\src\tests\build.xml:4: Reference master-classpath not found.

    ReplyDelete
  12. Hi,

    How to generate report in selenium using junit ?

    ReplyDelete
  13. Hi Prerna,

    I had already covered it in my earlier post.

    http://blog.varunin.com/2010/03/ant-script-for-generating-junit-report.html

    Regards
    Varun

    ReplyDelete
  14. org.xml.sax.SAXParseException: Content is not allowed in prolog

    which sort of error is it..?

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

    ReplyDelete
  16. HI Varun

    Kindly correct this line of your ant code

    xslt in="${REPORT}/TestNG-report/testng-results.xml" out="${basedir}/testng-xslt/index.html"

    AS--

    xslt in="test-output/testng-results.xml" style="test-output/testng-results.xsl" out="${basedir}/testng-xslt/index.html"

    ReplyDelete
  17. Updated the xml.
    Originally it contained the "style" attribute. May have missed or got deleted while editing in-between.
    Thanks @Abhi for correcting.

    Varun

    ReplyDelete
  18. Hi Varun,

    I was able to create the report but it show some extra stuff in the report :

    Name: testLogin on instance null(com.testscripts.Login)
    Signature: testLogin ()
    Start time: 18:57:20
    End time: 18:57:20
    Duration: 11 ms

    If you see the name section, it has "on instance null(). Is there a way, we can remove that. I also see these in base testNG reports before converting them to XSLT

    Appreciate the help

    Thanks, Sarat

    ReplyDelete
  19. @sd: Sorry for the late response. But i think it is getting generated by the TestNG itself. I tried doing the same for a test and didnt saw the said issue.
    You can debug the TestNg code and see where the issue is. You can post your issue in StackOverflow under the TestNG section where you can get answer to your question from "Cedric Beust"
    Another option is to write your own report output using TestNG result listeners.

    ReplyDelete
  20. how to get report of failing and skipped tests in testng.xml format using TestNG or ReportNg

    ReplyDelete
  21. TestNG by default only generates the testng.xml for the use of re-execution of failing and skipped cases.
    For custom report generation you can create a class by implementing the TestListnerClass of TestNG and implementing certain methods in it.
    Please check the following URL:
    http://testng.org/doc/documentation-main.html#logging-listeners

    ReplyDelete
  22. Hi Varun,

    I am trying to generate testNG reports. I checked the procedure you mentioned and implemented it. I am able to generate HTML output file but its blank.

    Can you please mention how do I run ant build and secondly do I need any changes to make in my testNG test case?

    ReplyDelete
  23. @Nikhil - Please check whether the test-cases got executed or not. Also check whether the testng-results.xml that is generated by TestNG contains any data.
    Also for executing your testng cases as part of ant you need to define an testng task.The details has been provided in the following link:
    http://testng.org/doc/ant.html

    mail me at mr.varun.menon@gmail.com in case of any issues.

    ReplyDelete
  24. Thanks a ton Varun. I am able to generate test reports now. That link was really helpful for me.
    I have one more issue. I have a generic test method which calls multiple test methods which are written in some other classes. Now, the problem is testNG is not logging any details of execution for those methods I call from generic test method. These all methods are nested. All the methods get executed as expected. Its just can not log into testNG reports. Can you please suggest any solution for this?

    ReplyDelete
  25. @Nikhil - Thanks for your comments.
    Regarding your question. I would like to knw how u are doing it. Then only I can answer. You can send a mail or add me in chat at: mr.varun.menon@gmail.com

    ReplyDelete
  26. Hi Varun ,

    While running it from ant i am geeting this error:


    [xslt] : Error! Syntax error in 'if ($testNgXslt.testDetailsFilter) then $t
    estNgXslt.testDetailsFilter else 'FAIL,PASS,SKIP''.

    Can you please help me here.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. This error occur because we may forget to add SaxonLiaison jar into our project or we forget to add processor="SaxonLiaison" as an attribute on tag. Proper tag is given below.

      this type of error happen when parser cannot parser the xsl file.



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

      Delete
  27. @aman: Can you send the build.xml that you are using to mr.varun.menon@gmail.com.
    I think the problem is with 'FAIL,PASS,SKIP"
    Notice that at starting of FAIL its single quotes rather than double.

    ReplyDelete
  28. Hi varun,

    I am using ruby and junit, shell I use this xslt in my build.xml file ( i never used testNG in my project)

    ReplyDelete
  29. @bhaskar: According to my info it only works with a testng results xml that is generated by TestNG execution.

    ReplyDelete
  30. Thanks for the detail steps. Although, an index.html is created but it there is no graphic. It's only text.

    ReplyDelete
  31. Hi Varun,

    I followed the steps mentioned able able to execute ant and getting build successful msg. But this directory is not getting created, I commented out that part and created the folder manually. Even then I am not getting any output in testng-xslt folder, please help me out here

    ReplyDelete
  32. First of all sorry for the late response. A little busy thts y.
    @aostad - Whether testcases are getting executed?
    @Bharath - Cant say without actually looking at ur build.xml. Send it to mr.varun.menon@gmail.com

    ReplyDelete
  33. hi varun

    Can you please tell me how to generate junit reports. I dont have ant or maven

    ReplyDelete
  34. 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..
    \

    code...............








    Please guide me

    ReplyDelete
    Replies
    1. Hi I too getting same error.Have got any solution.if s please share to me

      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 you can follow this link http://startingwithseleniumwebdriver.blogspot.in/2014/03/some-error-and-solution-for-testng-xslt.html

      Delete
  35. Hi Varun,

    While trying to run the build.xml, getting the error build fail

    BUILD FAILED
    D:\EP_Automation_Scripting_31_Jan\EPAutomationScripts\build.xml:24: Compile failed; see the compiler error output for details.

    Total time: 749 milliseconds
    error detail
    package com.thoughtworks.selenium does not exist
    package org.testng.annotations does not exist
    package org.testng does not exist
    package com.thoughtworks.selenium does not exist
    cannot find symbol
    symbol: class SeleneseTestCase
    public class feedback extends SeleneseTestCase {

    etc.

    ReplyDelete
    Replies
    1. Make sure u had added the selenium lib to your class path or under the folder.

      Delete
  36. Hi Varun,
    Getting the following error message on compiling ant

    setClassPath:

    init:

    BUILD FAILED
    E:\EclipseWorkspace\EBusinessAjax\build.xml:27: taskdef class org.testng.TestNGA
    ntTask cannot be found
    using the classloader AntClassLoader[]
    This is the part of build.xml file

    ReplyDelete
    Replies
    1. @Maya - You need to specifiy the path to the the testng lib in the ant file. I think its missing thats why you are getting this error.

      Delete
    2. Hi Varun,

      Thank you for the reply. However our issue was a different one, in our path we had given .jars instead of .jar. We found this suggestion on one of your googlegroups post.

      Thanks Again
      Maya

      Delete
    3. Hi Varun,

      Now we have a runtime issue on one machine. We are running selenium on two machines. The ant files compiles successfully on both, however it fails to run on one machine giving the build failed with a message 'Testng does not support the "suitename" attribute. It runs without any issues on the other.

      Both the machines are using the same build file.
      Could not find any docs on this online.

      Thanks
      Maya

      Delete
    4. Check your testng.xml configuration on both the machines. I think a space is missing between "suite" & "name" in the system where its failing.

      Varun

      Delete
    5. Hi Varun,

      Thank you for the reply, however both the machines are using the same testng.xml and build.xml. It is successfully compiling on the second machine but the run fails with the above message. we tried changing the "suitename" in build.xml to "suite" and got similar error message 'Testng does not support the "suite" attribute.

      The Testng we have used
      suite name = "Yahoo_Mail"

      The Build.xml fails here
      !-- run --
      testng classpath="${test.classpath}:${test.dest}" suitename = "Yahoo_Mail"

      Delete
    6. Hi Varun,

      Thank you , however there is no difference in the build.xml or tesng.xml being used in both machines. I tried changing the 'suitename' to 'suite' and got a similar message saying "testng does not support 'suite' attribute".
      Where am I going wrong? Compilation works fine, on ant run we get the error message, makexsltreports also works without any issues

      Delete
  37. Hi Varun,
    I'm able to execute the report. But, when the tesng classes are failed the reports are not generated.It only generates only when it all tests gets passed.

    ReplyDelete
    Replies
    1. @sai - Check you ant target that builds and run your testng methods and then calls the test-ng xslt report. I think there is some problem with the sequence in which your targets are getting called.

      Delete
  38. Hi Varun
    I am trying to generate XSLT report. testng-results.xml contains data. But index.html is not showing anything.What would be the reason?

    Regards
    Sriram

    ReplyDelete
  39. Hi varun, can u tell me how to generate the testNG-xslt report using maven alone?. please share the sample POM.xml if possible....

    ReplyDelete
    Replies
    1. Please go through my recent blog post.
      http://blog.varunin.com/2012/05/generate-testng-xslt-report-using-maven.html

      Delete
  40. Hi Varun

    i want to generate a jUnit report which should contain graphical representation is that possible

    pls help me

    Regards
    Nithin

    ReplyDelete
    Replies
    1. Is it Graphical report for a JUnit execution or Junit report which also have Graphical representation?

      Delete
    2. My lead is asking me to generate a report which should contain a graph but with the help of JUnit is it possible.

      Delete
    3. In case you need to generate a custom report for Junit. You can do it by extending the Junit runner and then overriding pass,fail and error functions

      Delete
  41. hi varun

    I want to generate a testng report using ant but the problem is after running test cases in testng,in my folder TEST_OUTPUT i cant find build.xml so my quen is we need to create that build.xml file??
    Pls help me

    Regards
    Ankita

    ReplyDelete
    Replies
    1. How are you running your testng tests? using eclipse?

      Delete
  42. Hi Varun,
    I am Saravanan.P, working as SQA engineer
    I just went to through your blog regarding TestNG report generation, really its useful
    Based on the blog reference, i just created the in my build.xml, while running that target it throwing error like

    "Deleting directory C:\Users\Administrator\Selenium\Selenium_Project\testng-xslt
    Created dir: C:\Users\Administrator\Selenium\Selenium_Project\testng-xslt
    Processing C:\Users\Administrator\Selenium\Selenium_Project\reports\testng-results.xml to C:\Users\Administrator\Selenium\Selenium_Project\testng-xslt\sss.html
    Loading stylesheet C:\Users\Administrator\Selenium\Selenium_Project\testng-results.xsl
    : Error! Syntax error in 'if ($testNgXslt.testDetailsFilter) then $testNgXslt.testDetailsFilter else 'FAIL,PASS,SKIP''.
    : Error! file:/C:/Users/Administrator/Selenium/Selenium_Project/testng-results.xsl: line 23: Error parsing XPath expression 'if ($testNgXslt.testDetailsFilter) then $testNgXslt.testDetailsFilter else 'FAIL,PASS,SKIP''.
    : Error! file:/C:/Users/Administrator/Selenium/Selenium_Project/testng-results.xsl: line 23: Required attribute 'select' is missing."

    i sent you the build.xml via mail

    Thanks
    Saravanan

    ReplyDelete
  43. Hi Mr.Varun,

    I also used Ant, TestNG, TestNG XSLT to run my selenium test cases and generate xslt reports and was working perfect initially but all of a sudden may be after the new version of firefox 11 and above, the build.xml file compiles successfully but while running it is not launching the firefox browser at all and the build fails. ( but the same .java file works correctly in eclipse)
    similarly ant is not working for chrome browser also and for IE I am getting "unable to locate eval method" error.

    it works only for HtmlUnitDriver.

    so i could not run any of my test cases using ant

    can you please tell me what would be the problem. I would prefer to use Firfox as my browser.

    please help to sole this issue

    Aruna

    ReplyDelete
  44. Hi Varun,

    This is siva. I gone through this blog it is really use full.
    I followed the steps as you mentioned above for creating the xslt reports.

    But,if i give the cmd as "testng-xslt-report" in the cmd prompt, it is showing the below error message

    D:\TestNGworkspace\TestNG_Ant\build.xml:119: stylesheet D:\TestNGworkspace\TestNG_Ant\test-output\testng-results.xsl doesn't exist.

    But if i copy the "testng-results.xsl" file from "D:\TestNGworkspace\TestNG_Ant\src\xslt\testng-results.xsl" path to "test-output" folder (D:\TestNGworkspace\TestNG_Ant\test-output\testng-results.xsl) then i could see the message in the cmd prompt as "Build successful" and the reports also got generated.

    Can you provide the solution for this

    ReplyDelete
    Replies
    1. Change the input file param as mentioned in the following:
      <xslt in="${basedir}/test-output/testng-results.xml"
      to
      <xslt in="${basedir}/src/xslt/testng-results.xsl"

      this may work.

      Delete
    2. Hi Varun,

      Thanks for your valuable information.
      Now it works for me.

      Can you do one more help.

      Now the XSLT reports got generated. When i open the below file "XSLT_Reports\index.html" i could see the results in graph.

      Is it possible to send the report automatically to a specific email address, once the test execution is completed.

      Delete
    3. Please refer to my earlier post:
      http://blog.varunin.com/2011/07/sending-e-mail-with-your-test-execution.html

      You may need to zip the report directory for attaching it to the mail.
      You can use an ant target after the report generation to send the report as mail attachment.

      Delete
  45. Any idea why will this happen:


    [echo] F:\My_Space\ipl_SeleniumScript\trunk\seleniumtests/reports
    delete] Deleting directory F:\My_Space\ipl_SeleniumScript\trunk\seleniumtests\testng-xslt
    [mkdir] Created dir: F:\My_Space\ipl_SeleniumScript\trunk\seleniumtests\testng-xslt
    [xslt] Processing F:\My_Space\ipl_SeleniumScript\trunk\seleniumtests\test-output\testng-results.xml to F:\My_Space\ipl_SeleniumScript\trunk\seleniumtests\testng-xslt\index.html
    [xslt] Loading stylesheet F:\My_Space\ipl_SeleniumScript\trunk\seleniumtests\testng-results.xsl
    [xslt] : Error! Syntax error in 'if ($testNgXslt.testDetailsFilter) then $testNgXslt.testDetailsFilter else 'FAIL,PASS,SKIP''.
    [xslt] : Error! file:/F:/My_Space/ipl_SeleniumScript/trunk/seleniumtests/testng-results.xsl: line 23: Error parsing XPath expression 'if ($testNgXslt.testDetailsFilter) then $testNgXslt.testDetailsFilter else 'FAIL,PASS,SKIP''.
    [xslt] : Error! file:/F:/My_Space/ipl_SeleniumScript/trunk/seleniumtests/testng-results.xsl: line 23: Required attribute 'select' is missing.
    [xslt] : Error! file:/F:/My_Space/ipl_SeleniumScript/trunk/seleniumtests/testng-results.xsl: line 12: The method attribute of an element had the value 'xhtml'. The value must be one of 'xml', 'html', 'text', or qname-but-not-ncname
    [xslt] : Error! Syntax error in 'if (suite/@url) then document(suite/@url)/suite else suite'.
    [xslt] : Error! file:/F:/My_Space/ipl_SeleniumScript/trunk/seleniumtests/testng-results.xsl: line 421: Error parsing XPath expression 'if (suite/@url) then document(suite/@url)/suite else suite'.
    [xslt] : Error! file:/F:/My_Space/ipl_SeleniumScript/trunk/seleniumtests/testng-results.xsl: line 421: Required attribute 'select' is missing.
    [xslt] : Error! Syntax error in 'if (test/@url) then document(test/@url)/test else test'.
    [xslt] : Error! file:/F:/My_Space/ipl_SeleniumScript/trunk/seleniumtests/testng-results.xsl: line 690: Error parsing XPath expression 'if (test/@url) then document(test/@url)/test else test'.
    [xslt] : Error! file:/F:/My_Space/ipl_SeleniumScript/trunk/seleniumtests/testng-results.xsl: line 690: Required attribute 'select' is missing.
    [xslt] : Error! Syntax error in 'if (compare($sortByStartTime, 'true') = 0) then @started-at else '''.
    [xslt] : Error! file:/F:/My_Space/ipl_SeleniumScript/trunk/seleniumtests/testng-results.xsl: line 892: Error parsing XPath expression 'if (compare($sortByStartTime, 'true') = 0) then @started-at else '''.
    [xslt] : Error! Syntax error in 'if (compare($testNgXslt.sortTestCaseLinks, 'true') = 0) then @name else '''.
    [xslt] : Error! file:/F:/My_Space/ipl_SeleniumScript/trunk/seleniumtests/testng-results.xsl: line 1003: Error parsing XPath expression 'if (compare($testNgXslt.sortTestCaseLinks, 'true') = 0) then @name else '''.
    [xslt] : Error! Syntax error in 'null'.
    [xslt] : Error! file:/F:/My_Space/ipl_SeleniumScript/trunk/seleniumtests/testng-results.xsl: line 1010: Error parsing XPath expression 'null'.
    [xslt] : Error! Syntax error in 'if ($totalCount > 0) then format-number($passedCount div $totalCount, '###%') else '100%''.
    [xslt] : Error! file:/F:/My_Space/ipl_SeleniumScript/trunk/seleniumtests/testng-results.xsl: line 1085: Error parsing XPath expression 'if ($totalCount > 0) then format-number($passedCount div $totalCount, '###%') else '100%''.
    [xslt] : Error! file:/F:/My_Space/ipl_SeleniumScript/trunk/seleniumtests/testng-results.xsl: line 1085: Required attribute 'select' is missing.
    [xslt] : Fatal Error! Could not compile stylesheet
    [xslt] Failed to process F:\My_Space\ipl_SeleniumScript\trunk\seleniumtests\test-output\testng-results.xml

    ReplyDelete
    Replies
    1. Sorry for the late reply.
      The above problem may be due to improper testng report xml.

      Delete
    2. Hey Faisee,

      The above error is not because of the improper testng-result.xml

      Please add following in your Ant build file :
      In tag please add processor="SaxonLiaison".
      And please make sure that both of the Saxon jars are there on your project classpath as well as mentioned in your build.xml file.

      Delete
  46. Hi Varun,
    Im new to testng...
    Your blog was very helpful to me..
    Thanks a lott..:)

    ReplyDelete
  47. Hi Varun.. After a lot of research also m unable to make a proper build.xml file for testng.. please send the complete build.xml for selenium rc testng with ant.. help will be appreciated.

    ReplyDelete
    Replies
    1. The content itself is a build.xml. What are the issues that you are facing?

      Delete
  48. Hi Varun.



    In this line i am getting error as


    BUILD FAILED
    C:\ibc\SELENIUM\Workspace\BLUESKYAUTOMATION\build.xml:15: Reference C:/ibc/SELENIUM/Workspace/BLUESKYAUTOMATION/lib/SaxonLiaison not found.

    Total time: 1 second

    ReplyDelete
    Replies
    1. It seems saxon lib is missing..

      Delete
    2. But i have included the jar under lib folder. can u help me out in which line i need to give the path?

      Delete
  49. Hi Varun Menon,
    Thanks a lot for posting 'generating-selenium-xslt-reports-using.html' topic.I tried to generate xslt report from a long time. But i unable to get xslt result.Unexpectedly i had gone through your blog, i tried and it succeeded.
    Really i am very happy after getting xslt report. :D :D :D

    Thanks.

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

    ReplyDelete
    Replies
    1. Most probably the dir from where you are trying to read or write a file does not exist and hence you are getting this error. Could share your build.xml.

      Delete
  51. Hi Varun,

    Really it's worth full content.It saved my time.
    Thanks a lot Varun...

    ReplyDelete
  52. Hay varun,

    I am trying to pull data from excel using jxl.I am able to do.But i am getting problem while I am working with multiple data sheets.In my scenario I have created 2 data sheets and one exe sheet.
    My script first will go to exe sheet.and will store the scenario name in one variable.on that scenario name only i created two data sheets.So the stored variable name will be a String if i want get data from that sheet i need to change the data type to sheet.how to convert string to data type.

    Hear is my sample code

    @BeforeTest
    public static void initialize() {
    for (int e = 1; e < objects.getRows(); e++) {
    fi=new FileInputStream("D:\\data_driven_frame_work\\DATADRIVE\\src\\Config\\Driver.xls");
    w=Workbook.getWorkbook(fi);
    Scenario=w.getSheet("Scenario");
    objects=w.getSheet("objects");
    TS_001=w.getSheet("TS_001");
    TS_002=w.getSheet("TS_002");
    EXE = Scenario.getCell(2,e).getContents();
    if (EXE.equals("Y")) {
    TS = Scenario.getCell(0,e).getContents();

    }
    }

    }

    //#################################################
    @Test(invocationCount=1)
    public static void google_search() throws Exception {

    for (int i = 1; i < TS_002.getRows(); i++) {
    selenium.type(properties.getProperty(objects.getCell(0,11).getContents()),TS_002.getCell(0,i).getContents());
    Thread.sleep(1000);
    selenium.click(properties.getProperty(objects.getCell(0,12).getContents()));
    }
    }

    #######################################

    In second method I want use TS instead of TS_002..how to do

    ReplyDelete
  53. HI Varun,
    While running the script by using Testing i am facing issue like as below.
    [TestNG] Running:
    C:\Documents and Settings\sudhakar\Local Settings\Temp\testng-eclipse--2131251812\testng-customsuite.xml

    Loading Google search page
    Google search page loaded fine
    FAILED CONFIGURATION: @AfterTest close
    java.lang.NullPointerException
    at Registration.Testexample.close(Testexample.java:27)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
    at org.testng.TestRunner.afterRun(TestRunner.java:1021)
    at org.testng.TestRunner.run(TestRunner.java:621)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1203)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1128)
    at org.testng.TestNG.run(TestNG.java:1036)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

    PASSED: Test

    ===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 0
    Configuration Failures: 1, Skips: 0
    ===============================================


    ===============================================
    Default suite
    Total tests run: 1, Failures: 0, Skips: 0
    Configuration Failures: 1, Skips: 0
    ===============================================

    [TestNG] Time taken by org.testng.reporters.XMLReporter@1194a4e: 31 ms
    [TestNG] Time taken by org.testng.reporters.jq.Main@b66cc: 32 ms
    [TestNG] Time taken by org.testng.reporters.EmailableReporter2@750159: 15 ms
    [TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 0 ms
    [TestNG] Time taken by org.testng.reporters.JUnitReportReporter@1971afc: 0 ms
    [TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@1037c71: 78 ms
    Please help me out.Would appreciate if solve this problem.

    Please send all details to respective mail id:sudhkar40.qa@gmail.com
    Thanks,
    Sudhakar

    ReplyDelete
  54. Hi varun ,
    i written below script in Testng with webdriver...but i facing above issue which i have posted 2 days back....
    package Registration;

    import static org.testng.AssertJUnit.assertEquals;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.Test;

    public class Testexample {
    private WebDriver driver;

    @BeforeClass
    public void Startup(){
    FirefoxDriver driver = new FirefoxDriver();
    }

    @Test (description="Google Login")
    public void GoogleLogin() throws Exception{
    driver.get("http://www.gmail.com");
    assertEquals("Sign in", driver.findElement(By.id("signIn")).getAttribute("value"));
    driver.findElement(By.id("Email")).sendKeys("sudhkar40.qa@gmail.com");
    driver.findElement(By.id("Passwd")).sendKeys("*******");
    driver.findElement(By.id("signIn")).click();
    Thread.sleep(10000);
    driver.switchTo().frame("canvas_frame");
    driver.findElement(By.id("gbgs4dn")).click();
    driver.findElement(By.id("gb_71")).click();
    driver.switchTo().defaultContent();
    assertEquals("Sign in to Gmail", driver.findElement(By.id("button")).getText());
    }

    @AfterClass
    public void teardown(){
    driver.quit();
    }

    }

    Please hlep me out ASAp....

    ReplyDelete
    Replies
    1. You are setting the value of class level driver object that is declared.
      Remove FirfoxDriver driver= new FirefoxDriver() and just use.
      driver = new FirefoxDriver();

      hopefully this should solve your problem

      Delete
  55. Dear varun,

    Yes working fine.Thank you so much for solving the problem.

    But one more concern after executing the script by using TestNg i am not able to see result folder in LHS pane under project.

    And Where i can see Testng.Xml file in testng for creating test suits and how to execute Testng.xml.

    Please can u explain me briefly.

    One again thank you so much for helping.

    ReplyDelete
    Replies
    1. Are you refreshing your project in eclipse after report is being generated?
      testng.xml file does not get automatically created by TestNG. You have to create a new file with name testng.xml and define testng suites and tests inside it.

      Delete
  56. Dear Varun,

    First of all i would like to say thanks for instance replaying on my issues.

    1)Yes i refreshed after executing the script by TetNg though i am not able to see result folder under project.

    2) Could you please tell me how to create Testng.xml file and that how to configure into Testng.

    Please send me details following mail ID:sudhakar40.qa@gmail.com.

    Please help me out on above problems because i am new for Testng and selenium.

    ReplyDelete
  57. Hi Varun,
    I did get fatal error during transformation while executing build.xml file.I have attached build.xml file and did send to your mail.If any mistake please let me know.

    Thanks,
    Rakesh.

    ReplyDelete
  58. Hi, Varun

    really nice blog, i am stuck with running 5 suites in conjuctions with xslt report ant and eclipse and all sort of good things with testng,

    problem is

    1. not all test come in order with suite.xyz.testcase.java files that is listed to run in xyz suite in order (missing order)
    2. testng.xml calls all 5 suite xml one by one( Missing order)
    3. i look up your post about xslt and testng sort order but after comment out ant failed to build and it not help

    i will appropriated if you can Please suggest something,

    all i need is xml handle order of all suites and then test cases ( both xml order out to xslt remain same )

    thx much

    ReplyDelete
    Replies
    1. You want the report to be sorted order?.

      Delete
  59. Hi Varun,

    What all jar files i needed for xslt report target?
    I have addes saxon and saxonliasion.but i am getting following error

    java.lang.AbstractMethodError: net.sf.saxon.dom.DOMObjectModel.isRecognizedNodeListClass(Ljava/lang/Class;)

    ReplyDelete
  60. Hi Varun,
    Your blog was very helpful to me..
    Im generating the selenium script for test-case in our project...
    can you help me how to generate Junit,TestNG reports in detail....
    my mail ID: naidu104@gmail.com
    Thanks a lott..:)

    ReplyDelete
    Replies
    1. I had already covered in my blogs on how to generate junit reports for your test executions.
      TestNg by default generate both junit test results xml files as well as testng own results xml. You can use these xml files to generate html reports according you requirement.

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

    ReplyDelete
  62. Hi Varun,

    Thanks for such a informative blog..
    When i am using the above code, i am getting following error:

    java.lang.NoSuchMethodError: org.apache.tools.ant.types.Resource.getMagicNumber([B)I

    Please let me know how to resolve it.

    ReplyDelete
    Replies
    1. I had used the same code for my projects but never saw the above error.

      Delete
    2. link mentioned here to download XSLT is no more working. could you please let me know from where to download XSLT now?

      Delete
    3. Updated the blog with the alternative link. https://docs.google.com/file/d/0B3OQaZlrVrdJZUtSMWJseGVzVGs/edit?usp=sharing

      Delete
    4. When i was getting the Error mentioned above, these were the system configurations:
      ant version was 1.6.5 and Java Version was 1.7.0

      But i updated these to:
      ant: 1.8.2 and Java 1.6.33

      Now XSLT reports are working fine on my system.

      Thanks for all the help. Really appreciated!!

      Delete
  63. hI varun
    I am not able to download testng-xslt folder from http://code.google.com/p/testng-xslt/ . The link is giving 403 error at my end . I would really appreciate if you can email me the zip file for this . I was reading your blog and wanted to try testng-xslt reports on one of my project . I have googled it everywhere but was unable to find an alternate download link . Thanks in advance .My email is pranaydua@gmail.com

    ReplyDelete
    Replies
    1. Updated the blog with the alternative link. https://docs.google.com/file/d/0B3OQaZlrVrdJZUtSMWJseGVzVGs/edit?usp=sharing

      Delete
  64. hi Varun,

    testng-xslt folder is empty however the test are executed succesfully through ant build iam using windows7 are there any limitations for xslt reports.

    Thanks in Advance,
    Regards
    Ramana

    ReplyDelete
    Replies
    1. My Email ID: ramana.8@gmail.com

      Delete
    2. Please check the path to the report xml file configured for the xslt report generation target.

      Delete
  65. Hi varun,

    I am getting unusual error, "[xslt] Unknown file:23:146: Fatal Error! Could not find function: if", i am just using same xslt as on github site, but i am stuck , will be obliged if you could help me to get out of this confusion. Let me know if you need any more detail.
    Any help would be appreciated.

    Thanks,
    nitin
    nitinl@outlinesys.com

    ReplyDelete
    Replies
    1. Hi Varun,

      Even am also getting the same error.
      can you please help.

      Thanks,
      Karthik

      Delete
    2. Sorry for the late reply, have been very busy with work.
      Anyways regarding the above issue, it seems that you may be missing the report xml or the xslt file in the specified path.

      Delete
  66. Hi vaurun , could you please look into this
    i am getting the following erros
    error1 : default target usage doesnt exist in this project
    error2: taskdef class org.testng.TestNGAntTask cannot be found using the classloader AntClassLoader[]

    ReplyDelete
    Replies
    1. Most probably the testng jar is not in the classpath specified.

      Delete
  67. Awesome Blog Varun...Thanks a ton !!!

    ReplyDelete
  68. Please help me , Im getting error ClassPathnotFound for SaxonLiaison

    ReplyDelete
  69. You get this error when the saxon library is not set in the classpath.

    ReplyDelete
  70. am using selenium webdriver java build [ latest one]

    Framework : TestNg

    Editor Eclipse

    Firefox browser version : 22.0

    Chrome Browser version : 28.0.1500.72 m

    OS: Windows 7 Ultimate

    From Eclipse run option my test cases are running properly but When ever i am trying to run my webdriver test cases from command prompt using ANT

    For the chrome browser it showing alert related to manifest version and for Firefox browser its showing error related to Unable to bind to locking port 7054.

    Can any one give some suggestion what changes are required so that i can run my test cases properly from ant

    ReplyDelete
  71. Hi varun please provide some suggestion about the above error

    ReplyDelete
  72. Hello Varun,

    Can u tel me how to add screen shots link in case of failure in xslt report

    ReplyDelete
    Replies
    1. http://ananraja.blogspot.in/2013/07/adding-screenshot-link-in-testng-xslt.html

      Delete
  73. Hi Varun,
    I did run build.xml from terminal.
    Even if the testcase fails,TestNG prints the message "BUILD SUCCESSFUL".IS it the expected behaviour from TESTNG?

    ReplyDelete
  74. Hi,

    Can u plz tel me sample code for implementing listeners in testng suite.
    I need sample code fully explaining.

    ReplyDelete
    Replies
    1. What are you trying to achieve through listeners? For a listener you just have to implement the ITestListener interface.

      Delete
  75. can u give me a sample code for same.Varun

    ReplyDelete
  76. Hello Varun :

    can u plz help me regarding the below :
    Build .xml file content :


    I am able to compile it successfully
    Problem:
    I'm getting error while running & reporting:
    [testng] Total tests run: 7, Failures: 0, Skips: 7
    [testng] Configuration Failures: 1, Skips: 2

    & unable to genarte reports as well. kindly help me regarding the below

    ReplyDelete
    Replies
    1. Check your before methods and the testng xml file.

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

    ReplyDelete
  78. Hello Varun,

    Can u please send me a sample code of how to implement Testng listners in java class.

    thanks in advance

    ReplyDelete
    Replies
    1. Look at the following link:

      http://testng.org/doc/documentation-main.html#logging

      Delete
  79. Hi Varun,

    I was trying to automate few browser cases using android web driver & eclipse. I was able to execute the cases. I was trying to follow all your mentioned step to generate the report, but could not able to. Pls help me. I do not want to integrate with ANT/Mavan. Only I need to get report generated after execution. One more thing, i want to execute test cases in a batch.

    Thanks,
    Amal

    ReplyDelete
    Replies
    1. If you want to get testng-xslt report generated without using ant/maven then you have to have some hack implemented into you code to apply xslt and generate the report. You can get the idea from the following code.

      https://github.com/cosminaru/reporty-ng/blob/master/src/main/java/org/reportyng/mavenplugin/TestNgXsltMojo.java

      Delete
  80. Can you pls let me know wt is the master-classpath mentioned here.


    Pls help

    ReplyDelete
    Replies
    1. It is the classpath containing the compiled code under the bin directory and all the jars present under the lib folder.

      Delete
  81. 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 u please share the build.xml?

    ReplyDelete
    Replies
    1. Hi Anu,

      There is no configuration available in TestNg to change the results xml file name.
      You can change the output directory of testng results in your ant file. You can have output directory represent the build number and date.
      Another approach will be to rename the testng-results.xml file with your desired name after if has been generated, by using ant target.

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

    ReplyDelete
  83. I copied the above build.xml for my project,and executed it through eclipse,am not getting any report,just build successful message in eclipse
    Getting build.xml not found when i type ant in cmd prompt
    What could be my mistake

    ReplyDelete
  84. make sure u have pasted ur build.xml in project level and u have given the correct path for jars in build.xml

    ReplyDelete
  85. My xslt reports are not opening in my browser.But opening in eclipse.

    ReplyDelete
  86. how to generate XSLT reports using reportng as Reportng does not generates testng-results.xml file

    ReplyDelete
    Replies
    1. ReportNG works with TestNg and TestNg generates the xml file. I think you may have disabled the default testng report generation. Try enabling it and you will get the results xml file.

      Delete
    2. Varun,

      Intentionally i've set useDefaultListener attribute to false in ant build file.

      We usually use "testng-reports.xml" file that is generated from testng in xslt reports. But i want to use an xml file which was generated from reportng that should contains all the information of reuslts of the suites to use the same in xslt.

      please help me how to achieve this ?

      Delete
    3. You cant achieve using the xslt report. The xslt report expects an input without which it wont work. Reportng generates Junit xml files. You have to have your own implementation to support Reportng xml.

      Delete