Do you understand how the Selenium automated testing framework works?

Table of contents

1. What is Selenium?

2. Selenium History

3. Principle of Selenium

Four, Selenium work process summary:

5. How are these functions on the remote server side realized?

6. Attachment:

1. What is Selenium?

  In a sentence from the official website: Selenium automates browsers. That's it! Simply put, Selenium is an automated testing tool for web applications. Selenium tests run directly in the browser, just like real users operating the browser. Supported browsers include IE, Firefox, Safari, Chrome, etc. Selenium is not just a tool or API, it is composed of many tools

 

(The above translation software is used, some translations are not accurate, please use your own discretion when reading)

  • WebDriver

If you are starting out with desktop web or mobile web test automation then you will be using webdriverapi. Webdriver uses browser automation APIs provided by browser vendors to control browsers and run tests. It's as if a real user is operating the browser. Since WebDriver does not require application code to compile its API, it is non-intrusive. So the application you test is the same as the one pushed live.

  • IDE

Ide (Integrated Development Environment) is the tool you use to develop Selenium test cases. It's an easy-to-use Chrome and Firefox extension, and is often the most efficient way to develop test cases. It uses existing Selenium commands to record user actions in the browser, with parameters defined by the element's context. Not only is this a time saver, but it's also a great way to learn Selenium scripting syntax.

  • Grid

Selenium Grid allows you to run test cases on different machines across different platforms. The control of triggering test cases is on the local side, and when the test cases are triggered, they will be automatically executed by the remote side.

After WebDriver tests are developed, you may need to run the tests on multiple browser and operating system combinations. This is where Grid comes in.

 

2. Selenium History

 In 2004, Selenium Core was born. Selenium Core is a browser-based testing tool using the JavaScript programming language. It runs in the security sandbox of the browser. The design concept is to deploy the product to be tested, Selenium Core and test scripts to the same server to complete the automated testing work.

​ In 2005, Selenium RC was born, which is selenium1. At this time, Selenium Core is actually the core of Selenium RC. Selenium RC allows the product under test, Selenium Core and test scripts to be distributed on different servers. (The test script only cares about sending the HTTP request to the specified URL, and selenium itself does not need to care about the programming language in which the HTTP request is written), Selenium RC consists of two parts: one is Selenium RC Server, and the other is to provide various programming language client drivers to write test scripts

​ In 2007, Webdriver was born. The design concept of WebDriver is to isolate the end-to-end test from the underlying specific test tools, and use the design pattern Adapter adapter to achieve the goal. WebDriver's API organization is more object-oriented.

​ In 2008, selenium2 was born. Selenium2 is actually the merger of selenium rc and webdriver. The fundamental reason for the merger is to complement each other's shortcomings

​ In 2009, selenium3 was born. This version eliminated selenium rc and is mainly composed of selenium webdriver and selenium Grid. What we use every day is actually selenium webdriver. As for selenium grid, it is a tool for distributed automated testing 

3. Principle of Selenium

Selenium in this article refers to Selenium Webdriver, which has the same functionality as RC and includes the original 1.x bindings. It involves the implementation of language bindings and individual browser control codes. This is often referred to as "WebDriver" and is sometimes referred to as Selenium 2. Selenium 1.0 + WebDriver = Selenium 2.0

  • WebDriver is designed in a simpler and more concise programming interface, while solving some limitations in Selenium-RC API.
  • Compared with Selenium1.0, WebDriver is a compact object-oriented API
  • It drives browsers more efficiently and overcomes Selenium 1.x limitations which impacted our test coverage of features such as file upload or download, popups and dialogs

When using Selenium for automated testing, you must introduce the corresponding jar package, such as selenium-server-standalone-2.46.0.jar, selenium-java-2.47.1.jar, version 3+ may be different, we see a jar package like sever, this jar package is the Selenium service, the server side can be any browser as a remote server, the responsibility is to process the client's request and make corresponding operations, the client is the script we run, response The specific content of se depends on the content of the request. Let's take firefox as an example, as shown in the figure below

 

Four, Selenium work process summary:

selenium client(Java等语言编写的自动化测试脚本)初始化一个service服务,通过Webdriver启动浏览器驱动程序
通过RemoteWebDriver向浏览器驱动程序发送HTTP请求,浏览器驱动程序解析请求,打开浏览器,并获得sessionid,如果再次对浏览器操作需携带此id
打开浏览器,绑定特定的端口,把启动后的浏览器作为webdriver的remote server
打开浏览器后,所有的selenium的操作(访问地址,查找元素等)均通过RemoteConnection链接到remote server,然后使用execute方法调用_request方法通过urlib3向remote server发送请求
浏览器通过请求的内容执行对应动作
浏览器再把执行的动作结果通过浏览器驱动程序返回给测试脚本

5. How are these functions on the remote server side realized?

    The browser implements the unified interface of webdriver, and the client can perform automatic operations of the browser through the unified restful interface.

  Currently, webdriver supports mainstream browsers such as ie, chrome, and firefox. The main reason is that these browsers implement various interfaces agreed by webdriver.

Take a chestnut that opens a browser:

package com.Demo;
 
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
 
public class ExampleForFirefox {
    public static void main(String[] args) {
 
        System.setProperty("webdriver.firefox.bin", "D:\\Program Files\\Mozilla Firefox 24\\firefox.exe");
        WebDriver driver = new FirefoxDriver();
        System.out.println("https://www.cnblogs.com/mrjade/");
        driver.get("https://www.cnblogs.com/mrjade/");
    
    }
}

Guess you like

Origin blog.csdn.net/lzz718719/article/details/131831958
Recommended