1

My code is like this:

@BeforeMethod
public void beforeMethod() {
   url= GetUrlBasedOnParameter(parameter);
   if(is.empty(url)) {
      SkipTest();
   } else {
      ExecuteTest();
   }
}

What condition can I use in SkipTest() so that without adding any additional parameters in @Test annotation, I can skip the test?

FYI: I tried driver.quit() and driver.close() but the @Test annotation is still executed.

frianH
  • 7,295
  • 6
  • 20
  • 45
Sagar Jani
  • 161
  • 2
  • 3
  • 21

1 Answers1

1

In TestNG, you can use

throw new SkipException("message");

So, your @BeforeMethod could look like

@BeforeMethod
public void beforeMethod() {
   url= GetUrlBasedOnParameter(parameter);
   if(is.empty(url)) {
      throw new SkipException("URL is empty");
   } else {
      ExecuteTest();
   }
}
Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
  • 1
    Thanks for the solution. The browser was still active so I added ```quit()``` method before the exception call. – Sagar Jani Jun 17 '20 at 06:58