Skip to content
| Marketplace
Sign in
Visual Studio Code>Testing>Selenium to Playwright ConverterNew to Visual Studio Code? Get it now.
Selenium to Playwright Converter

Selenium to Playwright Converter

Ashish Sharda

|
753 installs
| (0) | Free
AI-powered Selenium to Playwright migration with wait elimination, rule-based confidence scores, validation, CodeLens, AI chat and test health grades. Bring your own API key, a local model (Ollama), or GitHub Copilot.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

🎭 Selenium → Playwright Converter (S2P)

AI-powered VS Code extension that migrates your Selenium tests to Playwright in one click.

Bring your own API key, run a local model with Ollama, or reuse GitHub Copilot. No subscriptions, no account.


🆕 What's New in v1.4.0

  • ⏱ Wait Elimination Mode (selenium2pw.waitHandling: off · safe · aggressive). A built-in pre-pass finds Thread.sleep, time.sleep, WebDriverWait + ExpectedConditions, implicitlyWait, FluentWait, manage().timeouts(), cy.wait and waitForTimeout, then tells the AI exactly what to do with each one. In safe mode, a wait followed by an action on the same element is removed, because Playwright auto-waits. Other waits become web-first assertions (toBeVisible, toBeEnabled, toContainText, toBeHidden). Waits tied to network, navigation or loading become waitForResponse / waitForURL / waitForLoadState. Every removal is marked // S2P: removed explicit wait (auto-waiting handles this).
  • 🎯 Rule-based confidence score (0–100) for each file and each test. The score comes from rules, never from the AI's opinion of its own work. It goes down for leftover Selenium code, fixed waits, complex XPath, unknown helpers, Actions / JavaScript / windows / iframes / alerts, tsc errors and playwright test --list failures. Flagged lines get // TODO [S2P]: review - <reason>, and a review checklist is added to the migration report. The score shows in the diff preview title, the dashboard and the history.
  • ✅ Post-conversion validation. After you save, S2P runs npx tsc --noEmit and npx playwright test --list on the new file (Python output uses py_compile + pytest --collect-only). Problems appear in the Problems panel with a Fix with AI quick fix. Missing tools are skipped, each step times out after 30s, and you can cancel it.
  • 🩺 Health Score upgraded (A–F, no AI tokens). Now grades Java, C#, Python, JS and TS files, both Selenium and Playwright, using static rules: fixed sleeps, absolute or complex XPath, position-based selectors, tests without assertions, .only, skipped tests, hard-coded secrets, swallowed errors, { force: true }, leftover Selenium code, and very long tests. The grade shows in the status bar and issues appear in the Problems panel. You can scan a whole folder, and every conversion records Health before → after.
  • 🔧 Fix with AI. Sends the file and its errors to your AI provider and shows a diff. Nothing is written until you click Apply Fix.
  • 🤖 New providers: Ollama (local, no key), any OpenAI-compatible endpoint (LM Studio, vLLM, llama.cpp server, Together, Fireworks, Azure gateways, corporate proxies), VS Code Language Model API (reuse GitHub Copilot, no key), Mistral / Codestral and GitHub Models.
  • 🔌 Test Connection for every provider. Requests retry with exponential backoff and honour Retry-After on 429 / 5xx.
  • 📏 Context-window aware. Large files are split by top-level class / function / describe block and the results are merged. You get a warning when a local model's context is too small.
  • 🧮 Estimated usage. When a provider returns no token counts, S2P estimates them and marks them with *.
  • 📦 Import / export custom rules as JSON.

