Is there a way to quit the entire test suite if a condition is met in the @BeforeSuite annotation? Maybe a way to call the @AfterSuite and bypass the entire test?
I make a database call in the @BeforeSuite. If the query returns any results, I send an email and now am wanting to kill the entire test suite.
I have tried System.exit(1);
and org.testng.Assert.fail("There are unpaid invoices");
, but neither of those terminate the entire suite. My scripts are setup to run classes in parallel and when I run the test from the test.xml file, each class tries to start and opens a window and then immediately closes it.
FYI, the drivers do not get created until the @BeforeClass or @BeforeMethod (depending on the switch I created for parallel methods or classes). So in all reality, there should never even be an attempt to open a browser window.
try new SkipException("message");
this will skip the tests if the provided condition is not true.
Try the below code in beforesuite annotation method , check if the run mode of your suite is Y/N. if that's N Then throw an Exception
throw new skipException("desired Message")
Please keep it in mind don't catch the skip exception in try and catch block. otherwise it will go for the execution of testcases in that suite after throwing skip Exception
package com.qtpselenium.suiteA;
import org.testng.SkipException;
import org.testng.annotations.BeforeSuite;
import com.qtpselenium.base.TestBase;
import com.qtpselenium.util.TestUtil;
public class TestSuiteBase extends TestBase{
@BeforeSuite
public void checksuiteskip(){
//Initialize method of Test BASE Class to Initialize the logs and all the excel files
try {
Initialize();
} catch (Exception e) {
e.printStackTrace();
}
App_Logs.debug("checking run mode of SuiteA");
if( !TestUtil.isSuiterunnable(suitexlsx, "suiteA")){
App_Logs.debug("Run mode for SuiteA is N");
throw new SkipException("Run mode for suiiteA is N");
}else
App_Logs.debug("Run mode for SuiteA is Y");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With