This article will show how we can skip a test in TestNG.We can skip tests using a simple parameter called (enabled = false) at @Test. By default, this parameter is enabled to be true.
package week4.day2;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import io.github.bonigarcia.wdm.WebDriverManager;
public class PopUp {
@Test
private void test1() {
System.out.println("I came Before");
}
@Test
private void test2() {
System.out.println("I come After");
}
@Test(enabled = false)
public void popUp() throws Throwable {
WebDriverManager.chromedriver().setup();
ChromeDriver driver = new ChromeDriver();
driver.get("https://www.programsbuzz.com/");
driver.manage().window().maximize();
Thread.sleep(3000);
List<WebElement> elementTexts = driver.findElements(By.xpath("//div[@class='header__main__left']"));
for (WebElement webElement : elementTexts) {
System.out.println(webElement.getText());
}
}
}
- Consider this scenario, and we want to skip the popup method here.
- So we used the parameter (enabled = false).
- We can see here the two methods other than the popup ran here.
- This is how we can skip tests in TestNG.
- Log in to post comments