Playwright 01: Selenium - Playwright architecture comparison

What is Selenium?

Selenium WebDriver is a popular and mostly used browser automation tool, developed by Simon Stewart. Selenium WebDriver's first version was released in the year 2004. It supports multiple browsers (chrome, firefox, edge, etc), language bindings ( java, python, c#, javascript, etc) and cross-platforms.

What is Playwright?

The playwright is a fast and reliable end-to-end automation tool for modern web applications. It is developed by Microsoft and the first version is released in January 2020. Like Selenium, Playwright supports multiple browsers (chrome, firefox, edge, safari, etc), language bindings( Java, Python, JavaScript and TypeScript) and cross-platform.

The major difference between Selenium and Playwright lies in the protocol these two tools are used to run the tests on the browsers. Let's check out the architectures one by one.

Selenium WebDriver Architecture:

Selenium WebDriver uses W3C protocol to run the tests on the web browsers. W3C uses HTTP protocol internally to communicate with the browsers.

The communication happens in the form of HTTP requests and HTTP responses. For every action (click, send keys, findElement, etc), we have written in our test code an HTTP request will be sent to the browser and an HTTP response will be received on the client side and the HTTP connection will be closed.

This process will be repeated, if we have 10 actions in our test code to be performed on the browsers, 10 times the HTTP connection will be established and closed after every action.

This connection establishment and closing several times for each test takes some time and makes Selenium WebDriver a little slow compared to a tool like Playwright. Let's see how Playwright is executing the tests and how it is faster compared to Selenium.

Playwright Architecture:

Whereas Playwright uses WebSocket protocol to run the tests on the browsers. WebSocket is not based on the HTTP protocol.

WebSocket is a computer communication protocol, that provides a full-duplex communication channel single TCP connection. Unlike HTTP protocol it uses "ws://" and "wss://" instead of "http://" and "https://" in the URLs.

As soon as the test execution starts, the playwright opens a connection or handshake between the client and server as shown in the below image, called a WebSocket connection.

Image Source: Programmers Buzz.

After the connection establishment, all requests are sent to the server and responses will be received by the client over the same connection. The connection established is a Bi-Directional type, which means a two-way interactive communication channel between the client and server.

Until and unless all the actions in the test are completed the connection will be open and persistent. Once the execution is completed, the connection will be closed. The connection can be closed from the client side or server side, that is "One side closes the channel".

Since Playwright is establishing the connection only once and executing all the actions in the test code it is making it much faster compared to tools like Selenium.

This is the basic comparison of Selenium and Playwright architectures.

Thank you for reading this blog. Keep learning. #brahmakothapalli #playwright

Did you find this article valuable?

Support QA Automation Enthusiast by becoming a sponsor. Any amount is appreciated!