I use Selenium webdriver 2 with Test-NG. Test-NG gives a nice report when an assertion fails. The customer wishes to see the same report in the case where an assertion passes. Is it possible to do with the default Test-NG reporter?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
TestNG knows nothing about assertions per se. It knows only that the test threw an exception or did not. All of the information that TestNG gets from the assertion comes from the exception thrown by the assertion failure. If an assertion passes, TestNG never knows about it.
On the other hand, you can write your assertion methods that know how to log information, or to write information through TestNG's Reporter object. There may be other ways that an assertion can send information to TestNG, but each of them involves using some form of assertion that knows when and how to report the information.
One possibility is to write your own
One possible implementation:
If your output from Selenium Webdriver is in JUnit format, you can use ReportNG to format it to the way you need it.
If you are not currently outputting the your results in JUnit format, you will need to configure ant to output the reports in XML format (as per this link)
First, I would try to explain to the customer an assertion is a Boolean condition; if the assertion isn't hit then it "passes." Or perhaps ask the customer if they want to "see" what condition each Boolean expression is evaluating and log the condition.
I am not familiar with TestNG, but if they are persistent, then TestNG provides multiple assertion methods including:
This would certainly skew the report and appear to have lots of failures.
You can use ExtentReport.
You can use it to log your test steps and once its done it will generate a report to show your results. It will also show all fails and help you distinguish between assertion and an actually test fail. This is why we implemented it into our enviornment.
Here is how to set up ExtentReports on your project with examples - http://www.ontestautomation.com/creating-html-reports-for-your-selenium-tests-using-extentreports/
The above is a Logger method. You must put a log into each test step in your test code.
An easier but more restritive way of using ExtentReport is as a listener. You can use it to listen in on your tests as they are being executed. You must just specify the listener class in your test XML file.
The reports generated by ExtentReport are extremly attractive and informative. There is huge support from the creators of this technology and as its open source they are more than willing to accept ideas for future updates etc.
You must use it in conjunction with a test runner eg. TestNG or JUnit.
Here is an example of a report generated by ExtentReport - http://relevantcodes.com/Tools/ExtentReports2/ExtentJava.html
Hope it helps !