Automated testing tool - Selenium detailed explanation

foreword

Selenium is a tool for web application testing. It is an open source web automation testing tool, originally developed for website automation testing, the type is like the button sprites we use to play games, it can automatically operate according to the specified command, the difference is that Selenium can run directly on the browser, it All major browsers are supported, including IE (7, 8, 9, 10, 11), Mozilla Firefox, Safari, Google Chrome, Opera, etc.

Selenium tests run directly in the browser, just like real users. According to our instructions, the browser can automatically load the page, obtain the required data, even take a screenshot of the page, or determine whether certain actions on the website have occurred.

Selenium itself does not have a browser and does not support browser functions. It needs to be combined with the above-mentioned third-party browsers to be used. But we sometimes need it to run embedded in the code, so we can use a tool called PhantomJS instead of a real browser.

Several features of Selenium

1. Open source software: Open source code can increase some functions of the tool according to needs

2. Cross-platform, multi-platform support: linux, windows, mac

3. Support multiple browsers: Firefox, Internet Explorer, Safari, Opera, Chrome, Edge

4. Core function: It is possible to perform automated testing on multiple browsers

5. Can be used with a variety of programming languages: Java, Python, C#, JavaScript, Ruby, etc.

6. Mature and stable: it has been widely used by Google, Baidu, Tencent and other companies

7. Support the execution of distributed test cases, which can distribute test cases to different test machines for execution, which is equivalent to the function of a distribution machine.

8. Powerful functions: It can realize most of the functions similar to commercial tools, and because of the open source, it can realize customized functions

The main functions of Selenium include: Testing compatibility with browsers-testing your application to see if it can work well on different browsers and operating systems. Test System Functionality - Create regression tests to verify software functionality and user requirements. Supports automatic recording of actions and automatic generation of test scripts in different languages ​​such as .Net, Java, and Perl.

1. The bottom layer of the framework uses JavaScript to simulate real users operating the browser. When the test script is executed, the browser automatically performs operations such as click, input, open, and verification according to the script code, just like real users do, and the application is tested from the perspective of the end user.

2. It is possible to automate browser compatibility testing, although there are still subtle differences on different browsers.

3. It is easy to use and can use Java, Python and other languages ​​to write use case scripts.

seleniun components

 

selenium RC

Selenium RC is the core part of the selenium family. Selenium RC supports many different languages ​​to write automated test scripts, and uses the SeleniumRC server as a proxy server to access the application, so as to achieve the purpose of testing.

The process of RC is:

The test case establishes a connection with the selenium-RC server through an Http request

Selenium RC Server drives a browser, loads Selenium Core into the browser page, and sets the browser's proxy as Selenium Server's Http Proxy

The execution use case sends an Http request to Selenium Server, Selenium Server parses the request, and then sends JS commands through Http Proxy to notify Selenium Core to perform operations on the browser and inject JS code

4. Selenium Core executes the received instructions and operates

When the browser receives a new request, it sends an http request

After Selenium Server receives the Http request sent by the browser, it reorganizes the Http request and obtains the corresponding Web page

Http Proxy in Selenium Server returns the received page to the browser

selenium IDE

Selenium IDE is an open source web automation testing tool under Selenium Suite. This tool is a primary tool for building scripts. It is actually a plug-in for FireFox and has an easy-to-use interface. It has a recording function, which can record the actions performed by the user and can be exported as a reusable script. It does not use any programming logic to write the test base, but only needs to record the interaction with the browser to create the test cases. Afterwards, the test case can be rerun using the play option. If you have no programming experience, you can quickly familiarize yourself with Selenium commands through Selenium IDE.

selenium Grid

Selenium Grid is an automated testing aid tool that can speed up functional testing of Web-apps by utilizing existing computer infrastructure. Using Grid, it is very convenient to run multiple tests in parallel on multiple machines and heterogeneous environments at the same time case. Its characteristics are:

1. Parallel execution.

2. Use a host to control use cases to run in different environments and different browsers.

3. Add flexible testing machines.

selenium webDriver

selenium 2.0 = selenium 1.0 + WebDriver

 In selenium 2.0, WebDriver is the main push. WebDriver is a substitute for selenium RC. Because selenium is for backward compatibility, selenium RC has not been completely abandoned. If you use selenium to develop a new automated test project, it is strongly recommended to use WebDriver.

So what is the main difference between selenium RC and webdriver?

selenium RC runs JavaScript applications in the browser, and uses the browser's built-in JavaScript translator to translate and execute selenese commands (selenese is a collection of selenium commands).

 WebDriver directly controls browsers through native browser support or browser extensions. Developed for each browser, WebDriver replaces the JavaScript embedded in the web application under test. Tight integration with browsers enables the creation of more advanced tests that avoid the limitations imposed by the JavaScript security model. In addition to support from browser vendors, WebDriver also simulates user input using operating system-level calls.

webDriver is the core after selenium2.0, and Webdriver directly controls the browser through native browser support or browser extensions. The webdriver is developed for each browser and replaces the JavaScript embedded in the web application under test. Tight integration with browsers enables the creation of more advanced tests that avoid the limitations imposed by the JavaScript safe model. In addition to support from browser vendors, webdriver also simulates user input using operating system-level calls.

To use webdriver, you need to install the driver for the browser. The chrome browser driver is chromedriver, the IE browser driver is IEDriver, and the firefox browser driver is geckodriver. The browser and the driver have corresponding version requirements.

Selenium 2.0 or above supports multi-language test script writing, because webdriver is used, webdriver is based on JSON Wire Protocol protocol, JSON Wire protocol is based on http protocol, further standardizes http request and corresponding body part data. The request message and response message data in WebDriver are stored and transmitted in the form of JSON, so between Client and Server, as long as the data is transmitted based on the JSON Wire Protocol, it has nothing to do with the specific scripting language, so The driver of the same browser can process both Java language scripts and Python language scripts.

Finally, I would like to thank everyone who has read my article carefully. Reciprocity is always necessary. Although it is not a very valuable thing, you can take it away if you need it:

These materials should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey, and I hope it can help you! Partners can click the small card below to receive

Guess you like

Origin blog.csdn.net/hlsxjh/article/details/130893614#comments_26741885