Selenium Grid 2:本地集线器和 2 个本地节点 [英] Selenium Grid 2 : Local hub and 2 local nodes

查看:40
本文介绍了Selenium Grid 2:本地集线器和 2 个本地节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在设置 Selenium Grid 以在集线器上运行测试套件,并将这些测试分发到节点上.

Currently, I am setting up a Selenium Grid for running test suites on a hub and distribute these tests over the nodes.

这个想法是让测试在集线器上执行并分布在 10 个节点上以进一步执行它们.对于初学者和评估网格,我设置了一个本地集线器和 2 个本地节点.

The idea is to get the test executed on the hub and distributed over 10 nodes to execute them further. For the starters and evaluate the grid, I have set up a local hub and 2 local nodes.

在我的测试类中,我有 4 个测试,在使用 RemoteDriver 运行测试并将集线器作为 URL 和配置的功能传递时,它在 Node1 上执行所有四个测试,并且不会将其分发到 Node2.此外,它在 Node1 上连续运行所有 4 个测试.有谁知道这里可能有什么问题.请在下面找到设置.

In my test class, I have 4 tests, on running the test using RemoteDriver and passing the hub as URL and configured capabilities, it executes all four tests on Node1 and does not distribute it over to Node2. Also, it runs all 4 tests serially on Node1. Does any one know what could be wrong here. Please find the setup below.

集线器配置:

C:\Proto\Selserversidedjars>java 
    -jar selenium-server-standalone-2.44.0.jar 
    -role hub -hubConfig DefaultHub.json

节点 1 配置:

C:\Proto\Selserversidedjars>java 
    -jar selenium-server-standalone-2.44.0.jar  
    -role node  
    -hub http://localhost:4444/grid/register

节点 2 配置:

C:\Proto\Selserversidedjars>java 
    -jar selenium-server-standalone-2.44.0.jar 
    -role node 
    -nodeConfig DefaultNode1.json 
    -port 6666

Defaulthub.json :

Defaulthub.json :

{
  "host": null,
  "port": 4444,
  "newSessionWaitTimeout": -1,
  "servlets" : [],
  "prioritizer": null,
  "capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
  "throwOnCapabilityNotPresent": true,
  "nodePolling": 5000,

  "cleanUpCycle": 5000,
  "timeout": 300000,
  "browserTimeout": 0,
  "maxSession": 5,
  "jettyMaxThreads":-1
}

DefaultNode1.json:

DefaultNode1.json:

{
  "capabilities":
      [
        {
          "browserName": "*firefox",
          "maxInstances": 5,
          "seleniumProtocol": "Selenium"
        },
        {
          "browserName": "*googlechrome",
          "maxInstances": 5,
          "seleniumProtocol": "Selenium"
        },
        {
          "browserName": "*iexplore",
          "maxInstances": 1,
          "seleniumProtocol": "Selenium"
        },
        {
          "browserName": "firefox",
          "maxInstances": 5,
          "seleniumProtocol": "WebDriver"
        },
        {
          "browserName": "chrome",
          "maxInstances": 5,
          "seleniumProtocol": "WebDriver"
        },
        {
          "browserName": "internet explorer",
          "maxInstances": 1,
          "seleniumProtocol": "WebDriver"
        }
      ],
  "configuration":
  {
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "maxSession": 5,
    "port": 6666,
    "host": ip,
    "register": true,
    "registerCycle": 5000,
    "hubPort": 4444,
    "hubHost": ip
  }
}

现在在这些配置设置之后,我的集线器在端口 4444 上启动,节点 1 从 5555 启动,节点 2 从 6666 启动.在我的 TestNG 测试中,我试图执行 4 个测试.鉴于我有多个测试要在一个类中运行,是否可以将这些测试分布到多个节点或单个节点上的多个实例上?

Now after these configuration setup, my hub is started on port 4444, node 1 is started at 5555, node 2 is started at 6666. In my TestNG tests, I am trying to execute 4 tests. Given that I have multiple tests to run in a single class, is it possible to distribute those tests over multiple nodes or multiple instances on a single node?

关于在这种情况下如何在 Node1 上执行多个实例并将测试(假设超过 10 个测试)分发到 Node2"的任何帮助将不胜感激.

Any help on "how to execute multiple instances on Node1 and distribute tests(let's say more than 10 tests) over to the Node2 in this situation" will be highly appreciated.

提前致谢!

推荐答案

串行或并行运行取决于您如何触发测试,并且不会仅通过使用网格自动发生.网格只是帮助在各个节点上分发测试——如果测试是串行发送的,它将串行分发,如果并行发送,它将分发到各个节点.

Running serially or parallely depends on how you are triggering your tests and just doesn't happen automatically just by using the grid. Grid just helps in distributing tests over various nodes - if tests are sent serially it would distribute serially, if sent parallely, it would distribute on various nodes.

您可以考虑使用 TestNG 并行运行您的测试,或者您可以冒险实现自己的并行性.

You might consider using TestNG to run your tests parallely or you can venture to implement your own parallelism.

您提到您的单个类有多个测试 - 使用 testng,您可以将并行属性设置为方法,这些方法将触发各个线程中的每个测试,这些线程将发送到网格,集线器将负责挑选一个空闲节点并执行您的测试.

You mention your single class has multiple tests - with testng, you can set the parallel attribute to methods which would trigger each test in individual threads which would be sent to the grid and the hub would take care of picking up a free node and executing your test.

注意编写线程安全驱动程序启动代码,以便每个线程都有自己的驱动程序实例.

Take care to write threadsafe driver launch code so that each thread has it's own driver instance.

这篇关于Selenium Grid 2:本地集线器和 2 个本地节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