我有一个Test方法,该方法可启动浏览器并输入一些文本并执行其余操作。现在,我想在浏览器的多个实例中运行相同的Test方法(无论是chrome还是chrome,Mozilla)。为此,我传递了要在DataProvider中每个浏览器中输入的浏览器名称和文本。
我为数据提供者尝试了parallel=true
,但是它没有按预期工作。它可以打开多个浏览器,但是来自dataprovider的数据都只能在一个浏览器中输入,而其他浏览器则保持空闲。
public class test1 {
String communityURL = "https://example.com";
@DataProvider(name = "data", parallel = true)
public Object[][] data() {
return new Object[][] { new Object[] { "Chrome", "data1" }, new Object[] { "Chrome", "data2" }
};
}
@Test(dataProvider = "data")
public void runTest(String browser, String data) throws IOException, InterruptedException {
WebDriver driver;
Properties prop = new Properties();
FileInputStream fis = new FileInputStream(System.getProperty("user.dir") + "\\locators.properties");
prop.load(fis);
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\xxxx\\Downloads\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);
driver.get(communityURL);
driver.findElement(By.xpath(prop.getProperty("xxx"))).sendKeys(data);
Thread.sleep(5000);
driver.findElement(By.xpath(prop.getProperty("xxx"))).sendKeys(data);
driver.findElement(By.xpath(prop.getProperty("xxxx"))).click();
driver.findElement(By.xpath(prop.getProperty("xxx"))).click();
Thread.sleep(3000);
}
}
我需要打开多个浏览器会话,并且每个浏览器都从dataprovider ex中获取每个值,例如:Session1:Chrome- data1和Session2:Chrome- data2