WebDriver Principle

Note: Learn to look at the underlying code according to the execution order

 "The following content is excerpted from the master's blog"

WebDriver

Webdriver is designed according to the classic design pattern of server-client.

The role of webdriver is to create a new browser instance, that is, to start a server side.

(Starts the service and then creates new instance of chrome driver)

The server side is our Remote server, which is the browser instance we start through different browsers. After our script starts the browser, the browser can be called our Remote server. Its responsibility is to wait for the client Send the request and act accordingly.

client is our test code. All operations in our test code, such as opening the browser, searching for elements, and clicking are sent to the tested browser in the form of http requests, that is, our Remote server, which accepts the request. And perform the corresponding operation, and return the execution status, return value and other information in the response (the interface called here is the browser's original API, and each browser has its own set of interface information, which is why we need to Reason for installing different drivers)

WebDriver Workflow

1. Create a browser service through WebDriver, and the launched browser instance will be used as the remote server of WebDriver.

2. When the script starts, a browser will be started in a new thread and bound to a specific port. Each browser has a different port segment.

3. The client creates a session, in which a restful (HTTPRequest) request is sent to the remote server through an http request, and the remote server parses the request, completes the corresponding operation, and returns the response.

4. Analyze the response, continue to execute the script or end the execution

command.py

Some commonly used constants of WebDriver are defined in the Command class.

remote\webdrvier.py

The base class of all browser webdrvier, which contains all webdriver api interfaces

remote\remote_connection.py

It includes starting the Remote WebDrvier server and executing the client request. Self._commands is the core request parameter of selenium. According to the corresponding Command constant, different http requests are sent.

Advantages of Page Object Model (POM)
1. POM provides a mode that separates operation, business process and validation at the UI layer, which makes the test code clearer and more readable
2. The object library is separated from the use case, making the We can reuse objects better, and can even be deeply integrated with different tools.
3. Reusable page method code will become more
optimized element. For example, if we want to go back to the home page, the method name is named: gotoHomePage(), and the specific function implementation can be clearly known through the method name.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325021635&siteId=291194637