我已经执行以下代码来执行负载测试

 @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("[email protected]");
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();


}

它执行了5次,没有错误,但一次又一次。我需要一次打开多个窗口来执行一次。
我已经尝试通过给threadPoolSize = 5来尝试,但是由于未创建会话而出现错误。

最佳答案

TestNG运行程序只为所有运行的测试方法创建一个测试类实例。并行运行时也会发生此逻辑。似乎您的WebDriver对象是全局定义的,因此在每次调用“ driver = new ChromeDriver()”时,它都会覆盖另一个对象。

我的建议是使用ThreadLocal对象定义WebDriver会话。这样,给定线程中的每个WebDriver对象都充当独立的数据集。
有关此主题的更多详细说明,请参见此链接http://seleniumautomationhelper.blogspot.com/2014/02/initializing-webdriver-object-as-thread.html

09-30 14:57
查看更多