Architecture of Selenium and Playwright

Shubham Pandey
Version 1
Published in
3 min readJul 26, 2022

General Considerations

In this article, I will explain the architecture of two popular testing tools, Selenium and Playwright to gain a greater understanding of which tool is more stable for test execution.

What is Playwright?

A playwright is an open-source tool for web automation testing, developed by Microsoft in 2020. The playwright is designed for end-to-end automation testing of web apps. It executes tests very quickly which is very helpful in testing complex testing projects.

Browser Support:

Playwright supports multiple browsers such as:
Chromium, Firefox, Web Kit.

Language Support:

Playwright supports Java, Python, .Net C#, and JavaScript.

What is Selenium?

Selenium is a popular open-source automated testing tool used to validate web applications across different browsers.

Browser Support:

Selenium supports multiple browsers such as:
Chrome, Firefox, Internet Explorer, Safari.

Language Support:

Selenium supports Python, Java, JavaScript, C#, Ruby, Php

Architectures of Selenium and Playwright

Selenium Architecture:

Selenium architecture

Selenium works on the HTTP connection protocol. It means after you trigger the test, the complete Selenium code written by us (Client) will be converted to JSON format. Generated JSON is sent to the browser driver (Server) through HTTP protocol.

Playwright Architecture:

Playwright architecture

While Playwright works on Web socket connection protocol, it means once you will trigger the test, the code will be converted into JSON format and will be sent to the server using Web socket protocol.

So now we will see the difference between Web socket connection Protocol and HTTP connection protocol:

HTTP VS Web Sockets Connection Diagram

Selenium sends each command as a separate HTTP request and receives JSON responses. So, every action, such as opening the browser, clicking an element, or sending keys in a text box, is sent as a separate HTTP request. Additionally, after completion of every request, the connection between server and client will be terminated, which needed to be re-established for the next request.

Connection termination after every request result in slower execution which introduces a layer of flakiness.

Playwright, on the other hand, communicates all requests through a single Web socket connection, which stays in place until test execution is completed. This reduces the points of failure and allows commands to be sent quickly on a single connection.

Conclusion

From the architecture diagram, we got a clear idea that Selenium needs to establish a connection before each request, so there are possibilities that some of the requests can take more time to establish the connection which results in flakiness. Whereas Playwright connects through a web socket due to which the connection will be maintained until the completion of all the test case executions which makes Playwright a more stable tool as compared to Selenium.

About the Author:
Shubham Pandey is a Test Engineer here at Version 1.

--

--