简体   繁体   中英

How to Perform load Testing with Selenium TestNG at a time by opening multiple windows

I have executed the below code to perform load test

 @Test(invocationCount = 5, threadPoolSize = 1)
 public void GmailLogin() throws InterruptedException {

 System.setProperty("webdriver.chrome.driver", "D:\\CIPL0564\\D 
Drive\\Software\\chromedriver_win32\\chromedriver.exe");
 driver = new ChromeDriver();
 driver.manage().window().maximize();
driver.get("https://tst-oec-ebooking.azurewebsites.net/");
driver.manage().timeouts().implicitlyWait(6000, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id=\"Email\"]")).sendKeys("mad@dayrep.com");
driver.manage().timeouts().implicitlyWait(6000, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id=\"Password\"]")).sendKeys("Pass@123");
driver.findElement(By.xpath("//*[@id=\"login_submit\"]")).click();
Thread.sleep(1500);
driver.manage().timeouts().implicitlyWait(5000, TimeUnit.SECONDS);
driver.quit();

}

It executed 5 times with no errors but one after other.I need to execute this at a time by opening multiple windows. I have tried by giving threadPoolSize = 5,but i got error as session not created.

TestNG runner would create just one test class instance for all test methods run. This logic also occurs when running in parallel. It seems like your WebDriver object is defined globally, so in each invocation when you call "driver = new ChromeDriver()" it overrides the other.

My advice for you is to use ThreadLocal object to define your WebDriver sessions. In that way, each WebDriver object in given thread acts as independent data set. See this link http://seleniumautomationhelper.blogspot.com/2014/02/initializing-webdriver-object-as-thread.html for more detailed explanation about this subject.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM