Selenium 简明教程
Selenium Grid - Overview
Selenium Grid 用于通过在多台计算机上执行执行来并行模式执行测试脚本。因此,Selenium Grid 有助于通过将命令从客户端发送至远程浏览器实例来启动测试脚本的测试执行。
Selenium Grid is used to execute test scripts in parallel mode by spinning the execution across more than one machine. Thus the Selenium Grid helps to kick off test execution of test scripts by directing the commands from the clients to the instances of the remote browser.
Selenium Grid 是一种将测试分布在多台物理机或虚拟机上以使我们可以并行(同时)执行脚本的工具。它极大地加速了测试过程,并且可在多个浏览器和平台上运行测试,并向我们提供有关产品的快速且准确的反馈。
Selenium Grid is a tool that distributes the tests across multiple physical or virtual machines so that we can execute scripts in parallel (simultaneously). It dramatically accelerates the testing process, and runs the tests across multiple browsers and platforms and gives us quick and accurate feedback on the product.
Selenium Grid 允许我们执行 * WebDriver* 或 * Selenium Remote Control* 的多个实例允许并行执行使用相同代码库的测试,因此代码不必存在于它们执行的系统上。selenium-server-standalone 包括 Hub、WebDriver 和 Selenium RC 以在网格中执行脚本。
Selenium Grid allows us to execute multiple instances of WebDriver or Selenium Remote Control allows execution of tests in parallel which use the same code base, hence the code need not be present on the system they execute. The selenium-server-standalone package includes Hub, WebDriver, and Selenium RC to execute the scripts in grid.
Selenium Grid 有一个 Hub 和一个节点。Selenium 已发布了多个版本的 Selenium Grid,最新版本是 4。Selenium Grid 4 是一种新实现,并且不使用较旧 Selenium Grid 版本的源代码。
Selenium Grid has a Hub and a Node. Selenium has released several versions of the Selenium Grid, the latest version is on 4. Selenium Grid 4 is a new implementation and does not utilize the source code of the older Selenium Grid versions.
What is a Selenium Grid?
Selenium Grid 主要用于并行测试。它遵循 hub(充当中心部分,其余部分被视为节点)和节点架构。Selenium Grid 使我们能够同时在多台计算机上执行各种测试。Selenium Grid 主要用于测试执行,而不是设计。
Selenium Grid is mainly used for parallel testing. It follows a hub(which is a central part and rest are considered as nodes) and node architecture. Selenium Grid enables us to execute varied tests in multiple machines simultaneously. Selenium Grid is used mostly with the intent of test execution rather than design.
Selenium Grid 充当代理服务器,帮助触发多台计算机上的并行执行。这是通过向远程 Web 浏览器对象提供方向来完成的。在它们中间,其中之一充当 hub。
Selenium Grid acts as a proxy server to help in triggering parallel execution across multiple machines. This is done by providing direction to the remote web browser objects. Among them, one of them works as a hub.
接下来,hub 将测试指令定向到已注册的 Selenium Grid 节点。这些测试指令主要采用 JSON 格式。hub 在创建不同计算机上的并发执行、从中心控制各个浏览器方面发挥着重要作用。
Next, the hub directs the test instructions to the Selenium Grid nodes which are registered. These test instructions are mainly in JSON format. The hub is instrumental in creating concurrent execution on different machines, controlling various browsers from the center.
Selenium Grid 允许分散执行测试用例。在设计测试用例时,其执行在开发它的同一台计算机上进行。但是,一旦测试套件中有大量测试用例,就不会再进行本地执行以节省时间。相反,利用多台服务器,本地计算机对各种服务器或计算机进行隔离并运行测试。
Selenium Grid allows scattered execution of test cases. While designing a test case, the its execution is carried out in the same machine where it is developed. However, once there are a substantial number of test cases in a test suite, local execution is not done any more to save time. Instead, multiple servers are utilized and the local machine segregates and runs the tests on various servers or machines.
Need of Selenium Grid
Selenium Grid 赋予了在多个浏览器及其各个版本、同一浏览器的多个实例和平台上执行测试脚本的权利,从而主要减少了测试用例的执行时间。Selenium Grid 允许通过在多台计算机上触发执行来更好地利用资源。
Selenium Grid gives the privilege of executing the test scripts across multiple browsers, and their various versions, more than one instance of the same browser, and platforms thereby it mainly reduces the execution time of the test cases. Selenium Grid allows better utilization of resources by triggering execution across more than one machine.
Selenium Grid 提供了创建跨浏览器测试的选项,类似于在各种浏览器和平台上同时进行一项测试,从而帮助捕获结果并对其进行研究。测试结果获取速度更快,从而有助于向正在测试的产品提供更快的反馈。
Selenium Grid gives the option to create a cross browser testing similar to a one single test working on various browsers, and platforms at one go, thereby helping in capturing results, and studying them. The test results are obtained at a faster rate thus helping in providing faster feedback to the product under test.
Components of Selenium Grid
Selenium Grid 的组件如下所示 −
The components of Selenium Grid are listed below −
Hub
它是一个从 WebDriver 客户端检索请求的服务器。它基本上服从客户端的测试命令,并同时在多个节点中远程运行测试。因此,hub 也可以理解为充当测试将被触发的中心点的服务器。Selenium Grid 仅有一个 Hub,并且它一次只能在单台计算机上启动。
It is a server that retrieves the requests from the WebDriver client. It basically obeys the test commands from the client and runs the tests remotely in multiple nodes at the same time. Thus the hub can also be understood as a server which acts as the central point where the tests would be triggered. A Selenium Grid has only one Hub and it is launched on a single machine once.
Node
它是由一个远程 WebDriver 和一个原生操作系统组成的远程连接设备。它以 * JSON* 格式获取中心请求,并借助 WebDriver 根据请求执行。节点是连接到中心并执行测试的 Selenium 实例。一个网格中可以有一个或多个节点,这些节点可以是任何 * OS* ,还可以包含任何受 Selenium 支持的浏览器。
It is device connected remotely consisting of a remote webdriver, and a native operating system. It gets the hub requests in the JSON format and performs as per the request with the help of the webdriver. Nodes are the Selenium instances that are attached to the Hub which execute the tests. There can be one or more nodes in a grid which can be of any OS and can contain any of the Selenium supported browsers.
Advantages of Selenium Grid
Selenium 网格的优点如下:
The advantage of Selenium Grid are listed below −
-
Selenium Grid is used popularly for cross browser testing and to execute tests in different browsers, instances, devices, and platforms. Thus the Selenium Grid gives the opportunity to see how the application under test responds to a wide range of browsers, platforms, and device combinations.
-
Since tests can be triggered with parallel threads the entire test suite is executed completely with a short test cycle.
-
Since the test cycles are shorter, Selenium Grid gives quicker results to the project stakeholders and to conclude how the application is developed.
-
Selenium Grid test cases are flexible, easy to maintain, scalable, and give better test coverage within a short time.
Example
让我们举一个 Selenium 网格设置的示例,其中有两个节点。第一个节点具有最新版本的 Chrome,而另一个节点具有 Firefox(但不是最新版本)。随着测试的进行,Selenium 网格会将测试分配给针对配置的浏览器执行。
Let us take an example of a Selenium Grid set up where there are two nodes. The first node has the latest version of Chrome, and the other node has Firefox (but not the latest version). As the test is running, the Selenium Grid assigns the tests to execute against configured browsers.
配置应该是这样的,即使测试套件有大量的测试,也可以加速测试执行。Selenium 网格长期以来一直是 Selenium 的原生部分。
The configuration should be such that execution of tests is accelerated even with the test suite having a large number of tests. Selenium Grid a native part of the Selenium for a long time.
还必须指出,Selenium 网格允许跨平台设置配置。这意味着,如果中心在 Mac 的 Safari 浏览器上执行测试,那么一个节点可以在 Windows 中的 Chrome 浏览器上执行测试,另一个节点可以在 Ubuntu 中的 Firefox 浏览器上运行测试。
It must also be noted that Selenium Grid allows configuration to be set across platforms. This implies that if the hub executes tests on the Safari browser of the Mac, one node can execute tests on the Chrome browser in Windows, and another node can run tests on the Firefox browser in Ubuntu.
conclusion
这就结束了我们对 Selenium 网格概述教程的全面了解。我们首先描述了什么是 Selenium 网格、为什么需要 Selenium 网格、Selenium 网格的组件、Selenium 网格的优点以及配置 Selenium 网格的示例。这使你深入了解 Selenium 网格概述。明智的做法是继续实践你所学到的内容,并探索与 Selenium 相关的其他内容,以加深你的理解力并拓展你的视野。
This concludes our comprehensive take on the tutorial on Selenium Grid Overview. We’ve started with describing what is a Selenium Grid, why is a Selenium Grid needed, what are the components of a Selenium Grid, advantages of Selenium Grid, and examples to walk through how to configure Selenium Grid. This equips you with in-depth knowledge of the Selenium Grid Overview. It is wise to keep practicing what you’ve learned and exploring others relevant to Selenium to deepen your understanding and expand your horizons.