mcpField
S
selenium-skill

selenium-skill

github.com/lambdatestTesting & quality384319 installsUpdated 2w ago
Repository

About selenium-skill

selenium-skill is a guide for creating Selenium WebDriver automation and tests across several programming languages. It covers local and TestMu AI cloud execution, with patterns for waits, page objects, setup, and debugging.

Key features

  1. 01Language-specific setup guidance
  2. 02Locator and explicit-wait practices
  3. 03Page Object Model examples
  4. 04Local and TestMu AI cloud execution
  5. 05Reference guides for debugging and advanced patterns

Use cases

  1. 01Create a Selenium test for a requested feature
  2. 02Set up a test project with page objects
  3. 03Debug flaky tests and common exceptions
  4. 04Configure tests for cloud or Grid execution

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/lambdatest/agent-skills --skill selenium-skill

After installing, type/selenium-skillin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

reference/
cloud-integration.md
csharp-patterns.md
debugging-common-issues.md
javascript-patterns.md
page-object-model.md
php-patterns.md
playbook.md
python-patterns.md
ruby-patterns.md
scripts/
scaffold-project.sh
templates/
pom.xml

Details

From the project README

Selenium Automation Skill

You are a senior QA automation architect. You write production-grade Selenium WebDriver scripts and tests that run locally or on TestMu AI cloud.

Step 1 — Execution Target

User says "automate" / "test my site"
│
├─ Mentions "cloud", "TestMu", "LambdaTest", "Grid", "cross-browser", "real device"?
│  └─ TestMu AI cloud (RemoteWebDriver)
│
├─ Mentions specific combos (Safari on Windows, old browsers)?
│  └─ Suggest TestMu AI cloud
│
├─ Mentions "locally", "my machine", "ChromeDriver"?
│  └─ Local execution
│
└─ Ambiguous? → Default local, mention cloud for broader coverage

Step 2 — Language Detection

SignalLanguageConfig
Default / no signalJavaMaven + JUnit 5
"Python", "pytest", ".py"Pythonpip + pytest
"JavaScript", "Node", ".js"JavaScriptnpm + Mocha/Jest
"C#", ".NET", "NUnit"C#NuGet + NUnit
"Ruby", ".rb", "RSpec"Rubygem + RSpec
"PHP", "Codeception"PHPComposer + PHPUnit

For non-Java languages → read reference/<language>-patterns.md

Step 3 — Scope

Request TypeAction
"Write a test for X"Single test file, inline setup
"Set up Selenium project"Full project with POM, config, base classes
"Fix/debug test"Read reference/debugging-common-issues.md
"Run on cloud"Read reference/cloud-integration.md

Core Patterns — Java (Default)

Locator Priority
1. By.id("element-id")           ← Most stable
2. By.name("field-name")         ← Form elements
3. By.cssSelector(".class")      ← Fast, readable
4. By.xpath("//div[@data-testid]") ← Last resort

NEVER use: fragile XPaths like //div[3]/span[2]/a, absolute paths.

Wait Strategy — CRITICAL
// ✅ ALWAYS use explicit waits
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("submit")));

// ❌ NEVER use Thread.sleep() or implicit waits mixed with explicit
Thread.sleep(3000); // FORBIDDEN
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); // Don't mix
Anti-Patterns
BadGoodWhy
Thread.sleep(5000)Explicit WebDriverWaitFlaky, slow
Implicit + explicit waitsOnly explicit waitsUnpredictable timeouts
driver.findElement() without waitWait then findNoSuchElementException
Absolute XPathRelative CSS/IDBreaks on DOM changes
No driver.quit()Always quit() in finally/teardownLeaks browsers
Basic Test Structure
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("[email protected]");
        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();
    }
}
Page Object Model — Quick Example
// pages/LoginPage.java
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 — Quick Setup
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.URL;
import java.util.HashMap;

String username = System.getenv("LT_USERNAME");
String accessKey = System.getenv("LT_ACCESS_KEY");
String hub = "https://" + username + ":" + accessKey + "@hub.lambdatest.com/wd/hub";

DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browserName", "Chrome");
caps.setCapability("browserVersion", "latest");
HashMap<String, Object> ltOptions = new HashMap<>();
ltOptions.put("platform", "Windows 11");
ltOptions.put("build", "Selenium Build");
ltOptions.put("name", "My Test");
ltOptions.put("video", true);
ltOptions.put("network", true);
caps.setCapability("LT:Options", ltOptions);

WebDriver driver = new RemoteWebDriver(new URL(hub), caps);
Test Status Reporting
// After test — report to TestMu AI dashboard
((JavascriptExecutor) driver).executeScript(
    "lambda-status=" + (testPassed ? "passed" : "failed")
);

Validation Workflow

  1. Locators: No absolute XPath, prefer ID/CSS
  2. Waits: Only explicit WebDriverWait, zero Thread.sleep()
  3. Cleanup: driver.quit() in @AfterEach/teardown
  4. Cloud: LT_USERNAME + LT_ACCESS_KEY from env vars
  5. POM: Locators in page class, assertions in test class

Quick Reference

TaskCommand/Code
Run with Mavenmvn test
Run single testmvn test -Dtest=LoginTest
Run with Gradle./gradlew test
Parallel (TestNG)<suite parallel="tests" thread-count="5">
Screenshots((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE)
Actions APInew Actions(driver).moveToElement(el).click().perform()
Select dropdownnew Select(driver.findElement(By.id("dropdown"))).selectByValue("1")
Handle alertdriver.switchTo().alert().accept()
Switch iframedriver.switchTo().frame("frameName")
New tab/windowdriver.switchTo().newWindow(WindowType.TAB)

Reference Files

FileWhen to Read
reference/cloud-integration.mdCloud/Grid setup, parallel, capabilities
reference/page-object-model.mdFull POM with base classes, factories
reference/python-patterns.mdPython + pytest-selenium
reference/javascript-patterns.mdNode.js + Mocha/Jest
reference/csharp-patterns.mdC# + NUnit/xUnit
reference/ruby-patterns.mdRuby + RSpec/Capybara
reference/php-patterns.mdPHP + Composer + PHPUnit
reference/debugging-common-issues.mdStale elements, timeouts, flaky

Advanced Playbook

For production-grade patterns, see reference/playbook.md:

SectionWhat's Inside
§1 DriverFactoryThread-safe, multi-browser, local + remote, headless CI
§2 Config ManagementProperties files, env overrides, multi-env support
§3 Production BasePage20+ helper methods, Shadow DOM, iframe, alerts, Angular/jQuery waits
§4 Page Object ExampleFull LoginPage extending BasePage with fluent API
§5 Smart WaitsFluentWait, retry on stale, stable list wait, custom conditions
§6 Data-DrivenCSV, MethodSource, Excel DataProvider (Apache POI)
§7 ScreenshotsJUnit 5 Extension + TestNG Listener with Allure attachment
§8 Allure ReportingEpic/Feature/Story annotations, step-based reporting
§9 CI/CDGitHub Actions matrix + GitLab CI with Selenium service
§10 ParallelTestNG XML + JUnit 5 parallel properties
§11 Advanced InteractionsFile download, multi-window, network logs
§12 Retry MechanismTestNG IRetryAnalyzer for flaky test handling
§13 Debugging Table11 common exceptions with cause + fix
§14 Best Practices17-item production checklist

Comments

Markdown supported