🆕 What's New in v1.3.0

  • 🔍 CodeLens actions — ▶ Run · 🔧 Fix · ♻ Refactor · 💡 Explain appear above every test() / it() / describe() block
  • 🔧 AI Fix — paste an error message and AI rewrites the failing test to fix it
  • 💬 AI Chat — ask any Playwright question in a dedicated chat panel (Ctrl+Shift+Alt+C)
  • ⚡ Generate Tests — generate Playwright tests from any source file (Ctrl+Shift+Alt+G)
  • 🏥 Test Health Score — instant A–F grade for your test file with zero AI tokens (Ctrl+Shift+Alt+H)
  • 🩺 Health Diagnostics — inline warnings highlight waitForTimeout, XPath selectors, and other bad patterns
  • 🗺 Migration Progress Tree — sidebar tree showing ✅ Playwright / ❌ Selenium / ⚠️ Unknown across your workspace
  • 🛡 Make Tests Resilient — AI rewrites fragile locators to use getByRole, getByLabel, getByTestId
  • 🎭 One-click Playwright Setup — detects missing @playwright/test and scaffolds config, scripts, and browsers

🆕 What's New in v1.2.0

  • 🎨 Live sidebar dashboard — stats, history, and provider switcher always visible in the activity bar
  • 👁 Diff preview — review the converted code side-by-side before saving; Accept, Copy, or Discard
  • 📁 Batch folder convert — right-click any folder to convert all Selenium files at once
  • 🤖 Per-provider model picker — choose from curated models per provider or enter any custom model ID
  • 📜 Conversion history — last 50 conversions tracked with provider, tokens, and pass/fail status
  • 📊 Export migration report — one-click Markdown report with summary, provider breakdown, and history table
  • ⌨️ Keyboard shortcuts — Ctrl+Shift+Alt+P convert file · Ctrl+Shift+Alt+S convert selection · Ctrl+Shift+Alt+D dashboard
  • 📝 Custom prompt rules — inject your own project-specific conversion rules via settings

⚡ How It Works

  1. Pick a provider: Ctrl+Shift+P → Selenium2PW: Select AI Provider. Then set a key with Selenium2PW: Set AI Provider API Key (not needed for Ollama or Copilot).
  2. Right-click any Selenium test file in the Explorer and select "Convert Selenium → Playwright".
  3. Review the diff preview. Its title shows the confidence score.
  4. Click Save File. S2P validates the new file and flags any problems.

✨ Features

  • ⚡ One-click conversion: right-click any Selenium file in the Explorer or the editor
  • 🔀 Selection support: convert just a highlighted block of code
  • 📁 Batch convert: right-click a folder to convert every file in it
  • 👁 Diff preview: review changes before saving (Save / Copy / Discard)
  • ⏱ Wait elimination: deterministic pre-pass plus mode-specific AI instructions
  • 🩺 Health Score: A–F grade for any Selenium or Playwright test file, using no AI tokens
  • 🔍 CodeLens: ▶ Run · 🔧 Fix · ♻ Refactor · 💡 Explain above every test, plus ▶ Run Suite and 🏥 Health Score above describe blocks
  • 💬 AI Chat: ask Playwright questions with the current file as context
  • ⚡ Generate Tests: create a Playwright spec from any source file
  • 🛡 Make Tests Resilient: AI replaces sleeps and fragile selectors, shown as a diff with the health change
  • 🗺 Migration Progress tree: ✅ Playwright / ❌ Selenium / ⚠️ Unknown for every test file in the workspace
  • 🎭 One-click Playwright Setup: adds @playwright/test, a config, scripts and browsers
  • 🎯 Confidence score and review checklist: computed from rules, with weights you can tune in one file
  • ✅ Validation and Fix with AI: tsc and playwright test --list results show up as diagnostics, with a quick fix
  • 🤖 11 providers with per-provider model picker (live model lists for Ollama, Copilot and /models endpoints)
  • 🌐 5 input languages: JavaScript, TypeScript, Python, Java, C#
  • 📤 3 output formats: TypeScript, JavaScript, Python Playwright
  • 📊 Dashboard: sidebar plus a full tab with stats, average confidence, history and validation results
  • 📜 History: last 50 conversions with tokens (estimated ones marked), confidence and validation status
  • 📊 Migration report: Markdown with a summary, provider breakdown, history and the review checklist
  • 📝 Custom rules: add project-specific rules to the AI prompt and import / export them as JSON
  • 🔒 Secure key storage: keys are stored in VS Code SecretStorage and never logged
  • 🗂 Non-destructive: creates a new .playwright.ts file and never modifies the original

