The Playwright is aligned with the architecture of the modern browsers and runs tests out-of-process, and it is free of the typical in-process test runner limitations of Cypress. Playwright communicates all requests between client and server through a single WebSocket connection which is comparatively better than the Selenium HTTP Connection protocol for automation.
- Server: The Playwright Server communicates with the client and different web browser engines.
Browser Protocols: The Playwright uses the Chrome DevTools Protocol (CDP) to communicate with Chromium. For Firefox and WebKit, Playwright implemented their own protocols similar to CDP.
- WebSocket Protocol: A WebSocket connection is established by sending a request to the server from a client through a process called the WebSocket handshake. WebSockets have a much lower latency in terms of messages being sent to their clients due to the open connection, which is contrary to the long polling where the connection has to be reestablished with each request. WebSockets, send the response as soon as it gets it in real time. The WebSocket connection uses WebSocket communication protocol which provides a full-duplex communication channel over a single TCP connection. A full-duplex system allows communication in both directions. All modern browsers support this protocol. It is a stateful protocol where the connection between the client and server will stay alive until either client or server terminates it.
- Client Server Communication: Once you will trigger your test, the code will be converted into JSON format, and then it will be sent to the server using Web Socket Protocol. The Playwright communicates all requests through a single web socket connection, which stays in place until all test execution is completed. Since commands are sent on a single connection, chances of test failure or flakiness are less, and commands are executed quickly. This architecture is contrary to Selenium, which uses HTTP connection protocol and sends each command like browser opening, clicking, sending keys, or closing the browser as a separate HTTP request. Also, in Selenium, the connection between the server and the client will be terminated after each request and re-established for the next request. This is the reason why Playwright is faster than Selenium.