Is it possible to stop or skip whole suite execution if a particular test fails

120 views
Skip to first unread message

Abhay

unread,
Nov 19, 2021, 7:58:52 AM11/19/21
to testng-users
My test performs validation on browser UI as well as device (as backend). Sometime, device goes offline. It does not make sense for me run tests when device is offline.

As of now, I checking device is online in every test method. I want to check device status as first test & skip or stop suite execution if first test fails.

I can not put this code in beforeSuite() method, due to framework limitation.

Any other way, I can handle this.

Krishnan Mahadevan

unread,
Nov 21, 2021, 10:58:30 PM11/21/21
to testng...@googlegroups.com

In simple terms you could the following:

 

  1. Build an implementation of ITestListener.
  2. Within this implementation, add a logic within onTestFailure() that basically sets an attribute at the ITestContext level indicating that a test had a failure.
  3. Within the same implementation, inside onTestStart() check if the current ITestContext has the failure indicating attribute set. If attribute is set, then throw a SkipException.

 

That should perhaps take care of this need of yours.

 

PS: Please ensure that you are using the latest released TestNG version (7.4.0 as of today).

 

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribblings @ https://rationaleemotions.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/a0051ad3-2615-412f-ab65-caca913912f1n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages