【问题标题】:What is the exact purpose of Selenium Grid?Selenium Grid 的确切用途是什么?
【发布时间】:2020-04-26 02:43:29
【问题描述】:

我是 Selenium、TestNG 和 Selenium Grid 的新手。我对何时需要使用 Selenium Grid 感到有些困惑。以下是我对此的理解。如果我是对的,请告诉我:

  1. Selenium Grid用于在另一台机器上远程运行测试
  2. 如果我需要在本地计算机上并行运行测试,则无需使用 Grid。这可以通过仅使用 TestNG 来实现
  3. 如果我需要在不同的远程机器上并行执行我的测试,那么我必须使用 selenium Grid 和 TestNG。

所以我的理解是,Selenium 网格的目的不是并行执行。它用于远程执行。 并行执行是通过 TestNG 实现的仅使用 Grid 是不可能进行并行执行的。这是正确的吗?

【问题讨论】:

    标签: selenium selenium-webdriver webdriver selenium-grid


    【解决方案1】:

    您的结论非常正确,Selenium Grid 的目的是在远程机器上远程执行测试。分发测试的两个主要原因是:


    远程网络驱动程序

    根据Remote WebDriver的官方文档:

    您可以像在本地使用 WebDriver 一样远程使用它。主要区别在于需要配置远程 WebDriver,以便它可以在单独的机器上运行您的测试。

    远程 WebDriver 由两部分组成:服务器和客户端。客户端是 WebDriver 测试,服务器只是一个 Java servlet,可以托管在任何现代 JEE 应用服务器中。


    远程 WebDriver 服务器

    Remote WebDriver server 将始终在装有您要测试的浏览器的机器上运行。可以从命令行(或通过代码配置)启动服务器。


    远程 WebDriver 客户端

    要运行Remote WebDriver client,您必须先连接到 RemoteWebDriver。为此,我们将 URL 指向运行我们测试的服务器的地址。


    详细步骤

    您需要按照以下步骤操作:

    • 启动Selenium Grid Hub

      java -jar selenium-server-standalone-3.141.59.jar -role hub
      
    • 生成的日志:

      18:10:13.310 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
      18:10:13.618 INFO [GridLauncherV3.lambda$buildLaunchers$5] - Launching Selenium Grid hub on port 4444
      2020-01-02 18:10:14.605:INFO::main: Logging initialized @2136ms to org.seleniumhq.jetty9.util.log.StdErrLog
      18:10:15.504 INFO [Hub.start] - Selenium Grid hub is up and running
      18:10:15.509 INFO [Hub.start] - Nodes should register to http://192.168.1.125:4444/grid/register/
      18:10:15.510 INFO [Hub.start] - Clients should connect to http://192.168.1.125:4444/wd/hub
      
    • 通过 url http://localhost:4444/grid/console 访问 Selenium Grid Console v.3.141.59

    • 启动Selenium Grid 节点

      java -Dwebdriver.chrome.driver=chromedriver.exe -jar selenium-server-standalone-3.141.59.jar -role node -port 7777 -hub http://192.168.1.125:4444/grid/register
      
    • 生成的日志:

      18:33:55.959 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
      18:33:56.112 INFO [GridLauncherV3.lambda$buildLaunchers$7] - Launching a Selenium Grid node on port 7777
      2020-01-02 18:33:56.584:INFO::main: Logging initialized @983ms to org.seleniumhq.jetty9.util.log.StdErrLog
      18:33:56.913 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
      18:33:57.029 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 7777
      18:33:57.029 INFO [GridLauncherV3.lambda$buildLaunchers$7] - Selenium Grid node is up and ready to register to the hub
      18:33:57.195 INFO [SelfRegisteringRemote$1.run] - Starting auto registration thread. Will try to register every 5000 ms.
      18:33:57.734 INFO [SelfRegisteringRemote.registerToHub] - Registering the node to the hub: http://192.168.1.125:4444/grid/register
      18:33:57.856 INFO [SelfRegisteringRemote.registerToHub] - The node is registered to the hub and ready to use
      
    • 再次通过urlhttp://localhost:4444/grid/console访问Selenium Grid Console v.3.141.59查看注册节点:

    【讨论】:

      猜你喜欢
      • 2014-11-23
      • 1970-01-01
      • 2016-08-26
      • 2023-04-01
      • 2012-09-03
      • 2012-04-04
      • 1970-01-01
      • 2019-09-21
      • 1970-01-01
      相关资源
      最近更新 更多