Selenium 简明教程
Selenium - Components
Selenium 组件通常被称为 Selenium 工具套件。总共有四个工具被共同称为 Selenium 组件。让我们讨论 Selenium 中的各种组件 -
Selenium Components are often referred to as a suite of Selenium tools. There are a total of four tools which are together called the Selenium Components. Let us discuss the various components of Selenium −
-
Selenium IDE
-
Selenium RC
-
Selenium Webdriver
-
Selenium Grid
Selenium IDE
Selenium 集成开发环境是 Selenium 套件中的一项重要内容。它最初作为一个 Firefox 插件进行开发,但现在可以在 Firefox 和 Chrome 浏览器中使用。下面列出 Selenium IDE 的一些特性 -
Selenium Integrated Development Environment is an important part of the Selenium suite. It was first developed as a Firefox plugin, however now it is available in both Firefox and Chrome browser. Some of the features of Selenium IDE are listed below −
-
The recording, debugging, executing and editing of the functional tests can be done in Selenium IDE.
-
The scripts in Selenium IDE are developed in Selenese which is a scripting language in Selenium.
-
Selenium IDE commands help us to perform tasks like clicking a button or link, taking input in an edit box, obtaining a text from a webelement and so on.
-
Selenium IDE tests can be converted to formats like Java, C#, Python, TestNG, and so on. Its default format is in .html.
-
Selenium IDE tests can be exported and used in Selenium Webdriver and Selenium RC.
-
Selenium IDE does not require technical or programming knowledge. Hence it can be used only testing simple scenarios and not used to cover any complex use cases.
-
Selenium IDE does not give the feature of parameterization of tests for data driven testing.
-
Maintenance of objects and other reusable components are difficult in Selenium IDE, in case it is being used for complex testing projects.
Selenium Remote Control
Selenium Remote Control 是在 Java 中执行的服务器。它可以接受使用 HTTP 的浏览器的命令。Selenium RC 具有 Selenium RC 服务器和 Selenium RC 客户端。Selenium RC 已过时,Selenium 已将其弃用。
Selenium Remote Control is a server implemented in Java. It can accept commands for browsers using the HTTP. Selenium RC has a Selenium RC server and a Selenium RC client. Selenium RC is outdated and it has been deprecated by Selenium.
下面列出 Selenium RC 的一些特性 -
Some of the features of Selenium RC are listed below −
-
Automation tests in Selenium RC can be developed in any programming languages like Java, Python, C#, and so on.
-
Selenium RC can be used to write automated tests for testing web applications.
-
Selenium RC comprises a proxy server which gives the provision to the browser to work as if that the application under test is available in the domain of the proxy server.
-
To initiate test execution, we have to create an instance of the Selenium RC server.
Selenium WebDriver
Selenium WebDriver(从 Selenium 版本 2 开始)是 Selenium RC 的替代品,它可以直接向浏览器发送命令并检索结果,因此比 Selenium RC 更快。它接收命令并将它们传递给浏览器。这是借助于向浏览器发送命令并获取结果的浏览器驱动程序来完成的。
Selenium WebDriver (began from Selenium version 2 onwards) is the successor to Selenium RC which sends commands directly to the browser and retrieves results, hence it is faster than Selenium RC. It receives commands and passes them to the browser. This is done with the help of the browser drivers that sends commands to the browser and obtains the results.
Selenium 版本 2 将 Selenium RC 和 Selenium Webdriver 的有用特性合并到 Selenium Webdriver 中。随后,Selenium 3 为 Selenium Webdriver 添加了更多特性。
Selenium version 2 combined the useful features of Selenium RC and Selenium Webdriver into Selenium Webdriver. Later on Selenium 3, added more features to Selenium Webdriver.
下面列出 Selenium Webdriver 的一些特性 -
Some of the features of Selenium Webdriver are listed below −
-
Automation tests can be written in multiple programming languages like the Java, C#, Python, JavaScript, and so on.
-
Selenium webdriver supports browsers like Chrome, Firefox, Safari, IE, and so on.
-
Selenium webdriver works on more than one platforms like Windows, Mac, Linux, Android, and so on.
-
Headless execution can be achieved with the help of the HTMLUnit Driver.
-
Selenium webdriver does not require a server to initiate test execution and it communicates directly with the browser.
-
Selenium webdriver is open-source and comes without any licensing cost.
-
Selenium Webdriver does not have an IDE, hence it is time consuming to create test scripts.
-
Selenium Webdriver supports only web based applications.
-
Selenium Webdriver has no support to automate QR, captcha and barcode scenarios.
-
Selenium Webdriver has no feature such as Object Repository/Recovery Scenario.
-
Selenium Webdriver has no default test report generation.
-
Selenium Webdriver requires programming and technical knowledge to develop automated tests.
-
Selenium Webdriver requires time to be more compatible and stable with new browsers.
-
Selenium Webdriver is difficult to set up since no vendor support is available.
-
Selenium Webdriver can be extended for various technologies that expose DOM.
-
Selenium Webdriver has a big community support for help in case of issues.
Selenium Grid
Selenium Grid 主要用于并行测试。它采用集线器(充当中央部分,其余部分被视为节点)和节点架构。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 的部分功能:
Some of the features of Selenium Grid are listed below −
-
Presence of a hub machine which directs the execution on multiple machines using the Selenium Grid. Also, there are more than one node machines where the actual execution takes place.
-
Selenium Grid supports testing on multiple browsers and platforms. Reduces execution time by allowing parallel execution of tests.
目前最新的 Selenium 版本为 4 版本。从 Selenium 4 版本开始,整个架构完全兼容 W3C(万维网联盟),这意味着 Selenium 4 遵循 W3C 提供的所有标准和指南。我们可以从下面的链接获取更多有关 W3C 的信息 −
Currently the latest version of Selenium is on version 4. From the Selenium 4 version, the entire architecture is fully compatible with W3C - World Wide Consortium meaning Selenium 4 follows all the standards and guidelines given by W3C. We can get more information about W3C from the below link −
Selenium 3 和 Selenium 4 之间的基本区别在于,在 Selenium 3 中,客户端和服务器之间的通信是通过 JSON Wire 协议进行的,但是,从 Selenium 4 开始,服务器和客户端之间存在直接通信,遵循 W3C 指南。
The basic difference between Selenium 3 and Selenium 4 is that, in Selenium 3 the communication between client and server is done by JSON Wire protocol, however, from Selenium 4, there is direct communication between the server and client, following the W3C guidelines.
在 Selenium 4 之前,客户端和服务器之间的通信是通过 HTTP 上的 JSON Wire 协议进行的。但是,Selenium 4 中不存在 JSON Wire 协议,并且客户端和服务器之间使用 W3C 协议直接通信。
Before Selenium 4, the communication between the client and server was carried on using the JSON Wire protocol over HTTP. However, there is no existence of JSON Wire protocol from Selenium 4,and there is direct communication between the client and server using the W3C protocols.
此外,Selenium 4 提供了一些额外的定位器(除了常规定位器,如 id、class、xpath 等)称为相对定位器,其中包含 following、below、near、toRightOf、toLeftOf 方法,以及多个相对定位器的链接。Selenium 4 还提供了对 ChromeDevTools 的访问,有助于调试、网络流量分析以及有助于自动化的其他功能。
Also, Selenium 4 gives some additional locators (apart from the regular locators like id, class, xpath, and so on) called the Relative locators with the help of the methods - above, below, near, toRightOf, toLeftOf, and chaining of multiple Relative locators. Selenium 4 also gives access to the ChromeDevTools which help for debugging, network traffic analysis, and other features that help in automation.
因此,在本教程中,我们讨论了 Selenium 的各个组件。
Thus, in this tutorial, we had discussed various components of Selenium.