How to perform load testing using the invocationCount and threadPoolSize parameters 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 = 100, threadPoolSize = 100) //for load testing @Test(invocationCount = 5, threadPoolSize = 3) public void NavigateLogin() { System.out.println("\nThread Name: "+Thread.currentThread().getName()+"\nThread ID: "+Thread.currentThread().getId()); 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 Thread Name: TestNG-methods-3 Thread ID: 13 Thread Name: TestNG-methods-2 Thread ID: 12 Thread Name: TestNG-methods-1 Thread ID: 11 Login Successful Thread Name: TestNG-methods-2 Thread ID: 12 Login Successful Thread Name: TestNG-methods-3 Thread ID: 13 Login Successful Login Successful Login Successful PASSED: NavigateLogin PASSED: NavigateLogin PASSED: NavigateLogin PASSED: NavigateLogin PASSED: NavigateLogin =============================================== Default test Tests run: 5, Failures: 0, Skips: 0 =============================================== =============================================== Default suite Total tests run: 5, Passes: 5, Failures: 0, Skips: 0 =============================================== Default test ( 118.707 s) NavigateLogin (24.129 s) NavigateLogin (26.997 s) NavigateLogin (29.213 s) NavigateLogin (18.996 s) NavigateLogin (19.372 s)
Comments and Reactions
What Next?
How to use TestNG Parameters and Data Provider for Data Driven Testing
How to run parallel tests with Selenium WebDriver and TestNG
How to use and implement TestNG Listeners
Advertisement