Scenario:-We have a test case in the test set, which is not ready for testing and we wont this test case to be disabled while Selenium is executing the complete test suite.

Solution:-
We can disabled the test case in TestNG using enabled property.

Syntax
@Test(enabled=false)
By default it is enabled= true

Code:-

XML file:-

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite">
<test name="uftHelp">
<classes>
<class name="TestNG_Learning.DisableTest"/>
</classes>
</test>
</suite>


Java:-

package TestNG_Learning;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class DisableTest {
private WebDriver driver;

@Test
public void login() {
//Fill the UserName and Password fields
driver.findElement(By.id("userName")).sendKeys("uftHelp");
driver.findElement(By.id("password")).sendKeys("Password");
}
//Test is disabled
@Test(enabled=false)
public void signIn() {
//Click the Sign in Button
driver.findElement(By.id("SignIn")).click();
//Clicking on the alert message
driver.switchTo().alert().accept();
}

@BeforeMethod
public void beforeMethod() {
driver = new FirefoxDriver();
//Adding Implicit wait
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//Maximize browser
driver.manage().window().maximize();
//Open the Login Application
driver.get("http://www.ufthelp.com/p/testpage.html");
}

@AfterMethod
public void afterMethod() {
//Closing the browser
driver.quit();
}

}



Output:-

enabled=false example testng
Output result have missing “signIn” test case 

More practical scenarios

Leave a Reply

Your email address will not be published. Required fields are marked *