Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

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от 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

  1. Delete waits, do not translate them. Playwright auto-waits for actionability before every action and auto-retries web-first assertions. A ported WebDriverWait is almost always a bug carried forward.
  2. Prefer user-facing locators. Move from CSS/XPath to getByRole, getByLabel, getByText. These are resilient to DOM churn and mirror how users find elements.
  3. Locators are lazy; WebElements are eager. A Playwright Locator is a query re-evaluated on use. A Selenium WebElement is a stale-prone handle. This difference removes most flakiness.
  4. One assertion library: expect with web-first matchers. await expect(locator).toBeVisible() polls until true or times out. Never assert on a boolean you fetched manually.
  5. Grid becomes workers + projects. Cross-browser and parallelism are built in. Delete RemoteWebDriver/hub config and configure projects and workers in playwright.config.ts.
  6. Port the POM, keep the structure. Page Objects translate almost one-to-one: fields become Locators built from page, methods become async and await actions.
  7. 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.
  8. 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
Полный SKILL.md на GitHub

Установить 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), без исполняемых скриптов.

Похожие скиллы

Сравнить Selenium to Playwright Migration с