Selenium 简明教程

Selenium - Automation Testing

Selenium 主要用于自动化对 web 应用程序的测试。它免费,不需要任何许可成本。采用 Selenium 进行自动化测试比手动测试更有优势,因为采用 Selenium 进行自动化测试比手动操作更能带来投资回报。

Selenium is used primarily to automate tests on web applications. It is free, does not require any licensing cost. Automation testing with Selenium is much more preferred than manual testing since the automation testing with Selenium has a better return on investment than manual effort.

Different Types of Selenium Tests

Selenium 可用于创建如下所列的不同类型的测试 −

Selenium can be used to create different types of tests as listed below −

  1. Functional Tests − These tests help to check various new functionalities and features of the application or the product under test.

  2. Regression Tests − These tests help to check if code changes have broken an existing functionality of the application.

  3. Smoke Tests − These tests help to verify if a new build is stable enough to carry out testing activities on it.

  4. Integration Tests − These tests help to validate if the integration of all the modules are working together as a unit.

  5. Unit Tests − These tests are created by the developers to test their code.

Selenium Automation Testing Tools

Selenium 涉及通常称为 Selenium 组件的一组工具。这些工具列在下方 −

Selenium comprises a group of tools often called the Selenium components. These tools are listed below −

  1. Selenium IDE − It is available as an addon for Chrome and Firefox browsers.

  2. Selenium Remote Control − It is server developed in Java and allows writing automation tests in multiple languages like Java, Perl, Python, and so on.

  3. Selenium Webdriver − It is a tool that can be integrated with other frameworks like TestNG, JUnit, and so on and can be used with multiple programming languages.

  4. Selenium Grid − It is a tool that helps to achieve parallel execution across various platforms and browsers.

Differences Between Selenium Version 3.x and 4.x

Selenium 的最新版本是 4.0 版本。从 Selenium 4.0 版本开始,整个架构完全兼容 W3C - 万维网联盟,意味着 Selenium 4.0 遵循 W3C 给出的所有标准和指南。

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.

Selenium 3.x 和 Selenium 4.x 之间的基本区别是在 Selenium 3 版本中,客户端和服务器之间的通信由 JSON Wire 协议执行,而从 Selenium 4.0 开始,服务器和客户端直接通信,遵循 W3C 指南。

The basic difference between Selenium 3.x and Selenium 4.x 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.0 之前,客户端和服务器之间的通信通过 HTTP 使用 JSON Wire 协议进行。但是,从 Selenium 4.0 开始,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.0 除了 id、class、xpath 等普通定位器之外,还提供了一些其他定位器(称为相对定位器),它们由以上、以下、旁边、在右侧、在左侧和多个相对定位器的组合方法提供帮助。Selenium 4.0 还提供对 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 Web Driver 架构,根据 4.0 版本简化图示,如下所述 −

Selenium Web Driver architecture as per version 4.0 in a simplified diagram is described below −

selenium automation testing

Why Selenium is Used for Automating Testing?

  1. Automation tests using Selenium can be written in multiple programming languages like the Java, C#, Python, JavaScript, and so on.

  2. Selenium webdriver supports browsers like Chrome, Firefox, Safari, IE, and so on.

  3. Selenium webdriver works on more than one platforms like Windows, Mac, Linux, Android, and so on.

  4. Headless execution can be achieved with the help of the HTMLUnit Driver.

  5. Selenium webdriver does not require a server to initiate test execution and it communicates directly with the browser.

  6. Selenium is open-source and comes without any licensing cost.

  7. Selenium can be extended for various technologies that expose DOM.

  8. Selenium has a big community support to resolve issues.

Disadvantages of Using Selenium

  1. Selenium supports only web based applications.

  2. Selenium should not be used to automate tests on QR, captcha and barcode scenarios.

  3. Selenium does not have an in-built object repository or recovery scenario.

  4. Selenium has no default test report generation.

  5. Selenium Webdriver requires programming and technical knowledge to develop automated tests.

  6. Selenium Webdriver requires time to be more compatible and stable with new browsers.

  7. Selenium Webdriver is difficult to set up since no vendor support is available.

Run Selenium Automation Testing in Different Languages

Selenium 可用于使用 Java、Python、Ruby、JavaScript 等等不同编程语言,在不同的浏览器、平台和设备上测试 web 应用程序。根据我们正在使用的语言,配置 Selenium 测试所需的先决条件也会发生改变。以下链接将帮助我们使用不同语言在 Selenium 中设置并运行自动化测试 -

Selenium can be used to test web applications using multiple browsers, platforms, and devices using different programming languages like Java, Python, Ruby, JavaScript, and so on. Based on the language we are using, the preconditions required to configure the Selenium tests also change. The below links will help to set up and run automation testing in Selenium in different languages −

这篇关于 Selenium —— 自动化的教程已接近尾声。我们从描述了 Selenium 是什么开始,然后是不同类型的 Selenium 测试、Selenium 自动化测试工具、Selenium 3.x 和 Selenium 4.x 的区别、为什么 Selenium 用于自动化测试、Selenium 的缺点,以及如何在不同语言中运行 Selenium 中的自动化测试。

This concludes our comprehensive take on the tutorial on Selenium - Automation. We’ve started with describing what Selenium is, different types of Selenium Tests, Selenium automation testing tools, differences between Selenium 3.x and Selenium 4.x, why Selenium is used for automating testing, disadvantages of Selenium, and how to run automation testing in Selenium in different languages.

这让你对 Selenium —— 自动化测试有了深入了解。明智的做法是不断实践你学到的东西,探索与 Selenium 相关的其他内容,以加深你的理解,拓宽你的视野。

This equips you with in-depth knowledge of the Selenium - Automation Testing. It is wise to keep practicing what you’ve learned and exploring others relevant to Selenium to deepen your understanding and expand your horizons.