[英]Selenium Run multiple browser instances parallely
if (platform != null) {
for (final String p : platform) {
log.info("Platform " + p);
executorService.submit(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
runService(p, config, url, title, report);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
executorService.shutdown();
executorService.awaitTermination(Long.MAX_VALUE,
TimeUnit.NANOSECONDS);
// for(final String p: platform){
// runUIService(p, config, url, title, report);
// }
}
public void runService(){
WebDriver driver = getDriver();
//some selenium operations performed
}
I am trying to execute runService() in multiple threads parallelly. 我试图在多个线程中并行执行runService()。 getDriver() method returns a new instance of selenium WebDriver.
getDriver()方法返回Selenium WebDriver的新实例。 If I execute for a single platform all the selenium operations run successfully, but if the same code is fired for multiple platforms although a new browser instance is opened for each platform, I am getting a lot of errors on selenium elements not found.
如果我在单个平台上执行所有硒操作,则成功运行,但是,尽管为每个平台打开了新的浏览器实例,但在多个平台上触发了相同的代码,则硒元素上将出现很多错误。 I am not able to figure what can be the reason for this ?
我不知道这可能是什么原因? Is there a problem associated with running multiple browser instances through selenium at the same time ?
通过selenium同时运行多个浏览器实例是否存在问题?
I think this is a concurrency issue. 我认为这是一个并发问题。 Have you tried using synchronized keyword for your method?
您是否尝试过对方法使用synced关键字? ie public synchronized void runService()
即公共同步void runService()
or in your getDriver() method. 或在您的getDriver()方法中。
Hope this can help. 希望这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.