selenium-skill: Enabling AI to Write End-to-End Tests According to the Selenium WebDriver Specification

Introduction

Many legacy projects still rely on Selenium WebDriver for browser automation, while conversational coding assistants have increasingly defaulted to Playwright examples in recent years. Teams that want to maintain their existing stacks—Maven/JUnit, pytest, NUnit, and others—often have to repeatedly correct locator strategies, waiting policies, and project structures. selenium-skill is a dedicated skill for Agents: when users mention Selenium, WebDriver, Grid, or cross-browser testing, it guides the model to generate WebDriver scripts that can run locally or in the cloud, while constraining common anti-patterns.

What Is This

selenium-skill lives in the selenium-skill directory of the LambdaTest/agent-skills repository and uses the universal SKILL.md format. Its metadata lists the author as TestMu AI, version 1.0, MIT license, and the e2e-testing category.

The official description can be summarized as: generating production-grade Selenium WebDriver automation scripts and tests across Java, Python, JavaScript, C#, Ruby, and PHP. These scripts can run locally or connect to the TestMu AI cloud (the documentation notes support for more than 3,000 browser/OS combinations). Trigger words include Selenium, WebDriver, RemoteWebDriver, ChromeDriver, GeckoDriver, Selenium Grid, cross-browser, TestMu, and LambdaTest.

Core Features

Execution Target Routing

The skill requires first determining the execution environment, then writing code:

  • If the user mentions cloud, TestMu, LambdaTest, Grid, cross-browser, or real devices → route to the TestMu AI cloud (RemoteWebDriver).
  • When a special combination is needed (e.g., Safari on Windows, legacy browsers) → recommend a cloud environment.
  • If the user emphasizes locally, on-device, or ChromeDriver → execute locally.
  • When intent is unclear → default to local and note that cloud can expand coverage.

Language and Project Conventions

Signal Language Configuration
Default / no explicit signal Java Maven + JUnit 5
Python, pytest, .py Python pip + pytest
JavaScript, Node, .js JavaScript npm + Mocha/Jest
C#, .NET, NUnit C# NuGet + NUnit
Ruby, .rb, RSpec Ruby gem + RSpec
PHP, Codeception PHP Composer + PHPUnit

For non-Java languages, the skill instructs reading reference/<language>-patterns.md.

Request Scope

Request Type Behavior
Write a test for a feature Single test file with inline setup
Scaffold a Selenium project Full project (POM, config, base classes)
Fix/debug tests Read reference/debugging-common-issues.md
Run in the cloud Read reference/cloud-integration.md

Java Default Mode (Excerpts)

Locator priority: id → name → cssSelector → relative XPath; fragile absolute XPaths (e.g., //div[3]/span[2]/a) are forbidden.

Waiting: Explicit WebDriverWait is mandatory; Thread.sleep() is banned, and mixing implicit and explicit waits is discouraged.

Anti-pattern contrasts (highlights from the official table): findElement without waits easily throws NoSuchElementException; tests must call driver.quit() in teardown.

Validation checklist: Locators, explicit waits only, browser cleanup, cloud credential environment variables, locators and page actions in the POM, assertions in the tests.

Reference Documentation

The skill embeds multiple reference files, cited on demand:

File Purpose
reference/cloud-integration.md Cloud/Grid, parallel execution, capabilities
reference/page-object-model.md Full POM, base classes, factories
reference/python-patterns.md etc. Idioms for each language
reference/debugging-common-issues.md Stale elements, timeouts, flaky tests

Installation and Activation

The captured documentation does not provide a unified installation command or configuration field for Cursor, Codex CLI, or Claude Code. In practice, integrate the selenium-skill directory from the repository using your Agent product’s skill-loading mechanism; refer to the official directory and the corresponding product docs for exact paths and activation steps.

Typical Usage

Local Java + JUnit 5 Login Flow

The following example comes from the skill body and demonstrates explicit waits and teardown:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.junit.jupiter.api.*;
import java.time.Duration;

public class LoginTest {
    private WebDriver driver;
    private WebDriverWait wait;

    @BeforeEach
    void setUp() {
        driver = new ChromeDriver();
        wait = new WebDriverWait(driver, Duration.ofSeconds(10));
        driver.manage().window().maximize();
    }

    @Test
    void testLogin() {
        driver.get("https://example.com/login");
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("username")))
            .sendKeys("user@test.com");
        driver.findElement(By.id("password")).sendKeys("password123");
        driver.findElement(By.cssSelector("button[type='submit']")).click();
        wait.until(ExpectedConditions.urlContains("/dashboard"));
        Assertions.assertTrue(driver.getTitle().contains("Dashboard"));
    }

    @AfterEach
    void tearDown() {
        if (driver != null) driver.quit();
    }
}

A local Java project typically runs tests with mvn test or mvn test -Dtest=LoginTest (per the skill’s Quick Reference).

Page Object Fragment

Page classes centralize locators; test classes handle assertions:

public class LoginPage {
    private WebDriver driver;
    private WebDriverWait wait;
    private By usernameField = By.id("username");
    private By passwordField = By.id("password");
    private By submitButton  = By.cssSelector("button[type='submit']");

    public LoginPage(WebDriver driver) {
        this.driver = driver;
        this.wait = new WebDriverWait(driver, Duration.ofSeconds(10));
    }

    public void login(String username, String password) {
        wait.until(ExpectedConditions.visibilityOfElementLocated(usernameField))
            .sendKeys(username);
        driver.findElement(passwordField).sendKeys(password);
        driver.findElement(submitButton).click();
    }
}

TestMu AI Cloud (RemoteWebDriver)

The cloud hub uses the environment variables LT_USERNAME and LT_ACCESS_KEY, with a URL like https://{username}:{accessKey}@hub.lambdatest.com/wd/hub. Capabilities set platform, build, name, video, network, etc., via LT:Options; after tests, a lambda-status script can report passed/failed status. See reference/cloud-integration.md for full parallelization and capability details.

Use Cases and Considerations

Suitable for: Maintaining legacy projects on the Selenium stack; needing Grid/cross-browser/cloud-device matrices; wanting AI output that aligns with team norms for WebDriver code (waits, POM, cleanup).

Notes: The skill defaults to Java; other languages depend on repository references, so the Agent must be able to read those files. Cloud execution requires a valid LambdaTest/TestMu account and environment variables; pricing and quota details are not included in the documentation. The truncated material does not fully display the Advanced Playbook; for deep production practices, rely on the complete SKILL.md and references in the repository.

Summary

selenium-skill codifies the decision tree for “local vs. cloud, which language stack, single test vs. full project,” and bakes WebDriver waiting and locator constraints into the generation workflow, reducing the misapplication of Playwright paradigms to Selenium projects. Official repository: https://github.com/LambdaTest/agent-skills/tree/main/selenium-skill

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye