简体   繁体   English

Selenium并行运行多个浏览器实例

[英]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.

相关问题 如何在没有硒网格的情况下在浏览器的多个实例中并行运行单个测试用例 - How to run single test case in multiple instances of browser parallelly without selenium grid 我可以使用单个驱动程序在 Selenium (Java) 中并行运行多个测试吗? - Can I use a single driver to run parallely multiple tests in Selenium (Java)? 是否在同一会话中运行多个浏览器实例 - Do multiple browser instances run in same session 如何使用Selenium Java在同一台机器上并行运行方法或类 - how to run methods or classes parallely on same machine using selenium java 如何在3个不同的浏览器中在同一台PC上并行运行selenium html套件? - how to run selenium html suite parallely on same pc in 3 different browsers? 硒; 如何运行多个实例并维护不同的会话 - Selenium; How to run multiple instances and maintain different session 多个Selenium Grid 2测试:如何在带有隐藏Windows浏览器的Firefox中运行 - Multiple Selenium Grid 2 Test: how to run in Firefox with hidden windows Browser 我们可以在一个浏览器中运行多个Selenium WebDriver脚本吗? - can we run multiple selenium WebDriver scripts in a single browser? 我可以在 java 的父选项卡和子选项卡中同时运行测试吗? (硒 TestNG) - Can I able to run the test parallely in both parent and child tab in java ? (selenium TestNG ) 如何使用 Selenium 运行 Chromium 浏览器? - How to run a Chromium Browser with Selenium?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM