r/QualityAssurance • u/BoxFalse247 • 6d ago
Selenium+Python vs. Playwrigh+Typescript
This was presented to prove one tool was much faster than the other and switching technology stacks was badly needed. Regardless of the tools preference, do you think this comparison is representative enough to prove the case?
Playwright TypeScript:
import { test, expect } from '@playwright/test';
test('user can log in', async ({ page }) => {
await page.goto('/login');
await page.getByLabel('Username').fill('qa');
await page.getByLabel('Password').fill('secret');
await page.getByRole('button', { name: 'Log in' }).click();
await expect(page.getByRole('heading', { name: 'Home' })).toBeVisible();
});Selenium+Python:
def test_log_in(self):
self.driver.find_element(By.ID, "user").send_keys("qa")
self.driver.find_element(By.ID, "pass").send_keys("secret")
self.driver.find_element(By.CSS_SELECTOR, "button.login").click()
time.sleep(3)
self.assertEqual(self.driver.find_element(By.CSS_SELECTOR, "h1").text, "Home")Edit: I did not write these. I just want to check with the community to see if they see the same flaws I do.
2
Upvotes
15
u/latnGemin616 6d ago
No. You are comparing two different languages and code styles.
A better comparison would be:
I understand these are code samples to demonstrate a point, but for the love of all things, please refactor these so they are re-usable and easier to parse. Believe it or not, employing strong POM discipline will contribute to faster test execution. It's 2026 .. no one uses
time.sleep()7
u/Xiao20 6d ago
The sleep confuses the result with a guaranteed 3s wait.
1
u/ArtemBondarQA 5d ago
No. What it shows is the ineffectiveness and potential flakiness of the Selenium example, because it uses a hardcoded 3-second sleep before the assertion. In Playwright, the locator assertion toBeVisible() doesn't need it, as it has a built-in dynamic wait of up to 5 seconds by default.
1
u/NkZ-1 4d ago
My honest opinión is that you are not comparing apples to apples. Indifferently from comparing JS (Jest) to PyTest as code base, Id say the most convincing way to make your point is comparing Selenium to Playwright and forget the code language. "Ah, but in Python Playwright is a wrapper and in JS is native and faster" May be, yet then you are not comparing Playwright to Selenium but also comparing Python to JS. Your argument gets more complex. Break it in 2. About Selenium to Playwright. Easier to write (aria selectors), easier to maintain (No waits or sleeps) and the transition from Selenium to Playwright is almost instant. Important to note: Selenium handles old, legacy browsers. Playwright not so much. Put a list of what PR does against what Selenium does and the scale of difficulty for the adoption. After that then you can talk about the language (Python vs JS)
3
u/No_Echo2745 6d ago
These are both bad examples. I'm big on Playwright and TypeScript, but a comparison should use a proper POM structure and any patterns for waits.
1
u/Asya1 6d ago
Playwright is the only thing you need
1
u/NaturalShow4006 4d ago
Sleep 🥱😵💫
1
u/Fit-Avocado-1880 1d ago
Choosing a language is about org skills set and dependencies you need. Choosing the package and tools is based on feature set and maintenance and integration. Everything else is preference and design patterns. There is a lot of other tools and patterns to modularize your solution and create the suffice abstraction layer to enable test authoring at proper cost.