difference between playwright, cypress and selenium
1️⃣ Cypress Architecture Overview
Unlike Selenium or Playwright:
- Cypress runs inside the browser itself (or in the same Node process that controls the browser).
- It injects its automation code directly into the web page via a JavaScript bundle.
- Cypress does not use WebDriver, and it rarely talks to the browser engine via a protocol like CDP.
Diagrammatically:
Your Test Code (Cypress)
│
▼
Cypress Test Runner (Node + Browser bundle)
│
▼
Browser DOM / JS
│
▼
Native events / page interactions
2️⃣ How Cypress Click Works Internally
When you do:
cy.get('#login-button').click()
Cypress does:
-
Find the element in the DOM (it’s actually running inside the browser context).
-
Scroll element into view.
-
Dispatch native events using JavaScript, not CDP:
mousedown,mouseup,click,focus
-
Ensure application stability before and after the click (waits for animations, XHR, promises, etc.)
Essentially:
element.dispatchEvent(new MouseEvent('mousedown', { bubbles: true, clientX: 200, clientY: 150 }));
element.dispatchEvent(new MouseEvent('mouseup', { bubbles: true, clientX: 200, clientY: 150 }));
element.dispatchEvent(new MouseEvent('click', { bubbles: true, clientX: 200, clientY: 150 }));
✅ Notice: There is no separate driver or CDP command involved. Cypress is literally controlling the DOM from inside the browser.
3️⃣ Comparison with Selenium / Playwright
| Feature | Selenium | Playwright | Cypress |
|---|---|---|---|
| Driver needed | Yes (chromedriver/geckodriver) | No | No |
| Protocol | W3C WebDriver → driver → CDP | Direct CDP / native protocol | None; runs in-browser JS |
| Low-level action | Input.dispatchMouseEvent (via driver) | Input.dispatchMouseEvent (direct) | element.dispatchEvent in JS |
| Access to browser internals | Limited | Full via CDP | Limited to what can be done via JS |
| Auto-wait / retry | Manual waits or built-in (Playwright has auto-wait better) | Built-in waits, retries, stability checks | Built-in waits, retries, and DOM stability |
4️⃣ Key Takeaways
- Selenium: W3C command → driver → CDP → browser
- Playwright: Direct CDP → browser
- Cypress: Runs inside the browser → dispatches DOM events via JavaScript
So yes, all three eventually trigger the same browser behavior (click, type, navigate), but the path and control mechanism differ:
- Selenium → external driver
- Playwright → direct low-level protocol
- Cypress → internal JS automation
5️⃣ Analogy
| Analogy | Selenium | Playwright | Cypress |
|---|---|---|---|
| Click a button | Ask your assistant to press the button | Press it yourself via a direct wire to the robot | You reach in and press the button yourself |
💡 Extra: This is why Cypress cannot control multiple browsers simultaneously, or run remote sessions natively — it’s limited to the browser it’s injected into. Playwright and Selenium can do that because they use external processes/protocols.