| |

Selenium to Playwright Migration Part 3: The Master Cheat Sheet — Every Pattern Mapped

This is part of the Selenium to Playwright Migration Series. Follow the complete 7-part tutorial to migrate your test suite from Selenium Java to Playwright TypeScript.

🎭 Want to master this with real projects? Join the Playwright Automation Mastery course at The Testing Academy.


The complete side-by-side reference: every Selenium Java pattern mapped to its Playwright TypeScript equivalent across assertions, locators, interactions, waits, navigation, and configuration.

Contents

Assertions

Selenium (Java)Playwright (TypeScript)
assertEquals(expected, actual)await expect(locator).toHaveText('expected')
assertTrue(element.isDisplayed())await expect(locator).toBeVisible()
assertFalse(element.isEnabled())await expect(locator).toBeDisabled()
assertThat(element).hasAttribute("x","y")await expect(locator).toHaveAttribute('x','y')
assertThat(driver.getTitle()).contains("x")await expect(page).toHaveTitle(/x/)
assertThat(driver.getCurrentUrl()).contains("/dash")await expect(page).toHaveURL(/dash/)

Locators

Selenium (Java)Playwright (TypeScript)
driver.findElement(By.id("x"))page.locator('#x')
driver.findElement(By.name("x"))page.locator('[name="x"]')
driver.findElement(By.className("x"))page.locator('.x')
driver.findElement(By.xpath("//btn"))page.getByRole('button')
driver.findElement(By.linkText("x"))page.getByRole('link', {name:'x'})
driver.findElements(By.css(".item"))page.locator('.item') (auto-multiple)
@FindBy(id="x") WebElement el;readonly el = page.locator('#x')

🚀 Level Up Your Playwright

From locators to CI pipelines — build a production-grade Playwright + TypeScript framework step by step.

Interactions

Selenium (Java)Playwright (TypeScript)
element.click()await locator.click()
element.sendKeys("text")await locator.fill('text')
element.clear()await locator.clear()
Select(el).selectByVisibleText("x")await locator.selectOption({label:'x'})
element.sendKeys(Keys.ENTER)await locator.press('Enter')
Actions(driver).moveToElement(el).perform()await locator.hover()
Actions(driver).doubleClick(el).perform()await locator.dblclick()
Actions(driver).dragAndDrop(src,tgt).perform()await src.dragTo(tgt)

Waits

Selenium (Java)Playwright (TypeScript)
WebDriverWait(driver,10).until(visible(el))await expect(locator).toBeVisible()
Thread.sleep(3000)Remove entirely (auto-wait)
FluentWait with pollingawait expect(locator).toBeVisible({timeout:30000})
implicitlyWait(10, SECONDS)Not needed (auto-wait built in)
ExpectedConditions.alertIsPresent()page.on('dialog', handler)

Key pattern: Remove ALL explicit waits. Playwright’s expect() auto-retries until the condition is met or timeout occurs. This single change eliminates 80% of flaky test failures.

Next: Part 4: Page Objects and Test Conversion — transforming your POM, eliminating base classes, and introducing the Module layer.

🎓 Master Playwright End to End

Join hundreds of SDETs building real automation frameworks. Lifetime access, hands-on projects, and a job-ready portfolio.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.