🤖 Supported AI Providers

Pricing, limits and free tiers change often, so check each provider's own page.

Provider ID Key Default model Provider page
Groq groq API key llama-3.3-70b-versatile groq.com/pricing
Google Gemini gemini API key gemini-2.5-flash ai.google.dev/pricing
OpenRouter openrouter API key deepseek/deepseek-r1:free openrouter.ai/models
DeepSeek deepseek API key deepseek-chat api-docs.deepseek.com
OpenAI openai API key gpt-4o openai.com/api/pricing
Anthropic anthropic API key claude-sonnet-4-6 anthropic.com/pricing
Mistral (Codestral) mistral API key codestral-latest mistral.ai/pricing
GitHub Models githubModels GitHub token (models: read) openai/gpt-4.1 docs.github.com/github-models
Ollama (local) ollama none qwen2.5-coder:7b ollama.com/library
OpenAI-compatible endpoint openaiCompatible optional set openaiCompatible.model your server's docs
VS Code Language Model (Copilot) vscodeLm none (VS Code 1.90+, Copilot Chat) first Copilot model VS Code LM API

Ollama quick start: install Ollama, run ollama pull qwen2.5-coder:7b, choose Ollama (local) and run Test Connection. Change AI Model lists the models you have installed. Raise selenium2pw.ollama.numCtx if your machine can handle a larger context.

LM Studio / vLLM / llama.cpp / gateways: choose OpenAI-compatible endpoint, then set selenium2pw.openaiCompatible.baseUrl and selenium2pw.openaiCompatible.model. Store a key with Set AI Provider API Key if your server needs one. For Azure-style gateways, set apiKeyHeader to api-key and set apiVersion.

GitHub Copilot: choose VS Code Language Model (Copilot). VS Code asks for your consent the first time.


📝 Conversion Example

Before — Selenium Python:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait

driver = webdriver.Chrome()
driver.get("https://example.com")
driver.find_element(By.ID, "username").send_keys("admin")
time.sleep(2)
driver.find_element(By.CSS_SELECTOR, ".login-btn").click()
WebDriverWait(driver, 10).until(
    EC.visibility_of_element_located((By.ID, "dashboard"))
)
driver.quit()

After — Playwright TypeScript (waitHandling: safe):

import { test, expect } from '@playwright/test';

test.describe('Login', () => {
  test('user can sign in', async ({ page }) => {
    await page.goto('https://example.com');
    await page.locator('#username').fill('admin');
    // S2P: removed explicit wait (auto-waiting handles this)
    await page.locator('.login-btn').click();
    // S2P: replaced explicit wait with web-first assertion
    await expect(page.locator('#dashboard')).toBeVisible();
  });
});

🎯 How the confidence score works

Every file starts at 100. Each rule subtracts weight × occurrences, up to a cap per rule:

Rule Severity Default weight
Leftover Selenium import / API call big −25
tsc --noEmit errors · playwright test --list failure big −25 each
waitForTimeout medium −10
Complex XPath (axes, positional, long) medium −10
Calls to unknown helpers / utility classes medium −10
Actions, JavaScript execution, windows/tabs, iframes, alerts small (flagged) −4 each

All rules and weights live in one file, src/core/confidenceRules.ts, so they are easy to tune.


⌨️ Keyboard Shortcuts

Shortcut Action
Ctrl+Shift+Alt+P Convert active file
Ctrl+Shift+Alt+S Convert selected code
Ctrl+Shift+Alt+D Open dashboard
Ctrl+Shift+Alt+F Fix with AI (in a .playwright.* file)
Ctrl+Shift+Alt+C Open AI Chat
Ctrl+Shift+Alt+G Generate tests for the current file
Ctrl+Shift+Alt+H Show Test Health Score

⚙️ Configuration

{
  "selenium2pw.aiProvider": "ollama",
  "selenium2pw.outputLanguage": "typescript",
  "selenium2pw.waitHandling": "safe",
  "selenium2pw.validateAfterConvert": true,
  "selenium2pw.ollama.baseUrl": "http://localhost:11434",
  "selenium2pw.customRules": [
    "Use data-testid attributes where available",
    "Replace myCustomWait() with page.waitForSelector()"
  ]
}
Setting Options Default
aiProvider groq · gemini · openrouter · deepseek · openai · anthropic · mistral · githubModels · ollama · openaiCompatible · vscodeLm groq
outputLanguage typescript · javascript · python typescript
waitHandling (new) off · safe · aggressive safe
validateAfterConvert (new) true · false true
validationTimeoutSeconds (new) 5–300 30
report.includeReviewChecklist (new) true · false true
ollama.baseUrl (new) URL http://localhost:11434
ollama.numCtx (new) tokens 8192
openaiCompatible.baseUrl (new) URL http://localhost:1234/v1
openaiCompatible.model (new) model ID ""
openaiCompatible.contextWindow (new) tokens 32768
openaiCompatible.apiKeyHeader (new) bearer · api-key bearer
openaiCompatible.apiVersion (new) e.g. 2024-06-01 ""
mistral.baseUrl (new) URL https://api.mistral.ai/v1
healthScore.enabled (new) true · false true
healthScore.showDiagnostics (new) true · false true
createNewFile true · false true
showDiffPreview true · false true
customRules array of strings []
modelOverrides object per provider {}

All settings use the selenium2pw. prefix.


🚀 Commands

Command Description
Selenium2PW: Convert Selenium → Playwright Convert the active file
Selenium2PW: Convert Selected Code → Playwright Convert selected code only
Selenium2PW: Batch Convert Folder → Playwright Convert all files in a folder
Selenium2PW: Select AI Provider (new) Switch between the 11 providers
Selenium2PW: Test AI Provider Connection (new) Check that a provider and model respond
Selenium2PW: Change AI Model Pick from the provider's live list or enter a model ID
Selenium2PW: Validate Converted Playwright File (new) Run tsc / playwright test --list on a file
Selenium2PW: Fix with AI (new) Send errors to the AI and review the fix as a diff
Selenium2PW: Show Test Health Score (A–F) Grade the current file, list its top issues, jump to Make Resilient
Selenium2PW: Scan Folder Test Health (new) Grade every test file in a folder
Selenium2PW: Export Custom Rules (JSON) (new) Save customRules to a file
Selenium2PW: Import Custom Rules (JSON) (new) Merge or replace rules from a file
Selenium2PW: Generate Playwright Tests for This File Create a spec from any source file
Selenium2PW: Open AI Chat Chat about Playwright with the current file as context
Selenium2PW: Make Tests More Resilient Rewrite sleeps and fragile selectors, previewed as a diff
Selenium2PW: Fix / Refactor / Explain / Run This Test CodeLens actions on each test
Selenium2PW: Refresh Migration Progress Rescan the Migration Progress tree
Selenium2PW: Set Up Playwright in This Workspace Install and configure Playwright
Selenium2PW: Export Migration Report Markdown report with the review checklist
Selenium2PW: Open Usage Dashboard Stats, history, validation and provider management
Selenium2PW: Set AI Provider API Key Store your API key securely

🔒 Privacy

  • API keys are stored in VS Code's built-in SecretStorage, never in plain text, and are removed from error messages
  • Your code is sent only to the AI provider you choose. With Ollama or a local OpenAI-compatible server, it never leaves your machine
  • Validation runs your project's own tsc / playwright with npx --no-install, so nothing is downloaded
  • No account required, no data collected

📬 Support

  • Website: S2P — Selenium to Playwright
  • Email: ashishjsharda@gmail.com

Made for the testing community. Happy migrating! 🎭

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft