Next-Gen App & Browser Testing Cloud

Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Next-Gen App & Browser Testing Cloud

Free Selenium to Playwright Converter Online

Convert Selenium Java tests into Playwright Python tests for pytest. Conversion runs in your browser.

Categories

...

Verify Before You Deploy

Terminal-native web and mobile automation.

Try Kane CLI
...

Write Tests in Plain English with KaneAI

Create, debug, and evolve tests using natural language.

Try for free
...

3000+ Browsers. One Platform.

See exactly how your site performs everywhere.

Try it free
Selenium Java input (to Playwright Python)

What Is a Selenium to Playwright Converter?

A Selenium to Playwright converter is a tool that rewrites Selenium WebDriver tests as Playwright tests. This one takes Selenium tests written in Java with TestNG or JUnit and returns Playwright Python tests for pytest, with locators, waits, assertions, setup hooks and the surrounding Java logic already translated.

Teams move from Selenium to Playwright for its built-in waiting, faster runs and simpler setup; the trade-offs can be explored at Playwright vs Selenium. The slow part of the move is rewriting every test by hand.

TestMu AI built this converter to do the mechanical part: it maps each WebDriver call to its Playwright equivalent, turns TestNG and JUnit structure into pytest fixtures and parameters, and lists the few places where the two tools behave differently. For a full migration plan, read Selenium to Playwright migration. If you are moving a Cucumber suite instead, the Gherkin to KaneAI Converter turns feature files into KaneAI tests.

How Does Selenium Java Map to Playwright Python?

The converter follows the Playwright locators and assertions guides and the pytest plugin reference. The most common mappings:

Selenium JavaPlaywright Python
driver.get(url)page.goto(url)
driver.findElement(By.id("email"))page.locator("#email")
driver.findElements(By.cssSelector(".item"))page.locator(".item"), looped with .all()
element.sendKeys(text) / click() / clear()locator.fill(text) / click() / clear()
element.getText() / isDisplayed()locator.inner_text() / is_visible()
WebDriverWait with ExpectedConditionsexpect(locator).to_be_visible() and other auto-retrying checks
Assert.assertEquals(driver.getTitle(), title)expect(page).to_have_title(title)
new Select(element).selectByVisibleText(label)locator.select_option(label=label)
new Actions(driver).moveToElement(el).perform()locator.hover()
driver.switchTo().frame("name")page.frame_locator(...), used for the steps that follow
driver.switchTo().alert().accept()page.once("dialog", ...), registered before the click that opens it
@Test methodtest_ method that takes the pytest-playwright page fixture
@BeforeMethod / @AfterMethod (or JUnit @BeforeEach / @AfterEach)autouse pytest fixture, with yield before the teardown
@DataProvider, @ValueSource, @CsvSource@pytest.mark.parametrize
Page object with @FindBy fieldsPython class that builds its locators in __init__
Loops, if/else, try/catch, collections, streamsPython for, if/elif, try/except, lists, dicts, comprehensions

By.id, By.name, By.className, By.cssSelector, By.xpath, By.linkText, By.partialLinkText and By.tagName all become selector strings for page.locator(). Assertions on page text, titles, URLs, attributes, visibility and element counts become expect() checks, which retry until they pass; other assertions become plain Python assert statements.

What Does a Converted TestNG Test Look Like?

This TestNG test checks the login page of the TestMu AI eCommerce Playground, a demo store built for practicing test automation. Input:

public class LoginTest {
    WebDriver driver;
    WebDriverWait wait;

    @BeforeMethod
    public void setUp() {
        driver = new ChromeDriver();
        wait = new WebDriverWait(driver, Duration.ofSeconds(10));
        driver.get("https://ecommerce-playground.lambdatest.io/index.php?route=account/login");
    }

    @Test
    public void wrongPasswordShowsWarning() {
        driver.findElement(By.id("input-email")).sendKeys("shopper@example.com");
        driver.findElement(By.id("input-password")).sendKeys("wrong-pass");
        driver.findElement(By.xpath("//button[text()='Login']")).click();
        WebElement alert = wait.until(
            ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".alert-danger")));
        Assert.assertTrue(alert.getText().contains("No match for E-Mail Address"));
    }

    @AfterMethod
    public void tearDown() {
        driver.quit();
    }
}

Output, ready for pytest:

import pytest
from playwright.sync_api import Page, expect


class TestLogin:
    @pytest.fixture(autouse=True)
    def set_up(self, page: Page):
        page.goto("https://ecommerce-playground.lambdatest.io/index.php?route=account/login")

    def test_wrong_password_shows_warning(self, page: Page):
        page.locator("#input-email").fill("shopper@example.com")
        page.locator("#input-password").fill("wrong-pass")
        page.locator("//button[text()='Login']").click()
        alert = page.locator(".alert-danger")
        expect(alert).to_be_visible(timeout=10000)
        expect(alert).to_contain_text("No match for E-Mail Address")

The ChromeDriver setup and driver.quit() are gone, because the pytest-playwright page fixture opens and closes the browser. The @BeforeMethod became an autouse fixture, the explicit wait became an expect() check that keeps its 10 second timeout, and the assertion on the alert text became to_contain_text(), which retries until the text appears.

...

How Do You Use the Selenium to Playwright Converter?

  • Add your Selenium test: Paste a Selenium Java test class, page object or snippet into the input box, upload a .java file, or click Sample to load an example.
  • Convert: Click Convert to Playwright. The Python test file appears below the input.
  • Review the notes: Read the Check before you run list. It names every line that needs a decision, with its line number in your Java code.
  • Copy or download: Copy the Python code, or download it as a .py file named for pytest.
  • Run the tests: Install pytest-playwright, run playwright install, then run pytest in the folder that holds the file. To run them on a cloud browser grid, follow Playwright with Python.

Paste a page object and the tests that use it together: the converter links them, so method calls such as loginPage.login() and the page object's locators are converted consistently.

What Should You Check After Converting Selenium Tests?

Selenium and Playwright drive the browser in different ways, so a line-for-line translation is not always the same test. The converter flags each of these in the Check before you run list:

  • Strict locators: findElement returns the first match, but a Playwright locator fails an action when its selector matches several elements. Tighten the selector or add .first, and test it first with the XPath Tester or CSS Selector Tester.
  • Waiting: Playwright checks that an element is ready before each action, so most of the Selenium waits are no longer needed. A try/catch that expected an element to be missing may now wait for it instead.
  • Dialogs: Playwright handles alerts with a listener set up before the action that opens them. The converter moves the handler above that action and captures the alert text for your assertions.
  • Tabs and windows: Playwright has no window handles; each tab is its own Page object. Window switching is marked for you to rewrite.
  • Code outside Selenium: calls to libraries such as Apache POI or Faker, and base classes you did not paste, are kept with a note, since their Python equivalents depend on your project.

Once the converted suite passes locally, you can run it on Playwright testing in the cloud across browser versions, or speed up large suites with HyperExecute.

Frequently Asked Questions

Does the Selenium to Playwright converter upload my test code?

No. The Selenium to Playwright converter runs entirely in your browser and writes the Python on the same page, so your Java source, URLs, test data and credentials never leave your machine. Nothing is sent to a server, so you can convert tests for internal applications without exposing their addresses or accounts.

Which Selenium Java code can the converter read?

The converter reads full Java test classes written for TestNG, JUnit 4 or JUnit 5, page object classes with @FindBy fields, and plain snippets of WebDriver calls. It converts waits, assertions, Select, Actions, frames, alerts, JavaScript calls and general Java logic, and lists any line it could not convert so you can finish it by hand.

What happens to WebDriverWait and Thread.sleep calls?

Playwright waits for each element before acting on it, so implicit waits are removed and WebDriverWait conditions become expect() assertions, which retry until they pass or time out. The converter keeps the timeout from your WebDriverWait. Thread.sleep becomes page.wait_for_timeout(), which still pauses, and is flagged so you can replace it with an assertion.

What does a TODO comment in the output mean?

A TODO comment marks a line the converter could not translate with confidence, such as a third-party library call, Selenium's low-level pointer API or window handle switching. The original Java is described in the comment, and the same items appear in the Check before you run list with their line numbers, so nothing is dropped silently.

Why does the converter remove the browser setup code?

In pytest-playwright, the page fixture launches the browser, opens a fresh context for every test and closes it afterwards. That replaces new ChromeDriver(), browser options, window maximize and driver.quit(). You choose the browser when you run the tests, for example pytest --browser firefox, and add --headed to watch the run.

Can Selenium tests be converted to Playwright automatically?

Mostly, yes. The Selenium to Playwright converter rewrites WebDriver calls, waits, assertions, TestNG and JUnit hooks and the surrounding Java logic into Playwright Python in one step. Parts with no direct equivalent, such as window handles or third-party libraries, are marked as TODOs, so review and run each converted test before retiring the Selenium version.

Did you find this page helpful?

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests