Thursday, 9 February 2017

SELENIUM: Invocation count IN TESTNG(How to execute a test case multiple number of times)


Invocation count in testng:

InvocationCount:


This attribute present in @Test.
The number of times this method should be invoked.
We can execute the test method mutiple time by specifying 'invocationCount'.

InvocationTimeOut:
This attribute present in @Test.
The maximum number of milliseconds this test should take for the cumulated time of all invocationCounts.
This attribute will be ignored if invocationCount is not specified.
syntax:
@Test(invocationCount=numberoftimes,invocationTimeOut=numberOfMilliseconds)
public void test()
{
;;;;;;
}
  
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 InvocationCountDemo {
         
          @BeforeMethod
          public void before()
          {
                   System.out.println("Before test running");
          }
          @AfterMethod
          public void after()
          {
                   System.out.println("After test running");
          }
         
          @Test(invocationCount=2,invocationTimeOut=30)
          public void execute() throws InterruptedException
          {
                   System.setProperty("webdriver.gecko.driver", "C:\\Users\\ramesh\\Desktop\\java\\desk\\geckodriver-v0.11.1-win64\\geckodriver.exe");
                   WebDriver driver=new FirefoxDriver();
                   driver.manage().window().maximize();                   driver.manage().timeouts().implicitlyWait(50,TimeUnit.SECONDS);                  
                   driver.get("https://www.gmail.com");                                      driver.findElement(By.id("Email")).sendKeys("rameshsoft.selenium");                  
                   driver.findElement(By.id("next")).click();
                   Thread.sleep(2000);
                   driver.findElement(By.id("Passwd")).sendKeys("12345");
                   driver.findElement(By.id("signIn")).click();                  
                   driver.quit();
          }

}

No comments:

Post a Comment