如何使用 Selenium Grid2 在一个集线器上运行多个浏览器

发布于 2024-11-28 01:49:02 字数 598 浏览 1 评论 0原文

我正在运行一个测试:

DesiredCapabilities capability = DesiredCapabilities.Firefox();
                IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capability);

                ISelenium selenium = new WebDriverBackedSelenium(driver, "http://localhost/");
                selenium.Start();

这将运行 Firefox 浏览器,并且在 http://localhost:4444/grid/console Web 控制台视图中我可以看到一个 Firefox 浏览器正在运行。如何在节点上并行使用多个浏览器?

我正在使用 Grid2 wiki 页面在此处找到

I'm running a test:

DesiredCapabilities capability = DesiredCapabilities.Firefox();
                IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capability);

                ISelenium selenium = new WebDriverBackedSelenium(driver, "http://localhost/");
                selenium.Start();

This runs the Firefox browser, and in the http://localhost:4444/grid/console web console view I can see that one Firefox browser is running. How can I use more than one browser on the node in parallel?

I'm using the Grid2 wiki page found here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小姐丶请自重 2024-12-05 01:49:03

您需要同时触发 5 个测试 - 所有测试都指向同一个集线器,才能使用所有浏览器。在接收到来自不同测试的命令后,集线器会将这些命令传递给与功能匹配的 RC。您可以在此页面中查看更多详细信息: http://selenium-grid.seleniumhq.org/how_it_works .html

根据此网站:-

当然,要真正利用 Selenium Grid,您需要
并行运行您的测试。如果您正在编写 Selenium 测试
Java,您可以利用 TestNG 并行运行或并行 JUnit。如果你
更喜欢用 Ruby 编写 Selenium 测试,你可能想看看
进入 DeepTest 或生成多个进程。很可能你的
最喜欢的编程语言和开发平台已经有了
解决方案。

编辑:
上面给出的站点适用于 Selenium 1.x 版本,不适用于 Grid 2.0。但是,运行并行测试的基本概念仍然相同

EDIT2:
步骤和示例程序如下。请注意,这是一个非常基本的测试,仅向您展示 Grid 如何并行运行测试。

第 1 步 - 启动 Grid Hub
java -jar selenium-server-standalone.jar -role hub

第 2 步 - 启动 RC 节点。 例如,我们使用的测试是 webdriver 测试。所以我们需要启动webdriver节点。该命令将启动一个支持 5 个 firefox 浏览器、5 个 googlechrome 和 1 个 IE 浏览器的 webdriver 节点。这是 webdriver 的默认配置。

java -jar selenium-server-standalone.jar -role wd -hub http://localhost:4444/grid/register

第 3 步 - 创建 5 个独立的程序,类似于下面给出的程序。该程序采用 JAVA 语言。您需要将其更改为您需要的语言。将类名称更改为 Program2、Program3 等。如前所述,这不是并行运行测试的最佳方法。您需要使用 testNG 或 jUnit 同时触发多个测试。由于这本身就是一个不同的主题,因此我不会在这里进行解释。

public class Program1{
        public static void main(String args[]){

            WebDriver wd;
            //Assign a remotewebdriver object to webdriver with firefox capability
            wd=new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),DesiredCapabilities.firefox());
            wd.get("http://www.google.com");
            //Sleep for 2 seconds so that RC will not be released. This is to demonstrate Hub using multiple RCs
            Thread.sleep(120000);
            //Close webdriver
            wd.quit();

        }
    }

第 4 步 - 同时运行所有 5 个程序。

第 5 步 - 观看网格并行运行 5 个测试的神奇效果。 :)

You need to trigger 5 tests simultaneously - all pointing to the same hub, to use all the browsers. On receiving the commands from different tests, hub would pass those commands to RCs matching the capability. You can see more details in this page : http://selenium-grid.seleniumhq.org/how_it_works.html.

Per this site:-

Of course to really take advantage of the Selenium Grid, you need to
run your tests in parallel. If you are writing your Selenium tests in
Java, you can leverage TestNG parallel runs or Parallel JUnit. If you
prefer to write your Selenium tests in Ruby, you might want to look
into DeepTest or spawn multiple processes. Chances are that your
favorite programming language and development platform already have a
solution.

EDIT:
The above given site was for Selenium 1.x version and not for Grid 2.0. However, the underlying concept for running parallel tests remains the same

EDIT2:
Steps and example programs are below. Please note that this is a very basic test ONLY to show you how Grid runs tests in parallel.

Step1 - Start Grid Hub
java -jar selenium-server-standalone.jar -role hub

Step2 - Start RC nodes. The tests which we are using for example are webdriver tests. So we need to start webdriver nodes. This command would start a webdriver node which supports 5 firefox browsers, 5 googlechrome and 1 IE browser. This is the default config for webdriver.

java -jar selenium-server-standalone.jar -role wd -hub http://localhost:4444/grid/register

Step 3- Create 5 separate programs similar to the one given below. This program is in JAVA. You need to change it to the language you need. Change class name to Program2,Program3 etc. As mentioned earlier, this is not the best way to run tests in parallel. You need to use testNG or jUnit to trigger multiple tests at the same time. Since that is a different topic by itself am not going to explain it here.

public class Program1{
        public static void main(String args[]){

            WebDriver wd;
            //Assign a remotewebdriver object to webdriver with firefox capability
            wd=new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),DesiredCapabilities.firefox());
            wd.get("http://www.google.com");
            //Sleep for 2 seconds so that RC will not be released. This is to demonstrate Hub using multiple RCs
            Thread.sleep(120000);
            //Close webdriver
            wd.quit();

        }
    }

Step 4 - Run all 5 programs simultaneously.

Step 5 - Watch the grid doing the magic of running 5 tests in parallel. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文