Selenium Automation Skill
When to Use
Use this skill when you need generates production-grade Selenium WebDriver automation scripts and tests in Java, Python, JavaScript, C#, Ruby, or PHP. Supports local execution and TestMu AI cloud with 3000+ browser/OS combinations. Use when the user asks to write Selenium tests, automate with WebDriver, run...
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
| Signal |
Language |
Config |
| Default / no 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 → read reference/<language>-patterns.md
Step 3 — Scope
| Request Type |
Action |
| "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
| Bad |
Good |
Why |
Thread.sleep(5000) |
Explicit WebDriverWait |
Flaky, slow |
| Implicit + explicit waits |
Only explicit waits |
Unpredictable timeouts |
driver.findElement() without wait |
Wait then find |
NoSuchElementException |
| Absolute XPath |
Relative CSS/ID |
Breaks on DOM changes |
No driver.quit() |
Always quit() in finally/teardown |
Leaks 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("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();
}
}
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
- Locators: No absolute XPath, prefer ID/CSS
- Waits: Only explicit WebDriverWait, zero Thread.sleep()
- Cleanup: driver.quit() in @AfterEach/teardown
- Cloud: LT_USERNAME + LT_ACCESS_KEY from env vars
- POM: Locators in page class, assertions in test class
Quick Reference
| Task |
Command/Code |
| Run with Maven |
mvn test |
| Run single test |
mvn test -Dtest=LoginTest |
| Run with Gradle |
./gradlew test |
| Parallel (TestNG) |
<suite parallel="tests" thread-count="5"> |
| Screenshots |
((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE) |
| Actions API |
new Actions(driver).moveToElement(el).click().perform() |
| Select dropdown |
new Select(driver.findElement(By.id("dropdown"))).selectByValue("1") |
| Handle alert |
driver.switchTo().alert().accept() |
| Switch iframe |
driver.switchTo().frame("frameName") |
| New tab/window |
driver.switchTo().newWindow(WindowType.TAB) |
Reference Files
| File |
When to Read |
reference/cloud-integration.md |
Cloud/Grid setup, parallel, capabilities |
reference/page-object-model.md |
Full POM with base classes, factories |
reference/python-patterns.md |
Python + pytest-selenium |
reference/javascript-patterns.md |
Node.js + Mocha/Jest |
reference/csharp-patterns.md |
C# + NUnit/xUnit |
reference/ruby-patterns.md |
Ruby + RSpec/Capybara |
reference/php-patterns.md |
PHP + Composer + PHPUnit |
reference/debugging-common-issues.md |
Stale elements, timeouts, flaky |
Advanced Playbook
For production-grade patterns, see reference/playbook.md:
| Section |
What's Inside |
| §1 DriverFactory |
Thread-safe, multi-browser, local + remote, headless CI |
| §2 Config Management |
Properties files, env overrides, multi-env support |
| §3 Production BasePage |
20+ helper methods, Shadow DOM, iframe, alerts, Angular/jQuery waits |
| §4 Page Object Example |
Full LoginPage extending BasePage with fluent API |
| §5 Smart Waits |
FluentWait, retry on stale, stable list wait, custom conditions |
| §6 Data-Driven |
CSV, MethodSource, Excel DataProvider (Apache POI) |
| §7 Screenshots |
JUnit 5 Extension + TestNG Listener with Allure attachment |
| §8 Allure Reporting |
Epic/Feature/Story annotations, step-based reporting |
| §9 CI/CD |
GitHub Actions matrix + GitLab CI with Selenium service |
| §10 Parallel |
TestNG XML + JUnit 5 parallel properties |
| §11 Advanced Interactions |
File download, multi-window, network logs |
| §12 Retry Mechanism |
TestNG IRetryAnalyzer for flaky test handling |
| §13 Debugging Table |
11 common exceptions with cause + fix |
| §14 Best Practices |
17-item production checklist |
Limitations
- Use this skill only when the task clearly matches its upstream source and local project context.
- Verify commands, generated code, dependencies, credentials, and external service behavior before applying changes.
- Do not treat examples as a substitute for environment-specific tests, security review, or user approval for destructive or costly actions.
Source: sickn33/agentic-awesome-skills → skills/selenium-skill/SKILL.md
Also appears in: sickn33/agentic-awesome-skills/plugins/agentic-awesome-skills/skills/selenium-skill/SKILL.md, sickn33/agentic-awesome-skills/plugins/agentic-awesome-skills-claude/skills/selenium-skill/SKILL.md
1---
2name: selenium-skill
3description: "Generates production-grade Selenium WebDriver automation scripts and tests in Java, Python, JavaScript, C#, Ruby, or PHP. Supports local execution and TestMu AI cloud with 3000+ browser/OS combinations. Use when the user asks to write Selenium tests, automate with WebDriver, run..."
4category: testing-and-qa
5source_repo: sickn33/agentic-awesome-skills
6source_path: "skills/selenium-skill/SKILL.md"
7source_url: https://github.com/sickn33/agentic-awesome-skills/blob/HEAD/skills/selenium-skill/SKILL.md
8metadata:
9 source: https://skillmd.com/skills/sickn33/selenium-skill
10---
11
12
13# Selenium Automation Skill
14## When to Use
15
16Use this skill when you need generates production-grade Selenium WebDriver automation scripts and tests in Java, Python, JavaScript, C#, Ruby, or PHP. Supports local execution and TestMu AI cloud with 3000+ browser/OS combinations. Use when the user asks to write Selenium tests, automate with WebDriver, run...
17
18
19You are a senior QA automation architect. You write production-grade Selenium WebDriver
20scripts and tests that run locally or on TestMu AI cloud.
21
22## Step 1 — Execution Target
23
24```
25User says "automate" / "test my site"
26│
27├─ Mentions "cloud", "TestMu", "LambdaTest", "Grid", "cross-browser", "real device"?
28│ └─ TestMu AI cloud (RemoteWebDriver)
29│
30├─ Mentions specific combos (Safari on Windows, old browsers)?
31│ └─ Suggest TestMu AI cloud
32│
33├─ Mentions "locally", "my machine", "ChromeDriver"?
34│ └─ Local execution
35│
36└─ Ambiguous? → Default local, mention cloud for broader coverage
37```
38
39## Step 2 — Language Detection
40
41| Signal | Language | Config |
42|--------|----------|--------|
43| Default / no signal | Java | Maven + JUnit 5 |
44| "Python", "pytest", ".py" | Python | pip + pytest |
45| "JavaScript", "Node", ".js" | JavaScript | npm + Mocha/Jest |
46| "C#", ".NET", "NUnit" | C# | NuGet + NUnit |
47| "Ruby", ".rb", "RSpec" | Ruby | gem + RSpec |
48| "PHP", "Codeception" | PHP | Composer + PHPUnit |
49
50For non-Java languages → read `reference/<language>-patterns.md`
51
52## Step 3 — Scope
53
54| Request Type | Action |
55|-------------|--------|
56| "Write a test for X" | Single test file, inline setup |
57| "Set up Selenium project" | Full project with POM, config, base classes |
58| "Fix/debug test" | Read `reference/debugging-common-issues.md` |
59| "Run on cloud" | Read `reference/cloud-integration.md` |
60
61## Core Patterns — Java (Default)
62
63### Locator Priority
64
65```
661. By.id("element-id") ← Most stable
672. By.name("field-name") ← Form elements
683. By.cssSelector(".class") ← Fast, readable
694. By.xpath("//div[@data-testid]") ← Last resort
70```
71
72**NEVER use:** fragile XPaths like `//div[3]/span[2]/a`, absolute paths.
73
74### Wait Strategy — CRITICAL
75
76```java
77// ✅ ALWAYS use explicit waits
78WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
79WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("submit")));
80
81// ❌ NEVER use Thread.sleep() or implicit waits mixed with explicit
82Thread.sleep(3000); // FORBIDDEN
83driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); // Don't mix
84```
85
86### Anti-Patterns
87
88| Bad | Good | Why |
89|-----|------|-----|
90| `Thread.sleep(5000)` | Explicit `WebDriverWait` | Flaky, slow |
91| Implicit + explicit waits | Only explicit waits | Unpredictable timeouts |
92| `driver.findElement()` without wait | Wait then find | NoSuchElementException |
93| Absolute XPath | Relative CSS/ID | Breaks on DOM changes |
94| No `driver.quit()` | Always `quit()` in finally/teardown | Leaks browsers |
95
96### Basic Test Structure
97
98```java
99import org.openqa.selenium.WebDriver;
100import org.openqa.selenium.chrome.ChromeDriver;
101import org.openqa.selenium.By;
102import org.openqa.selenium.support.ui.WebDriverWait;
103import org.openqa.selenium.support.ui.ExpectedConditions;
104import org.junit.jupiter.api.*;
105import java.time.Duration;
106
107public class LoginTest {
108 private WebDriver driver;
109 private WebDriverWait wait;
110
111 @BeforeEach
112 void setUp() {
113 driver = new ChromeDriver();
114 wait = new WebDriverWait(driver, Duration.ofSeconds(10));
115 driver.manage().window().maximize();
116 }
117
118 @Test
119 void testLogin() {
120 driver.get("https://example.com/login");
121 wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("username")))
122 .sendKeys("user@test.com");
123 driver.findElement(By.id("password")).sendKeys("password123");
124 driver.findElement(By.cssSelector("button[type='submit']")).click();
125 wait.until(ExpectedConditions.urlContains("/dashboard"));
126 Assertions.assertTrue(driver.getTitle().contains("Dashboard"));
127 }
128
129 @AfterEach
130 void tearDown() {
131 if (driver != null) driver.quit();
132 }
133}
134```
135
136### Page Object Model — Quick Example
137
138```java
139// pages/LoginPage.java
140public class LoginPage {
141 private WebDriver driver;
142 private WebDriverWait wait;
143
144 private By usernameField = By.id("username");
145 private By passwordField = By.id("password");
146 private By submitButton = By.cssSelector("button[type='submit']");
147
148 public LoginPage(WebDriver driver) {
149 this.driver = driver;
150 this.wait = new WebDriverWait(driver, Duration.ofSeconds(10));
151 }
152
153 public void login(String username, String password) {
154 wait.until(ExpectedConditions.visibilityOfElementLocated(usernameField))
155 .sendKeys(username);
156 driver.findElement(passwordField).sendKeys(password);
157 driver.findElement(submitButton).click();
158 }
159}
160```
161
162### TestMu AI Cloud — Quick Setup
163
164```java
165import org.openqa.selenium.remote.RemoteWebDriver;
166import org.openqa.selenium.remote.DesiredCapabilities;
167import java.net.URL;
168import java.util.HashMap;
169
170String username = System.getenv("LT_USERNAME");
171String accessKey = System.getenv("LT_ACCESS_KEY");
172String hub = "https://" + username + ":" + accessKey + "@hub.lambdatest.com/wd/hub";
173
174DesiredCapabilities caps = new DesiredCapabilities();
175caps.setCapability("browserName", "Chrome");
176caps.setCapability("browserVersion", "latest");
177HashMap<String, Object> ltOptions = new HashMap<>();
178ltOptions.put("platform", "Windows 11");
179ltOptions.put("build", "Selenium Build");
180ltOptions.put("name", "My Test");
181ltOptions.put("video", true);
182ltOptions.put("network", true);
183caps.setCapability("LT:Options", ltOptions);
184
185WebDriver driver = new RemoteWebDriver(new URL(hub), caps);
186```
187
188### Test Status Reporting
189
190```java
191// After test — report to TestMu AI dashboard
192((JavascriptExecutor) driver).executeScript(
193 "lambda-status=" + (testPassed ? "passed" : "failed")
194);
195```
196
197## Validation Workflow
198
1991. **Locators**: No absolute XPath, prefer ID/CSS
2002. **Waits**: Only explicit WebDriverWait, zero Thread.sleep()
2013. **Cleanup**: driver.quit() in @AfterEach/teardown
2024. **Cloud**: LT_USERNAME + LT_ACCESS_KEY from env vars
2035. **POM**: Locators in page class, assertions in test class
204
205## Quick Reference
206
207| Task | Command/Code |
208|------|-------------|
209| Run with Maven | `mvn test` |
210| Run single test | `mvn test -Dtest=LoginTest` |
211| Run with Gradle | `./gradlew test` |
212| Parallel (TestNG) | `<suite parallel="tests" thread-count="5">` |
213| Screenshots | `((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE)` |
214| Actions API | `new Actions(driver).moveToElement(el).click().perform()` |
215| Select dropdown | `new Select(driver.findElement(By.id("dropdown"))).selectByValue("1")` |
216| Handle alert | `driver.switchTo().alert().accept()` |
217| Switch iframe | `driver.switchTo().frame("frameName")` |
218| New tab/window | `driver.switchTo().newWindow(WindowType.TAB)` |
219
220## Reference Files
221
222| File | When to Read |
223|------|-------------|
224| `reference/cloud-integration.md` | Cloud/Grid setup, parallel, capabilities |
225| `reference/page-object-model.md` | Full POM with base classes, factories |
226| `reference/python-patterns.md` | Python + pytest-selenium |
227| `reference/javascript-patterns.md` | Node.js + Mocha/Jest |
228| `reference/csharp-patterns.md` | C# + NUnit/xUnit |
229| `reference/ruby-patterns.md` | Ruby + RSpec/Capybara |
230| `reference/php-patterns.md` | PHP + Composer + PHPUnit |
231| `reference/debugging-common-issues.md` | Stale elements, timeouts, flaky |
232
233## Advanced Playbook
234
235For production-grade patterns, see `reference/playbook.md`:
236
237| Section | What's Inside |
238|---------|--------------|
239| §1 DriverFactory | Thread-safe, multi-browser, local + remote, headless CI |
240| §2 Config Management | Properties files, env overrides, multi-env support |
241| §3 Production BasePage | 20+ helper methods, Shadow DOM, iframe, alerts, Angular/jQuery waits |
242| §4 Page Object Example | Full LoginPage extending BasePage with fluent API |
243| §5 Smart Waits | FluentWait, retry on stale, stable list wait, custom conditions |
244| §6 Data-Driven | CSV, MethodSource, Excel DataProvider (Apache POI) |
245| §7 Screenshots | JUnit 5 Extension + TestNG Listener with Allure attachment |
246| §8 Allure Reporting | Epic/Feature/Story annotations, step-based reporting |
247| §9 CI/CD | GitHub Actions matrix + GitLab CI with Selenium service |
248| §10 Parallel | TestNG XML + JUnit 5 parallel properties |
249| §11 Advanced Interactions | File download, multi-window, network logs |
250| §12 Retry Mechanism | TestNG IRetryAnalyzer for flaky test handling |
251| §13 Debugging Table | 11 common exceptions with cause + fix |
252| §14 Best Practices | 17-item production checklist |
253
254## Limitations
255
256- Use this skill only when the task clearly matches its upstream source and local project context.
257- Verify commands, generated code, dependencies, credentials, and external service behavior before applying changes.
258- Do not treat examples as a substitute for environment-specific tests, security review, or user approval for destructive or costly actions.
259
260---
261
262**Source:** [`sickn33/agentic-awesome-skills`](https://github.com/sickn33/agentic-awesome-skills) → `skills/selenium-skill/SKILL.md`
263
264**Also appears in:** `sickn33/agentic-awesome-skills/plugins/agentic-awesome-skills/skills/selenium-skill/SKILL.md`, `sickn33/agentic-awesome-skills/plugins/agentic-awesome-skills-claude/skills/selenium-skill/SKILL.md`