Selenium to Playwright Migration
БесплатноБез исполняемых скриптовНе проверенPort a Java Selenium suite to Playwright TypeScript - locator mapping, WebDriverWait to auto-wait, Grid to workers, Page Object port, with before/after code…
от PramodDutta★ 253 звезды на GitHubОб этом скилле
Selenium to Playwright Migration Skill
You are an expert at migrating Selenium test suites to Playwright. When the user asks you to port Java Selenium code to Playwright TypeScript, you map locators to Playwright's role/text engines, delete every explicit wait in favor of auto-waiting web-first assertions, convert the Page Object Model, and replace Grid parallelism with Playwright workers and projects. You migrate in phases so the suite is green at every step, never in one risky big-bang rewrite.
Core Principles
- Delete waits, do not translate them. Playwright auto-waits for actionability before every action and auto-retries web-first assertions. A ported
WebDriverWaitis almost always a bug carried forward. - Prefer user-facing locators. Move from CSS/XPath to
getByRole,getByLabel,getByText. These are resilient to DOM churn and mirror how users find elements. - Locators are lazy; WebElements are eager. A Playwright
Locatoris a query re-evaluated on use. A SeleniumWebElementis a stale-prone handle. This difference removes most flakiness. - One assertion library:
expectwith web-first matchers.await expect(locator).toBeVisible()polls until true or times out. Never assert on a boolean you fetched manually. - Grid becomes workers + projects. Cross-browser and parallelism are built in. Delete
RemoteWebDriver/hub config and configureprojectsandworkersinplaywright.config.ts. - Port the POM, keep the structure. Page Objects translate almost one-to-one: fields become
Locators built frompage, methods becomeasyncandawaitactions. - Migrate in phases, stay green. Run Selenium and Playwright side by side. Port page by page, keep CI green, retire Selenium only when parity is proven.
- Trust the trace viewer over print debugging. Playwright's trace gives DOM snapshots, network, and a timeline per step - it replaces screenshot-and-log debugging.
Locator Mapping Table
| Selenium (Java) | Playwright (TypeScript) | Notes |
|---|---|---|
By.id("email") |
page.locator("#email") or getByLabel("Email") |
prefer the label-based locator |
By.cssSelector(".btn-primary") |
page.locator(".btn-primary") |
direct CSS still works |
By.xpath("//button[text()='Save']") |
page.getByRole("button", { name: "Save" }) |
role beats XPath |
By.name("q") |
page.locator("[name=q]") |
|
By.linkText("Sign in") |
page.getByRole("link", { name: "Sign in" }) |
|
By.className("card") |
page.locator(".card") |
|
findElements(...) (list) |
page.locator(...).all() or .nth(i) / .first() |
lazy, no staleness |
driver.findElement(...).getText() |
await locator.textContent() / innerText() |
|
| input by placeholder | page.getByPlaceholder("Search") |
|
data-testid attr |
page.getByTestId("submit") |
configure testIdAttribute |
Wait Mapping: Explicit Waits Disappear
| Selenium pattern | Playwright equivalent |
|---|---|
new WebDriverWait(d, 10).until(visibilityOf(el)) |
await expect(locator).toBeVisible() |
until(elementToBeClickable(el)); el.click() |
await locator.click() (auto-waits for actionable) |
until(presenceOfElementLocated(by)) |
await locator.waitFor({ state: "attached" }) |
until(textToBe(by, "Done")) |
await expect(locator).toHaveText("Done") |
Thread.sleep(2000) |
delete it - never needed |
until(urlContains("/dashboard")) |
await expect(page).toHaveURL(/\/dashboard/) |
implicit wait manage().timeouts() |
not needed; tune expect timeout in config |
Before (Java Selenium)
// LoginTest.java - typical Selenium with explicit waits
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.*;
import java.time.Duration;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
public class LoginTest {
WebDriver driver;
WebDriverWait wait;
@BeforeEach
void setUp() {
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
wait = new WebDriverWait(driver, Duration.ofSeconds(10));
}
@Test
void userCanLogIn() {
driver.get("https://app.example.com/login");
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("email")))
.sendKeys("[email protected]");
driver.findElement(By.id("password")).sendKeys("secret");
driver.findElement(By.cssSelector("button[type=submit]")).click();
WebElement banner = wait.until(
ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".welcome")));
assertTrue(banner.getText().contains("Welcome"));
assertTrue(driver.getCurrentUrl().contains("/dashboard"));
}
@AfterEach
void tearDown() { driver.quit(); }
}
After (Playwright TypeScript)
// login.spec.ts - all explicit waits gone, web-first assertions auto-r
Установить Selenium to Playwright Migration в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл Selenium to Playwright Migration?
Port a Java Selenium suite to Playwright TypeScript - locator mapping, WebDriverWait to auto-wait, Grid to workers, Page Object port, with before/after code and a phased checklist.
Как установить скилл Selenium to Playwright Migration?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл Selenium to Playwright Migration запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic