How To Enable/Disable @Test Method In Selenium WebDriver Using TestNG

TestNG has really practiced characteristic to enable or disable selenium webdriver @Test method. During exam execution, If y'all create non wants to execute specific @Test method from exam class thence y'all tin conduct disable It using TestNG property enabled = false. It Is something similar excluding @Test method from execution equally described In THIS POST.

Let us endeavour to Implement It practically. In bellow given exam case, I accept used @Test(priority=1,enabled = false) alongside method testCaseOne_Test_One(). Here, enabled = faux belongings Is used for disabling that @Test method from execution.

Create bellow given exam class as well as testng.xml file In your eclipse as well as run It.

1. Test_One.java
package Testing_Pack; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;  world class Test_One {  WebDriver driver;  WebElement dragElementFrom;   @BeforeTest  world void setup() throws Exception {   System.out.println("In @BeforeTest Of Test_One.");   driver =new FirefoxDriver();        driver.manage().window().maximize();   driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);   driver.get(" ");  }    @Test(priority=1,enabled = false)  world void testCaseOne_Test_One() {   System.out.println("Executing testCaseOne_Test_One.");   driver.findElement(By.xpath("//input[@id='2']")).click();   driver.findElement(By.xpath("//input[@id='plus']")).click();   driver.findElement(By.xpath("//input[@id='6']")).click();   driver.findElement(By.xpath("//input[@id='equals']")).click();   String Result = driver.findElement(By.xpath("//input[@id='Resultbox']")).getAttribute("value");   System.out.println("Result of testCaseOne_Test_One = "+Result);  }    @Test(priority=2)  world void testCaseTwo_Test_One() {   System.out.println("Executing testCaseTwo_Test_One.");   driver.findElement(By.xpath("//input[@id='Resultbox']")).clear();   driver.findElement(By.xpath("//input[@id='3']")).click();   driver.findElement(By.xpath("//input[@id='plus']")).click();   driver.findElement(By.xpath("//input[@id='7']")).click();   driver.findElement(By.xpath("//input[@id='equals']")).click();   String Result = driver.findElement(By.xpath("//input[@id='Resultbox']")).getAttribute("value");   System.out.println("Result of testCaseTwo_Test_One = "+Result);  } }


testng.xml
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="Parallel Class Suite" parallel="classes" thread-count="2">   <test name="Parallel Class Test" >     <classes>       <class name="Testing_Pack.Test_One"/>           </classes>   </test> </suite>

Test execution number volition looks similar bellow. If y'all tin meet In bellow Image, exclusively  testCaseTwo_Test_One() method has been executed because testCaseOne_Test_One() @Test method Is disabled thence TestNG volition exclude It from execution.


More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post