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.

150 comments :

Anonymous said...

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 @!

Varun Menon said...

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

sai krishna said...

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

what should i do

Varun Menon said...

"${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" />

sai krishna said...

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.

Unknown said...
This comment has been removed by the author.
Unknown said...

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

Mari said...

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

Varun Menon said...

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

Sira said...

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

Sira said...

Now iam getting this error

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

Presneha said...

Hi,

How to generate report in selenium using junit ?

Varun Menon said...

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

Abhi_Mishra said...

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

which sort of error is it..?

Abhi_Mishra said...
This comment has been removed by the author.
Abhi_Mishra said...

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"

Varun Menon said...

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

Varun

sd said...

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

Varun Menon said...

@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.

dinu1025 said...

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

Varun Menon said...

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

Nikhil Dixit said...

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?

Varun Menon said...

@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.

Nikhil Dixit said...

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?

Varun Menon said...

@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

aman said...

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.

Varun Menon said...

@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.

bhaaskar said...

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)

Varun Menon said...

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

aostad said...

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

Bharath said...

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

Varun Menon said...

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

siva said...

hi varun

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

master nik said...

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

Dipen said...

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.

Varun Menon said...

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

Maya said...

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

Varun Menon said...

@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.

sai said...

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.

Varun Menon said...

@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.

Maya said...

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

Maya said...

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

Varun Menon said...

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

Unknown said...

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

Maya said...

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"

Maya said...

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

Janardhana said...

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

Varun Menon said...

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

Unknown said...

Hi Varun

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

pls help me

Regards
Nithin

ankita said...

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

Varun Menon said...

Is it Graphical report for a JUnit execution or Junit report which also have Graphical representation?

Varun Menon said...

How are you running your testng tests? using eclipse?

Unknown said...

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

Varun Menon said...

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

Unknown said...

Thanku Varun

Unknown said...

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

Arun said...

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

Siva said...

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

Varun Menon said...

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.

Siva said...

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.

Varun Menon said...

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.

Faisee said...

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

Varun Menon said...

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

Jinsha said...

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

Varun Menon said...

Welcome :)

Unknown said...

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.

Varun Menon said...

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

Vinay Iyengar said...

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

Varun Menon said...

It seems saxon lib is missing..

Vinay Iyengar said...

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

Unknown said...

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.

Madhu said...

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

Madhu said...
This comment has been removed by the author.
Varun Menon said...

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.

Madhu said...

Hi Varun,

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

madhusudhanareddy MV said...

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

Chinmay Shepal said...

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.

sudhakar said...

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

sudhakar said...

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....

Varun Menon said...

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

sudhakar said...

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.

Varun Menon said...

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.

sudhakar said...

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.

Unknown said...

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.

Unknown said...

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

Varun Menon said...

You want the report to be sorted order?.

Unknown said...

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;)

Unknown said...

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..:)

Varun Menon said...

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.

Unknown said...
This comment has been removed by the author.
Unknown said...

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.

Varun Menon said...

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

Varun Menon said...

No idea.

Unknown said...

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

Unknown said...

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

Varun Menon said...

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

Varun Menon said...

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

ramana said...

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

ramana said...

My Email ID: ramana.8@gmail.com

Unknown said...

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

Unknown said...

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!!

karthikeyan said...

Hi Varun,

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

Thanks,
Karthik

Varun Menon said...

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.

Varun Menon said...

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

jack said...

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[]

Varun Menon said...

Most probably the testng jar is not in the classpath specified.

Anonymous said...

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

Mac said...

Please help me , Im getting error ClassPathnotFound for SaxonLiaison

Varun Menon said...

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

Neil said...

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

Neil said...

Hi varun please provide some suggestion about the above error

Unknown said...

Hello Varun,

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

Varun Menon said...

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

Unknown said...

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?

Unknown said...

Hi,

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

Varun Menon said...

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

Unknown said...

can u give me a sample code for same.Varun

Unknown said...

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

Unknown said...

unable to add xml file here.

Unknown said...
This comment has been removed by the author.
Varun Menon said...

Check your before methods and the testng xml file.

Unknown said...

Hello Varun,

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

thanks in advance

Varun Menon said...

Look at the following link:

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

amal kar said...

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

amal kar said...

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


Pls help

Varun Menon said...

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

Varun Menon said...

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

Unknown said...

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?

Varun Menon said...

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.

ramya said...
This comment has been removed by the author.
ramya said...

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

Arjun Ray said...
This comment has been removed by the author.
Arjun Ray said...

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

Arjun Ray said...

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

Shilpee Naik said...

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

Text said...

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

Unknown said...

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

Varun Menon said...

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.

Unknown said...

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 ?

Varun Menon said...

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.

Unknown said...

Hi Varun
I currently face an issue that the reports are not getting updated. Even after compiling and running tests again and then I run the xslt report target to generate the report but the report is of the first run and is not getting updated. I do delete and create the directories again. Can you please help

