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

标签 c# selenium-grid

我正在运行一个测试:

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 控制台 View 中,我可以看到一个 Firefox 浏览器正在运行。如何在节点上并行使用多个浏览器?

我正在使用 Grid2 维基页面 found here

最佳答案

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

根据这个网站:-

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.

编辑: 上面给出的站点是针对 Selenium 1.x 版本的,而不是针对 Grid 2.0 的。但是,运行并行测试的基本概念保持不变

编辑2: 步骤和示例程序如下。请注意,这是一个非常基本的测试,只是为了向您展示 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 个测试。 :)

关于c# - 如何使用 Selenium Grid2 在一个集线器上运行多个浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6916029/

相关文章:

c# - 提供程序 'SqlServer-20' 没有元数据信息

linux - 通过 Linux 服务器运行 Selenium 测试

selenium - Zalenium:OpenShift环境中的504网关超时

selenium - 在 Selenium 中为远程 Webdriver 设置设备宽度

c# - 秒表计时异步/等待方法不准确

c# - 当数据过大时,发布请求不起作用 .net 核心 web api

java - 如何使用远程驱动程序从 Selenium 2 gird 中的输入 html 标记中选择文件

selenium - 如何在docker-compose.yml中配置Selenium Grid(最大 session 数)

c# - 如何通过 UserControl 参数管理控件的宽度?

c# - FxCop 对我在 NON-Team System Visual Studio 的资源中使用格式字符串提出异议