TestNG Reports:
By Default , Selenium does not generate any reports.
By using testNG, We can generate reports.
In TestNG, generating reports is an essential feature that provides
insights into test execution results. Here's how you can use TestNG to generate
reports using its built-in capabilities:
// Reporter - is predefined class in TestNG
// which has some methods ,
can be used to send given msg to report
// log msgs
package TestNGBasics2;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.Test;
public class TestWithReports
{
@Test
public void
testA()
{
//
// System.out.println("Enter
user anme");
// System.out.println("Enter
pwd");
// System.out.println("click
login");
//
log msg in reports -Enter user anme
//
log msg in reports -Enter password
//
log msg in reports -click Login btn
}
@Test
public void
createOrder()
{
// log msg in reports - Enter product name
// log msg in reports - Enter qty
// log msg in reports - Enter address
// log msg in reports - Payment throuh credit card
}
}
Run as testng
test :
Check testng
Results :
Go to Project>
"Test-output" folder
i.e
C:\brahma\Practise\SelniumPractiseNew\March52024MyWorkspace\SeleniumMay52024\test-output
Note:
if 'test-output' folder is
not available in project ,
"Refresh" project , it displays 'test-output' folder
Types of reports :
-----------------------
1. emailable-report.html
2. index.html
1. emailable-report.html:
------------------------------
open emailable-report.html
--------------------------------
The emailable-report.html is one of
the default reports generated by TestNG after test execution.
It provides a summary of the test run, including the overall pass/fail
status of tests, duration, and any exceptions encountered. Here are some key
features:
· Summary
Information: Includes general information about the test suite such as
start time, end time, total tests run, passed, failed, skipped, etc.
· Detailed
Test Case Results: Provides detailed information about each test method
executed during the test run.
- Test Method Name: Displays the name of each
test method.
- Execution Status: Shows whether the test
method passed, failed, or was skipped.
- Duration: Time taken to execute each
test method.
- Stack Trace: If a test method fails,
the stack trace is usually provided, aiding in debugging.
· Screenshots
(if configured): Optionally, screenshots may be embedded in the report if
tests capture screenshots on failure.
· Custom
Messages (if logged): Messages logged using Reporter.log() or custom listeners may appear here, providing
additional context.
1.e
Test # Passed # Skipped # Retried #
Failed Time (ms) Included Groups Excluded Groups
Default suite
Default test 2 0 0 0 100
Class Method Start Time
(ms)
Default suite
Default test — passed
TestNGAsserionsBasics.TestWithReports createOrder 1718245292612 19
testA 1718245292640 5
Default test
TestNGAsserionsBasics.TestWithReports#createOrder
Messages
Enter product name
Enter qty
Enter address
Payment through credit card
back to summary
TestNGAsserionsBasics.TestWithReports#testA
Messages
Enter user name
Enter password
Click Login btn
back
------------------------------------------
2. Open index.html report :
----------------------------------
The index.html
report is another default report generated by TestNG. It serves as an overview
or dashboard of the test suite execution. Key features include:
- Suite Overview: Summary of the test suite,
similar to emailable-report.html but often presented in a more compact
format.
- Navigation: Typically provides
navigation links to detailed reports or individual test case results.
- Charts and Graphs (if
configured):
Sometimes includes visual representations like charts or graphs
summarizing test results.
- Customization: Can be customized with
additional widgets or modules based on specific reporting needs.
Test results
1 suite
All suites
Default suite
Info
C:\Users\Lenovo\AppData\Local\Temp\testng-eclipse--1847707886\testng-customsuite.xml
1 test
0 groups
Times
Reporter output
Ignored methods
Chronological view
Results
2 methods, 2 passed
Passed methods (hide)
createOrder
testA
C:\Users\Lenovo\AppData\Local\Temp\testng-eclipse--1847707886\testng-customsuite.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM
"https://testng.org/testng-1.0.dtd">
<suite name="Default suite"
guice-stage="DEVELOPMENT">
<test thread-count="5"
name="Default test" verbose="2">
<classes>
<class
name="TestNGAsserionsBasics.TestWithReports"/>
</classes>
</test> <!--
Default test -->
</suite> <!-- Default suite -->
Click each link in Reports--> observe the Report window:
--------------------------------
Fail Reports :
package TestNGBasics;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.Test;
public class TestNGReportsBasics1
{
@Test
public void
testA()
{
//
// System.out.println("Enter
user anme");
// System.out.println("Enter
pwd");
// System.out.println("click
login");
//
Reporter - is predefined class in TestNG
// which has some methods , can be used to send
given msg to report
Reporter.log("Enter
user name");
Reporter.log("Enter
pwd");
Reporter.log("click
login");
// Fail test
metod -- check ram and sita are equal
Assert.assertEquals("ram",
"sita");
// Fail --
fail Test method
}
@Test
public void createOrder()
{
Reporter.log("Enter
product name");
Reporter.log("Enter
qty");
Reporter.log("Enter
address");
Reporter.log("Payment
throuh credit card");
}
}
Check testNG reports for
"Failed" Test Methods :
----------------------------------------------
it displays failed test method in 'red' color
Passed test Methods - in
'green' color
// HW Define 3 Test methods:
One Test method - Pass, one test method - Fail - one Test method-
Fail, Send some msgs to Report window,
open emailble-report.html and
index.html ?
No comments:
Post a Comment