Listeners for logging in case of PASSED , FAILED, SKIPPED or test cases:
Refer :
https://testng.org/#_annotations
https://javadoc.io/doc/org.testng/testng/latest/org/testng/ITestListener.html
FAQ ***
ItestListner:
// ITestListener
- predefined Interface in TestNG
// only
abstr methods -- in complete method - some where we have to implement
// Listen to test Method -
when
test method starts execution,
when
test method finishes execution,
when
test method passed successfully,
when
test method fails,
when
test method skipped..etc
when
test method failed with time out error
when
test method failed with some success %
some methods in ItestListner:
-----------------------------
onStart()
{
}
onFinish()
{
}
onTestStart()
{
}
onTestSuccess()
{
}
onTestFailure()
{
}
onTestSkipped()
{
}
onTestFailedWithTimeout()
{
}
onTestFailedButWithinSuccessPercentage()
{
}
The ITestListener interface in TestNG provides a way to listen to
various events related to test methods during their execution. Here are the key
methods defined by ITestListener that you can implement to listen
to different events:
- onStart(ITestContext
context):
- Invoked before any test
method belonging to the classes inside the <test> tag is run.
- Provides an ITestContext object that contains all
the information for a given test run.
- onFinish(ITestContext
context):
- Invoked after all the test
methods belonging to the classes inside the <test> tag have run.
- onTestStart(ITestResult
result):
- Invoked when a test method
starts execution.
- Provides an ITestResult object containing details
about the test method starting.
- onTestSuccess(ITestResult
result):
- Invoked when a test method
succeeds.
- Provides an ITestResult object containing details
about the successful test method.
- onTestFailure(ITestResult
result):
- Invoked when a test method
fails.
- Provides an ITestResult object containing details
about the failed test method.
- onTestSkipped(ITestResult
result):
- Invoked when a test method
is skipped.
- Provides an ITestResult object containing details
about the skipped test method.
- onTestFailedButWithinSuccessPercentage(ITestResult
result):
- Invoked each time a test
method fails but has been annotated with success percentage and this
failure still keeps it within the success percentage.
- onTestFailedWithTimeout(ITestResult
result):
- Invoked when a test method
fails due to a timeout.
- Provides an ITestResult object containing details
about the test method that failed due to timeout.
System.out.println("onStart() - gets executed only once before executing all test methods ");
System.out.println("onFinish() method will be called only
once after executing all Test nethods ");
System.out.println("onTestStart - gets executed every time
before Starting Test Method");
System.out.println("onTestSuccess - gets executed for each test Method if Test MEthod
passes succssfully ");
System.out.println("onTestFailure - If test method failed ");
System.out.println("onTestSkipped - ");
System.out.println("onTestFailedButWithinSuccessPercentage");
System.out.println("onTestFailedWithTimeout");
package TestNGBasics2;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;
///Define MyTestListnerBasics
, implements ItestListner methods
public class MyTestListnerBasics implements ITestListener
{
// define
ItestListner -methods
// onstart(),
onfinish(), onTestStart(), onTestSucess(), OnTestFailure, ontestSkipped()
//
onTestFailureWithtime, ....
//Define
onStart()
@Override
public void
onStart(ITestContext context) {
System.out.println("onStart
- gets executed only once before
executing all test methods ");
}
// Define
onTestStart() == BEforeMethod
@Override
public void
onTestStart(ITestResult result) {
System.out.println("onTestStart
- gets executed every time before Starting Test Method");
}
// Define
onTestSuccess()
@Override
public void
onTestSuccess(ITestResult result) {
System.out.println("onTestSuccess
- gets executed for each test Method if
Test MEthod passes succssfully ");
}
// Define onTestFailure
@Override
public void
onTestFailure(ITestResult result) {
System.out.println("onTestFailure()
gets executed when test Method fails ");
}
//Define onTestSkipped()
@Override
public void
onTestSkipped(ITestResult result) {
System.out.println("onTestSkipped
gets executed if test method is skipped for execution");
}
//Define
onTestFailedWithTimeout()
@Override
public void
onTestFailedWithTimeout(ITestResult result) {
System.out.println("onTestFailedWithTimeout()
gets excuted when test method failed with time out error ");
}
//Define
onTestFailedButWithinSuccessPercentage()
@Override
public void
onTestFailedButWithinSuccessPercentage(ITestResult result) {
System.out.println("onTestFailedButWithinSuccessPercentage
- if test method fail with in some % ");
}
//Define
onFinish()
@Override
public void
onFinish(ITestContext context) {
System.out.println("onFinish
method will be called only once after executing all Test nethods ");
}
}
-----------------------------------
//Listen to ???
//Define @Listners before
class name
package TestNGBasics2;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
//Listen to ???
//Define @Listners before
class name
@Listeners(MyTestListnerBasics.class)
public class TestA
{
@Test
public void
testA()
{
System.out.println("Calling
test A -statement -1");
System.out.println("Calling
test A -statement -2");
}
}
run this class
o/p:
----
[RemoteTestNG] detected TestNG version 7.0.0
onStart - gets executed only once
before executing all test methods
onTestStart - gets executed every time before Starting Test Method
Caling test A -stmt- 1
Caling test A -statement -2
onTestSuccess - gets
executed for each test Method if Test MEthod passes succssfully
onFinish method will be called only once after executing all Test
nethods
PASSED: testA
===============================================
Default test
Tests run: 1, Failures:
0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Passes: 1, Failures: 0, Skips: 0
===============================================
ex2: Define class
with 2 @test methods:
package TestNGBasics2;
import org.testng.Assert;
import org.testng.SkipException;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
//Listen to ???
//Define @Listners before
class name
@Listeners(MyTestListnerBasics.class)
public class TestA
{
@Test
public void testA()
{
System.out.println("Calling
test A -statement -1");
System.out.println("Calling
test A -statement -2");
}
// when test Method
fails,it calls onTestFailure ()
// Define testB()
with assertion fail stmt
@Test
public void
testB()
{
System.out.println("Calling
test B -stmt-1");
Assert.assertEquals("ram",
"sita");// fails testB()
}
// // Define testC() with skip
//////when test Method skips,it calls onTestSkipped()
@Test
public void
testC()
{
System.out.println("Calling
test c -stmt-1");
//
throw skip exception
// ex throw new ArithematicExcepion();
throw
new SkipException("throwing Skip exception");
}
// // Define testD()
with time out = 5000
ThreadTimeoutException exception
@Test(timeOut =
5000)// if method takes >5 sec,it
throws ThreadTimeoutException exception
public void
testD() throws InterruptedException
{
System.out.println("Calling
test D -stmt-1");
Thread.sleep(8000);
//org.testng.internal.thread.ThreadTimeoutException:
Method TestNGBasics2.TestA.testD() didn't finish within the time-out 5000
}
}
run :
o/p:
[RemoteTestNG] detected TestNG version 7.0.0
onStart - gets executed only once
before executing all test methods
onTestStart - gets executed every time before Starting Test Method
Calling test A -stmt-1
Calling test A -statement -2
onTestSuccess - gets
executed for each test Method if Test MEthod passes succssfully
onTestStart - gets executed every time before Starting Test Method
Calling test B -stmt-1
onTestFailure() gets executed when test Method fails
onTestStart - gets executed every time before Starting Test Method
Calling test c -stmt-1
onTestSkipped gets executed if test method is skipped for
execution
onTestStart - gets executed every time before Starting Test Method
Calling test D -stmt-1
onTestFailedWithTimeout() gets excuted when test method failed
with time out error
onFinish method will be called only once after executing all Test
nethods
PASSED: testA
FAILED: testB
java.lang.AssertionError: expected [sita] but found [ram]
at org.testng.Assert.fail(Assert.java:97)
at
org.testng.Assert.assertEqualsImpl(Assert.java:136)
at
org.testng.Assert.assertEquals(Assert.java:118)
at
org.testng.Assert.assertEquals(Assert.java:575)
at
org.testng.Assert.assertEquals(Assert.java:585)
at TestNGBasics3.TestA.testB(TestA.java:27)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at
java.base/java.lang.reflect.Method.invoke(Method.java:564)
at
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at
org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:584)
at
org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:172)
at
org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at
org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:804)
at
org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:145)
at
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at
org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at
java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at
org.testng.TestRunner.privateRun(TestRunner.java:770)
at
org.testng.TestRunner.run(TestRunner.java:591)
at
org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
at
org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
at
org.testng.SuiteRunner.run(SuiteRunner.java:304)
at
org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at
org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
at
org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
at
org.testng.TestNG.runSuites(TestNG.java:1032)
at
org.testng.TestNG.run(TestNG.java:1000)
at
org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at
org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at
org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
FAILED: testD
org.testng.internal.thread.ThreadTimeoutException: Method
TestNGBasics3.TestA.testD() didn't finish within the time-out 5000
SKIPPED: testC
org.testng.SkipException: skipping the current test C()
at
TestNGBasics3.TestA.testC(TestA.java:38)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at
java.base/java.lang.reflect.Method.invoke(Method.java:564)
at
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at
org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:584)
at
org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:172)
at
org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at
org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:804)
at
org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:145)
at
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at
org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at
java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:770)
at
org.testng.TestRunner.run(TestRunner.java:591)
at
org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
at
org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
at
org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
at
org.testng.SuiteRunner.run(SuiteRunner.java:304)
at
org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at
org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at
org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
at
org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
at
org.testng.TestNG.runSuites(TestNG.java:1032)
at
org.testng.TestNG.run(TestNG.java:1000)
at
org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at
org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
===============================================
Default test
Tests run: 5, Failures:
2, Skips: 1
===============================================
===============================================
Default suite
Total tests run: 4, Passes: 1, Failures: 2, Skips: 1
===============================================
HW Write the o/p
for below program?
@Listeners(MyTestListnerBasics.class)
public class TestB {
@Test
public void
testA()
{
System.out.println("Caling
test A -stmt-1");
System.out.println("Caling
test A -statement -2");
}
@Test
public void
testB()
{
System.out.println("Caling
test B -stmt-1");
System.out.println("Caling
test B -statement -2");
}
}
o/p:
Revision :
FAQ What listners u have used in ur project ?
ItestListner :
FAQ What interfaces u used
in the Project ?
ItestListner - interface
from testNG
only abstract
method
-- no body
class MytesttList implements ItestListner
{
onstart() -- executed only once
{
}
onfinish() -
only once after execution all test methods
onTestStart()
-multiple times for each test method
onTestSuccess()
-- if test method is passed successfuly
onTestFailure() - if test method is failing -
onTestSkipped();
- if test method is skipped
}
@Listners(MytesttList.class)
class Mytestcases
{
@test
public void test
{
}
}
HW Define Login() , createOrder(), testE() test methods
in class and implement Listners by
passing test method and failing, skipping ?
@Listners(MyTestListnersBasics.class)
Class testA
{
}
2. define Listners tag in testNG.xml File :
<listeners>
<listener
class-name="TestNGBasics2.MyTestListnerBasics"></listener>
</listeners>
xml:
<?xml version="1.0" encoding="UTF-8"?>
<suite name ="My suite">
<listeners>
<listener
class-name="TestNGBasics2.MyTestListnerBasics"></listener>
</listeners>
<test
name="My test">
<classes>
<class
name="TestNGBasics2.TestA">
</class>
</classes>
</test>
</suite>
Remove @Listner
anontation from class and Run from testng.xml
package TestNGBasics2;
import org.testng.Assert;
import org.testng.SkipException;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
//Listen to ???
//Define @Listners before
class name
//@Listeners(MyTestListnerBasics.class)
public class TestA
{
@Test
public void
testA()
{
System.out.println("Calling
test A -statement -1");
System.out.println("Calling
test A -statement -2");
}
// when test Method
fails,it calls onTestFailure ()
// Define testB()
with assertion fail stmt
@Test
public void
testB()
{
System.out.println("Calling
test B -stmt-1");
Assert.assertEquals("ram",
"sita");// fails testB()
}
// // Define testC() with skip
//////when test Method skips,it calls onTestSkipped()
@Test
public void
testC()
{
System.out.println("Calling
test c -stmt-1");
//
throw skip exception
// ex throw new ArithematicExcepion();
throw
new SkipException("throwing Skip exception");
}
// // Define testD()
with time out = 5000
ThreadTimeoutException exception
@Test(timeOut =
5000)// if method takes >5 sec,it
throws ThreadTimeoutException exception
public void
testD() throws InterruptedException
{
System.out.println("Calling
test D -stmt-1");
Thread.sleep(8000);
//org.testng.internal.thread.ThreadTimeoutException:
Method TestNGBasics2.TestA.testD() didn't finish within the time-out 5000
}
}
RUN AS TESTng.XML FILE >
O/P:
[RemoteTestNG] detected TestNG version 7.0.0
[TestNGContentHandler] [WARN] It is strongly recommended to add
"<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd"
>" at the top of your file, otherwise TestNG may fail or not work as
expected.
onStart - gets executed only once
before executing all test methods
onTestStart - gets executed every time before Starting Test Method
Calling test A -statement -1
Calling test A -statement -2
onTestSuccess - gets
executed for each test Method if Test MEthod passes succssfully
onTestStart - gets executed every time before Starting Test Method
Calling test B -stmt-1
onTestFailure() gets executed when test Method fails
onTestStart - gets executed every time before Starting Test Method
Calling test c -stmt-1
onTestSkipped gets executed if test method is skipped for
execution
onTestStart - gets executed every time before Starting Test Method
Calling test D -stmt-1
onTestFailedWithTimeout() gets excuted when test method failed
with time out error
onFinish method will be called only once after executing all Test
nethods
===============================================
My suite
Total tests run: 4, Passes: 1, Failures: 2, Skips: 1
===============================================
Get "test
Method" name in Run time:
package ListnersBasics;
import org.testng.Assert;
import org.testng.SkipException;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
@Listeners(MyTestListner.class)
public class A
{
@Test
public void
testA()
{
System.out.println("stmt-1
from testA");
System.out.println("stmt-2
from testA");//passed - call/invoke OnTestSuccess()
}
@Test
public void
testB()
{
System.out.println("Caling
test B -stmt-1");
System.out.println("Caling
test B -statement -2");
//
Fail
Assert.assertEquals("ram",
"sita");// Failed - - Fail
-testB() - calls onTestFailure()
}
@Test
public void
testC()
{
System.out.println("Caling
test C -stmt-1");
System.out.println("Caling
test C -statement -2");
//
Skip
throw
new SkipException("Skipping TestC () ");// calls OnTestskipped()
}
@Test(timeOut =
5000)
public void
testD() throws InterruptedException
{
System.out.println("Caling
test D -stmt-1");
Thread.sleep(7000);
// If Test Method takes > 5 sec, it fails TestD -
// call onTestFailedWithTimeout()
System.out.println("Caling
test D -statement -2");
}
}
package TestNGBasics2;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;
///Define MyTestListnerBasics
, implements ItestListner methods
public class MyTestListnerBasics implements ITestListener
{
// define
ItestListner -methods
// onstart onfinish(),
onTestStart(), onTestSucess(), OnTestFailure, ontestSkipped()
//
onTestFailureWithtime, ....
@Override
public void
onStart(ITestContext context) {
//
TODO Auto-generated method stub
// ITestListener.super.onStart(context);
System.out.println("onStart
- gets executed only once before
executing all test methods ");
//
get "test" name
String
testMethodName = context.getName();
System.out.println("
name= "+ testMethodName + "
started execution ");
// name= Default test started execution
// default suite name= Default test
}
@Override
public
void onTestStart(ITestResult result) {
//
TODO Auto-generated method stub
// ITestListener.super.onTestStart(result);
System.out.println("onTestStart
- gets executed every time before Starting Test Method");
// get test method name which is running
String
testMethodName= result.getName();
// testB
String
testMethodName2 = result.getMethod().getMethodName();
System.out.println("testMethodName="+testMethodName);
System.out.println("testMethodName2="+testMethodName2);
System.out.println("Test
Method name="+ testMethodName+ " started execution" );//
Name=testA
// testA
// testB
}
@Override
public
void onTestSuccess(ITestResult result) {
//
TODO Auto-generated method stub
// ITestListener.super.onTestSuccess(result);
System.out.println("onTestSuccess
- gets executed for each test Method if
Test MEthod passes succssfully ");
//
get test method name and display pass
msg
String
testMethodName= result.getName();
// testA
System.out.println("Test
Method ="+ testMethodName+ " passed succesfully");//
// testA
}
@Override
public
void onTestFailure(ITestResult result) {
//
TODO Auto-generated method stub
// ITestListener.super.onTestFailure(result);
System.out.println("onTestFailure()
gets executed when test Method fails ");
//
get name and test method name in run time
String
testMethodName= result.getName();
System.out.println("Test Method ="+
testMethodName+ " failed");
// testB
}
@Override
public
void onTestSkipped(ITestResult result) {
//
TODO Auto-generated method stub
// ITestListener.super.onTestSkipped(result);
System.out.println("onTestSkipped
gets executed if test method is skipped for execution");
//
get anme and test method name in run time
String
testMethodName= result.getName();
System.out.println("Test Method ="+
testMethodName + " skipped");
//
}
@Override
public
void onTestFailedWithTimeout(ITestResult result) {
//
TODO Auto-generated method stub
// ITestListener.super.onTestFailedWithTimeout(result);
System.out.println("onTestFailedWithTimeout()
gets executed when test method failed with time out error ");
//
get name and test method name in run time
String
testMethodName= result.getName();
System.out.println("Test Method ="+
testMethodName + " failed with timeout error");
//
}
@Override
public
void onTestFailedButWithinSuccessPercentage(ITestResult result) {
//
TODO Auto-generated method stub
// ITestListener.super.onTestFailedButWithinSuccessPercentage(result);
System.out.println("onTestFailedButWithinSuccessPercentage
- if test method fail with in some % ");
}
@Override
public
void onFinish(ITestContext context) {
//
TODO Auto-generated method stub
// ITestListener.super.onFinish(context);
System.out.println("onFinish
method will be called only once after executing all Test nethods ");
//
get anme and test method name in run time
System.out.println("All Test Methods
finised execution completely");
}
}
o/p:
[RemoteTestNG] detected TestNG version 7.0.0
onStart - gets executed only once
before executing all test methods
name= Default test started execution
onTestStart - gets executed every time before Starting Test Method
Test Method name=testA started execution
Calling test A -stmt-1
Calling test A -statement -2
onTestSuccess - gets
executed for each test Method if Test MEthod passes succssfully
Test Method =testA passed
onTestStart - gets executed every time before Starting Test Method
Test Method name=testB started execution
Calling test B -stmt-1
onTestFailure() gets executed when test Method fails
Test Method =testB failed
onTestStart - gets executed every time before Starting Test Method
Test Method name=testC started execution
Calling test c -stmt-1
onTestSkipped gets executed if test method is skipped for
execution
Test Method =testC skipped
onTestStart - gets executed every time before Starting Test Method
Test Method name=testDstarted execution
Calling test D -stmt-1
onTestFailedWithTimeout() gets excuted when test method failed
with time out error
Test Method =testD failed with timeout error
onFinish method will be called only once after executing all Test
nethods
Test Method =Default test finised execution completely
PASSED: testA
FAILED: testB
java.lang.AssertionError: expected [sita] but found [ram]
at
org.testng.Assert.fail(Assert.java:97)
at
org.testng.Assert.assertEqualsImpl(Assert.java:136)
at
org.testng.Assert.assertEquals(Assert.java:118)
at
org.testng.Assert.assertEquals(Assert.java:575)
at
org.testng.Assert.assertEquals(Assert.java:585)
at
TestNGBasics3.TestA.testB(TestA.java:27)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at
java.base/java.lang.reflect.Method.invoke(Method.java:564)
at
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at
org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:584)
at
org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:172)
at
org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at
org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:804)
at
org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:145)
at
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at
org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at
java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at
org.testng.TestRunner.privateRun(TestRunner.java:770)
at
org.testng.TestRunner.run(TestRunner.java:591)
at
org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
at
org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
at
org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
at
org.testng.SuiteRunner.run(SuiteRunner.java:304)
at
org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at
org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at
org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
at
org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
at
org.testng.TestNG.runSuites(TestNG.java:1032)
at
org.testng.TestNG.run(TestNG.java:1000)
at
org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at
org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at
org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
FAILED: testD
org.testng.internal.thread.ThreadTimeoutException: Method
TestNGBasics3.TestA.testD() didn't finish within the time-out 5000
at
java.base@15.0.2/java.lang.invoke.MethodHandleNatives.resolve(Native Method)
at
java.base@15.0.2/java.lang.invoke.MemberName$Factory.resolve(MemberName.java:1087)
at
java.base@15.0.2/java.lang.invoke.MemberName$Factory.resolveOrNull(MemberName.java:1128)
at
java.base@15.0.2/java.lang.invoke.MethodHandleNatives.varHandleOperationLinkerMethod(MethodHandleNatives.java:563)
at java.base@15.0.2/java.lang.invoke.MethodHandleNatives.linkMethodImpl(MethodHandleNatives.java:475)
at
java.base@15.0.2/java.lang.invoke.MethodHandleNatives.linkMethod(MethodHandleNatives.java:463)
at
java.base@15.0.2/java.util.concurrent.FutureTask.setException(FutureTask.java:247)
at
java.base@15.0.2/java.util.concurrent.FutureTask.run(FutureTask.java:269)
at
java.base@15.0.2/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at
java.base@15.0.2/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at
java.base@15.0.2/java.lang.Thread.run(Thread.java:832)
SKIPPED: testC
org.testng.SkipException: skipping the current test C()
at
TestNGBasics3.TestA.testC(TestA.java:38)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at
java.base/java.lang.reflect.Method.invoke(Method.java:564)
at
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at
org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:584)
at
org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:172)
at
org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at
org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:804)
at
org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:145)
at
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at
org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at
java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at
org.testng.TestRunner.privateRun(TestRunner.java:770)
at
org.testng.TestRunner.run(TestRunner.java:591)
at
org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
at
org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
at
org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
at
org.testng.SuiteRunner.run(SuiteRunner.java:304)
at
org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at
org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at
org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
at
org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
at
org.testng.TestNG.runSuites(TestNG.java:1032)
at
org.testng.TestNG.run(TestNG.java:1000)
at
org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at
org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at
org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
===============================================
Default test
Tests run: 5, Failures:
2, Skips: 1
===============================================
===============================================
Default suite
Total tests run: 4, Passes: 1, Failures: 2, Skips: 1
===============================================
FAQ .HW how can we take Screenshot only for failed Test methods?
Login() - Failed --
Open ORange HRMs Webpage --
Enter valid user, invalid pwd , click login btn -- it will not login to ORange HRMS appl?
@Override
public void
onTestFailure(ITestResult result) {
//
TODO Auto-generated method stub
ITestListener.super.onTestFailure(result);
System.out.println("onTestFailure()
gets executed when @Test Method -failed");
System.out.println(result.getName()
+ " TC failed.Plz check the results ");
// HW
Take Screen shot of the page
//TakesScreenshot code
}
No comments:
Post a Comment