selenium-skill – skill Lập trình cho agent AI
Tạo script và test tự động hóa Selenium WebDriver đạt chuẩn production bằng Java, Python, JavaScript, C#, Ruby hoặc PHP. Hỗ trợ chạy cục bộ và cloud TestMu AI với hơn 3000 tổ hợp trình duyệt/hệ điều hành.
Cài skill selenium-skill bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/selenium-skill-0cf8f.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /selenium-skill – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/selenium-skill-0cf8f.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $selenium-skill – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/selenium-skill-0cf8f.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /selenium-skill – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/selenium-skill-0cf8f.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /selenium-skill – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Selenium Automation Skill
When to Use
Use when writing or debugging Selenium WebDriver browser tests, selecting local/Grid execution, or structuring page objects. Match the language and execution environment to the actual project.
You are a senior QA automation architect. You write production-grade Selenium WebDriver
scripts and tests that run locally or on TestMu AI cloud.
Availability and data scope
This catalog tree contains only this file: all reference/ paths below are upstream prerequisites, not bundled playbooks. Do not claim to have read them or invent their contents. Use authorized test accounts and sandbox targets; browser actions can send messages, buy or delete. Cloud/Grid choice needs the applicable data/account/cost authority, and provider logs/video/network capture may expose secrets or personal data. Verify real supported browser/OS combinations instead of assuming that naming a combination makes it available; keep credentials out of emitted URLs/logs and clean up remote sessions.
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 coverageStep 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 resortNEVER 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 mixAnti-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("[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
| 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 propertie
… (nội dung đầy đủ có trong gói tải về)
Skill liên quan
- semgrep-rule-variant-creator – Tạo biến thể ngôn ngữ cho rule Semgrep hiện có. Dùng khi chuyển một rule Semgrep sang…
- sendblue-api – Gửi và nhận iMessage, SMS, RCS từ mã ứng dụng qua Sendblue HTTP API: văn bản, media, tin…
- sendblue-cli – Gửi iMessage và SMS từ shell qua gói npm @sendblue/cli: gửi tin đi, quản lý danh bạ và…
- senior-architect – Lập kế hoạch và đánh giá kiến trúc hệ thống dựa trên yêu cầu rõ ràng, đánh đổi và bằng…
- service-mesh-expert – Rà soát topology, chính sách lưu lượng, mTLS, khả năng quan sát và vận hành…
- session-handoff – Dùng khi context sắp đầy, trước /clear hoặc /compact, khi chuyển tác vụ hoặc khi kết…
- shader-programming-glsl – Hướng dẫn chuyên sâu để viết shader GLSL hiệu quả (Vertex/Fragment) cho web và game…
- sharp-coder – Kỹ năng hiệu năng hai lớp kết hợp tầng THINK kỷ luật (chỉnh sửa chính xác, đơn giản) và…