If we don’t want execute specific test Method while executing entire
script, we can use TestNG annotation @Test(enabled = false). This TestNG
annotation allows us to ignore specific test.
In which all scenarios we can use TestNG annotation @Test(enabled =
false) ? :
- some time specific test may be outdated,
- code is not yet ready
@Test(enabled = false): If a test method is annotated with
@Test(enabled = false), then the test that is not ready to test is
ignored.
@Test(enabled =true): If a test method is annotated with
@Test(enabled =true), then the test will get execute
Now, let’s see how to ignore TestNG test using a script.
TestMethod 1: with @Test(enabled =true)
@Test(enabled=true)
public void openMyBlog()
{
driver.get("https://mahantesh-hadimani.blogspot.com/");
}
TestMethod 2: with @Test(enabled = false)
@Test(enabled=false)
public void openGoogle()
{
driver.get("https://mahantesh-hadimani.blogspot.com/");
}
testng.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Test">
<classes>
<class name="testCases.TestCase_1"/>
</classes>
</test>
</suite>
Complete Script:
package testCases;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TestCase_1 {
public WebDriver driver;
@Test(enabled=true)
public void openMyBlog() {
driver.get("https://mahantesh-hadimani.blogspot.com/");
}
@Test(enabled=false)
public void openGoogle() {
driver.get("https://mahantesh-hadimani.blogspot.com/");
}
@BeforeClass
public void beforeClass() {
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
driver = new ChromeDriver();
}
@AfterClass
public void afterClass() {
driver.quit();
}
}
TestNg Output:
Console Output:
No comments:
Post a Comment
If any suggestions or issue, please provide