Raghu said...

HI Varun,

Your blog really helped me a lot in generating XSLT reports through ant.

I am trying to add a build file for my existing projects and run them through hudson/commandprompt but i am receiving the below error message.

"error: package jxl does not exist [javac] import jxl.Cell;"

My existing projects are using page factory frame work , is this a problem . i mean do i need to include the common class which is in an other project.

Varun Menon said...

It seems your jxl library is not added to your classpath in ant build xml file.

Varun Menon said...

Most probably you have a hardcoded path for the testng-results.xml file in your xml. You need to check which results xml file has been reffered in your ant file. Another issue can be that the old report not being deleted. Delete the old report folder before execution start.

Unknown said...

Buildfile: D:\Java Workspace\XsltReport\src\build.xml
generateReport:
[delete] Deleting directory D:\Java Workspace\XsltReport\src\testng-xslt
[mkdir] Created dir: D:\Java Workspace\XsltReport\src\testng-xslt

BUILD FAILED
D:\Java Workspace\XsltReport\src\build.xml:14: input file D:\Java Workspace\XsltReport\src\test-output\testng-results.xml does not exist

sunilpatro1985 said...

Hi blogger,

I am getting the error on the 'out' variable declared line:
java.lang.abstractmethoderror:
net.sf.saxon.dom.DOMObjectModel.isRecognizedNodeListClass(Ljava/lang/Class;)Z

please help me to get rid of this error! thanks

Anonymous said...

Hi Varun,

I am trying to generate XSLT reports , but it was created empty output folder.

Can you please help me.

Unknown said...

ANT build is failed in eclipse mars and showing error- cannot find classpath. could you please help me why?

Unknown said...

ANT build is failed in eclipse mars and showing error- cannot find classpath. could you please help me why?

Unknown said...

I am not able to generate reports if there is any character like euro symbol in code or " ". please my code is UTF-8 encoded

makexsltreports:
[xslt] Processing D:\Jenkins\workspace\CEP-Functional-Test_slave\label\Windows_slave\CEP-Functional-Test\DummyProject_webdriver\DE_DataDriven_Framework_webdriver\test-output\testng-results.xml to D:\Jenkins\workspace\CEP-Functional-Test_slave\label\Windows_slave\CEP-Functional-Test\DummyProject_webdriver\DE_DataDriven_Framework_webdriver\XSLT_Reports\output\index.html
[xslt] Loading stylesheet D:\Jenkins\workspace\CEP-Functional-Test_slave\label\Windows_slave\CEP-Functional-Test\DummyProject_webdriver\DE_DataDriven_Framework_webdriver\src\com\canopy\xslt\testng-results.xsl
[xslt] D:\Jenkins\workspace\CEP-Functional-Test_slave\label\Windows_slave\CEP-Functional-Test\DummyProject_webdriver\DE_DataDriven_Framework_webdriver\test-output\testng-results.xml:1531:39: Fatal Error! Error reported by XML parser Cause: org.xml.sax.SAXParseException; systemId: file:/D:/Jenkins/workspace/CEP-Functional-Test_slave/label/Windows_slave/CEP-Functional-Test/DummyProject_webdriver/DE_DataDriven_Framework_webdriver/test-output/testng-results.xml; lineNumber: 1531; columnNumber: 39; Invalid byte 1 of 1-byte UTF-8 sequence.
[xslt] Failed to process D:\Jenkins\workspace\CEP-Functional-Test_slave\label\Windows_slave\CEP-Functional-Test\DummyProject_webdriver\DE_DataDriven_Framework_webdriver\test-output\testng-results.xml

BUILD FAILED
D:\Jenkins\workspace\CEP-Functional-Test_slave\label\Windows_slave\CEP-Functional-Test\DummyProject_webdriver\DE_DataDriven_Framework_webdriver\build.xml:114: net.sf.saxon.trans.DynamicError: org.xml.sax.SAXParseException; systemId: file:/D:/Jenkins/workspace/CEP-Functional-Test_slave/label/Windows_slave/CEP-Functional-Test/DummyProject_webdriver/DE_DataDriven_Framework_webdriver/test-output/testng-results.xml; lineNumber: 1531; columnNumber: 39; Invalid byte 1 of 1-byte UTF-8 sequence.
at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:278)
at net.sf.saxon.event.Sender.send(Sender.java:124)
at net.sf.saxon.event.Sender.send(Sender.java:46)
at net.sf.saxon.Controller.transform(Controller.java:1340)
at org.apache.tools.ant.taskdefs.optional.TraXLiaison.transform(TraXLiaison.java:197)
at SaxonLiaison.transform(SaxonLiaison.java:18)
at org.apache.tools.ant.taskdefs.XSLTProcess.process(XSLTProcess.java:878)
at org.apache.tools.ant.taskdefs.XSLTProcess.execute(XSLTProcess.java:416)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
at org.apache.tools.ant.Main.runBuild(Main.java:853)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)

Post a Comment