How to run the same method multiple times using the invocationCount in TestNG
File: KWTestNG.java
package tests; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.Test; public class KWTestNG { @Test(invocationCount = 3) public void NavigateLogin() { System.setProperty("webdriver.chrome.driver", "/home/kodingwindow/drivers/chromedriver"); WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); driver.navigate().to("http://newtours.demoaut.com"); driver.findElement(By.name("userName")).sendKeys("mercury"); driver.findElement(By.name("password")).sendKeys("mercury"); driver.findElement(By.name("login")).click(); if(driver.getTitle().equals("Find a Flight: Mercury Tours:")) { System.out.println("Login Successful"); } else { System.out.println("Login Unsuccessful"); } driver.close(); } }
Output
[RemoteTestNG] detected TestNG version 7.0.0 Login Successful Login Successful Login Successful PASSED: NavigateLogin PASSED: NavigateLogin PASSED: NavigateLogin =============================================== Default test Tests run: 3, Failures: 0, Skips: 0 =============================================== =============================================== Default suite Total tests run: 3, Passes: 3, Failures: 0, Skips: 0 =============================================== Default test ( 60.167 s) NavigateLogin 1/3 (21.198 s) NavigateLogin 2/3 (19.704 s) NavigateLogin 3/3 (19.265 s)
Comments and Reactions
What Next?
How to perform load testing using the invocationCount and threadPoolSize parameters in TestNG
How to use TestNG Parameters and Data Provider for Data Driven Testing
How to run parallel tests with Selenium WebDriver and TestNG
Advertisement