mirror of
https://github.com/hanzoai/skills.git
synced 2026-11-19 00:47:36 +00:00
Every page now loads /webmcp.js, scripts/webmcp.ts with its types stripped (npm run webmcp). Where the browser has document.modelContext it registers two read-only tools: search_skills over the published skills index, and get_skill, which returns a skill's markdown checked against the index digest. The markdown alternate link moves from build.py to site.py, so CI holds every page to it. The API catalog gains the site itself (llms.txt and the skills index) and hanzo.ai/agents; the live discovery check now fetches every catalog link. tests/site.mjs drives the tools through a recording modelContext, and checks a browser without one loads clean.
871 lines
43 KiB
HTML
871 lines
43 KiB
HTML
<!doctype html>
|
|
<html lang="en"><head>
|
|
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<title>testing-e2e-testing</title>
|
|
<meta name="color-scheme" content="dark">
|
|
<style>
|
|
/* Committed to one visual world: a dark instrument panel. No light variant —
|
|
the dot field and the hairline rules only read on black, and a naive
|
|
inversion would wash both out. Every colour is painted explicitly so the page
|
|
never borrows a host background. */
|
|
@font-face{font-family:'Zen';src:url('/fonts/Zen-Variable.woff2') format('woff2');font-weight:100 900;font-style:normal;font-display:swap}
|
|
@font-face{font-family:'Zen';src:url('/fonts/Zen-Italic-Variable.woff2') format('woff2');font-weight:100 900;font-style:italic;font-display:swap}
|
|
@font-face{font-family:'Zen Mono';src:url('/fonts/ZenMono-Variable.woff2') format('woff2');font-weight:100 900;font-style:normal;font-display:swap}
|
|
@font-face{font-family:'Zen Mono';src:url('/fonts/ZenMono-Italic-Variable.woff2') format('woff2');font-weight:100 900;font-style:italic;font-display:swap}
|
|
@font-face{font-family:'Zen Pixel Square';src:url('/fonts/ZenPixel-Square.woff2') format('woff2');font-style:normal;font-display:swap}
|
|
|
|
:root{
|
|
--ink:#f4f4f2; --soft:#9c9c98; --faint:#6a6a66; --ground:#000; --panel:#0a0a0a;
|
|
--line:#232323; --line-hi:#3a3a3a; --accent:#f4f4f2;
|
|
--font-zen-sans:'Zen',-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif;
|
|
--font-zen-mono:'Zen Mono',ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace;
|
|
--font-zen-pixel-square:'Zen Pixel Square',monospace;
|
|
--mono:var(--font-zen-mono);
|
|
--sans:var(--font-zen-sans);
|
|
/* Controls are pills and surfaces are soft, as on hanzo.ai. */
|
|
--r:999px; --r-soft:14px;
|
|
}
|
|
*{box-sizing:border-box}
|
|
html{-webkit-text-size-adjust:100%}
|
|
body{margin:0;background:var(--ground);color:var(--ink);font-family:var(--sans);
|
|
font-size:16px;line-height:1.65;-webkit-font-smoothing:antialiased}
|
|
.wrap{max-width:60rem;margin:0 auto;padding:0 1.75rem}
|
|
|
|
/* The dot field. A halftone made of one repeating radial-gradient, faded out
|
|
along the diagonal by a mask so it reads as a wave rather than wallpaper. */
|
|
/* No overflow clip here: the dot field is inset to the box already, and a clip
|
|
would cut off the copy-prompt menu. */
|
|
.hero{position:relative;border-bottom:1px solid var(--line)}
|
|
.hero::before{content:"";position:absolute;inset:0;
|
|
background-image:radial-gradient(var(--line-hi) 1px, transparent 1px);
|
|
background-size:7px 7px;
|
|
-webkit-mask-image:linear-gradient(115deg,#000 0%,rgba(0,0,0,.55) 38%,transparent 72%);
|
|
mask-image:linear-gradient(115deg,#000 0%,rgba(0,0,0,.55) 38%,transparent 72%);
|
|
pointer-events:none}
|
|
.hero .wrap{position:relative;padding-top:5.5rem;padding-bottom:4rem}
|
|
|
|
nav{border-bottom:1px solid var(--line)}
|
|
nav .in{max-width:60rem;margin:0 auto;padding:1.1rem 1.75rem;display:flex;
|
|
justify-content:space-between;align-items:center;gap:1rem}
|
|
.brand{font-family:var(--mono);font-size:.85rem;letter-spacing:.14em;
|
|
text-transform:uppercase;color:var(--ink);text-decoration:none;
|
|
display:inline-flex;align-items:center;gap:.6rem}
|
|
.brand i{font-style:normal;color:var(--faint)}
|
|
.mark{width:1.15em;height:1.15em;display:block;flex:0 0 auto}
|
|
nav a.up{font-family:var(--mono);font-size:.72rem;letter-spacing:.14em;
|
|
text-transform:uppercase;color:var(--soft);text-decoration:none}
|
|
nav a.up:hover{color:var(--ink)}
|
|
|
|
h1{font-family:var(--mono);font-size:clamp(2rem,5.4vw,3.4rem);line-height:1.12;
|
|
letter-spacing:-.02em;margin:0 0 1.1rem;font-weight:500;text-wrap:balance}
|
|
h1 em{font-style:normal;color:var(--faint)}
|
|
.lede{color:var(--soft);font-size:1.05rem;max-width:52ch;margin:0 0 2.25rem}
|
|
|
|
.btns{display:flex;flex-wrap:wrap;gap:.7rem;margin:0 0 .5rem;align-items:center}
|
|
.btn{display:inline-flex;align-items:center;gap:.5rem;font-family:var(--mono);
|
|
font-size:.72rem;letter-spacing:.14em;text-transform:uppercase;
|
|
padding:.8rem 1.4rem;border:1px solid var(--line-hi);border-radius:var(--r);
|
|
color:var(--ink);text-decoration:none;background:transparent;cursor:pointer;
|
|
line-height:1.2;font-weight:400}
|
|
.btn:hover{background:#141414;text-decoration:none;border-color:var(--soft)}
|
|
.btn.solid{background:var(--ink);color:#000;border-color:var(--ink)}
|
|
.btn.solid:hover{background:#d8d8d4}
|
|
.btn .chev{width:.7em;height:.7em;flex:0 0 auto;transition:transform .15s ease}
|
|
.btn[aria-expanded="true"] .chev{transform:rotate(180deg)}
|
|
|
|
/* Copy-prompt selector. Each row copies the prompt for its own target. */
|
|
.copy{position:relative;display:inline-flex}
|
|
.menu{position:absolute;top:calc(100% + .5rem);left:0;z-index:20;min-width:21rem;
|
|
background:var(--panel);border:1px solid var(--line-hi);border-radius:var(--r-soft);
|
|
padding:.4rem;display:flex;flex-direction:column;
|
|
box-shadow:0 12px 32px rgba(0,0,0,.75)}
|
|
.menu[hidden]{display:none}
|
|
.mi{display:flex;align-items:center;gap:.7rem;width:100%;text-align:left;
|
|
padding:.62rem .8rem;border:0;border-radius:calc(var(--r-soft) - .35rem);
|
|
background:transparent;color:var(--ink);font-family:var(--mono);font-size:.76rem;
|
|
letter-spacing:.04em;text-decoration:none;cursor:pointer;line-height:1.3;
|
|
white-space:nowrap}
|
|
.mi:hover,.mi:focus-visible{background:#181818;outline:none}
|
|
.mi .mark{width:1.05rem;height:1.05rem;color:var(--soft)}
|
|
.mi:hover .mark{color:var(--ink)}
|
|
.mi u{margin-left:auto;color:var(--faint);text-decoration:none;font-size:.68rem;
|
|
letter-spacing:.1em;text-transform:uppercase}
|
|
|
|
/* Works-with bar: one scrolling row, name and mark per agent. */
|
|
.strip{border-bottom:1px solid var(--line);background:var(--panel)}
|
|
.strip .in{max-width:60rem;margin:0 auto;padding:.9rem 1.75rem;display:flex;
|
|
align-items:center;gap:1.25rem;font-family:var(--mono);font-size:.72rem;
|
|
letter-spacing:.1em;text-transform:uppercase;color:var(--faint)}
|
|
.strip b{color:var(--soft);font-weight:400;flex:0 0 auto;
|
|
border-right:1px solid var(--line);padding-right:1.25rem;align-self:stretch;
|
|
display:flex;align-items:center}
|
|
.bar{display:flex;align-items:center;gap:.5rem;flex:1 1 auto;min-width:0;
|
|
overflow-x:auto;scrollbar-width:none;scroll-snap-type:x proximity;
|
|
-webkit-overflow-scrolling:touch;
|
|
-webkit-mask-image:linear-gradient(90deg,#000 calc(100% - 3rem),transparent);
|
|
mask-image:linear-gradient(90deg,#000 calc(100% - 3rem),transparent)}
|
|
.bar::-webkit-scrollbar{display:none}
|
|
.agent{display:inline-flex;align-items:center;gap:.45rem;flex:0 0 auto;
|
|
padding:.4rem .85rem;border:1px solid var(--line);border-radius:var(--r);
|
|
color:var(--soft);white-space:nowrap;scroll-snap-align:start;
|
|
text-decoration:none;background:var(--ground)}
|
|
.agent:hover{color:var(--ink);border-color:var(--line-hi);text-decoration:none}
|
|
.agent .mark{width:.95rem;height:.95rem}
|
|
|
|
h2{font-family:var(--mono);font-size:1.1rem;letter-spacing:-.01em;margin:2.75rem 0 .75rem;font-weight:500}
|
|
h3{font-size:1rem;margin:2rem 0 .5rem;font-weight:600}
|
|
h4,h5,h6{font-size:.94rem;margin:1.5rem 0 .5rem;font-weight:600}
|
|
p{margin:0 0 1rem;max-width:70ch}
|
|
ul,ol{margin:0 0 1rem;padding-left:1.35rem;max-width:70ch}
|
|
li{margin:.22rem 0}
|
|
a{color:var(--ink);text-decoration:underline;text-underline-offset:3px;
|
|
text-decoration-color:var(--line-hi)}
|
|
a:hover{text-decoration-color:var(--ink)}
|
|
a:focus-visible{outline:1px solid var(--ink);outline-offset:3px}
|
|
code{font-family:var(--mono);font-size:.85em;background:var(--panel);
|
|
border:1px solid var(--line);border-radius:5px;padding:.1em .36em}
|
|
pre{background:var(--panel);border:1px solid var(--line);padding:1rem 1.1rem;
|
|
border-radius:var(--r-soft);overflow-x:auto;margin:0 0 1.25rem}
|
|
pre code{background:none;border:0;padding:0;font-size:.82rem;line-height:1.7}
|
|
blockquote{margin:0 0 1rem;padding-left:1rem;border-left:1px solid var(--line-hi);color:var(--soft)}
|
|
hr{border:0;border-top:1px solid var(--line);margin:2.5rem 0}
|
|
table{border-collapse:collapse;width:100%;margin:0 0 1.25rem;font-size:.92rem;
|
|
display:block;overflow-x:auto}
|
|
th,td{border:1px solid var(--line);padding:.5rem .7rem;text-align:left}
|
|
|
|
.curl{display:block;background:var(--panel);border:1px solid var(--line);
|
|
border-radius:var(--r-soft);padding:.95rem 1.1rem;font-family:var(--mono);
|
|
font-size:.8rem;color:var(--soft);overflow-x:auto;margin:0 0 2.5rem;
|
|
white-space:pre;line-height:1.9}
|
|
.curl b{color:var(--ink);font-weight:400}
|
|
.curl i{font-style:normal;color:var(--faint)}
|
|
|
|
/* index */
|
|
#q{width:100%;padding:.85rem 1.2rem;font-family:var(--mono);font-size:.85rem;color:var(--ink);
|
|
background:var(--panel);border:1px solid var(--line);border-radius:var(--r);margin:0 0 .6rem}
|
|
#q::placeholder{color:var(--faint);text-transform:uppercase;letter-spacing:.1em;font-size:.72rem}
|
|
#q:focus{outline:none;border-color:var(--soft)}
|
|
#count{color:var(--faint);font-family:var(--mono);font-size:.72rem;letter-spacing:.1em;
|
|
text-transform:uppercase;margin:0 0 2rem}
|
|
.cat{margin:2.5rem 0 .5rem;font-family:var(--mono);font-size:.7rem;letter-spacing:.16em;
|
|
text-transform:uppercase;color:var(--faint);border-bottom:1px solid var(--line);
|
|
padding-bottom:.45rem}
|
|
.row{display:block;padding:.6rem .9rem;margin:0 -.9rem;border-bottom:1px solid var(--line);
|
|
border-radius:var(--r-soft);text-decoration:none}
|
|
.row:hover{background:#0a0a0a}
|
|
.nm{font-family:var(--mono);font-size:.84rem;color:var(--ink);display:block}
|
|
.ds{color:var(--soft);font-size:.9rem;display:block;margin-top:.12rem}
|
|
footer{margin-top:4rem;padding:2rem 0 4rem;border-top:1px solid var(--line);
|
|
color:var(--faint);font-size:.85rem}
|
|
footer a{color:var(--soft)}
|
|
.fmap{display:grid;gap:1.75rem;grid-template-columns:repeat(auto-fit,minmax(11rem,1fr));
|
|
margin:0 0 2rem;font-size:.85rem}
|
|
.fmap b{display:block;font-family:var(--mono);font-size:.68rem;letter-spacing:.16em;
|
|
text-transform:uppercase;color:var(--faint);font-weight:400;margin:0 0 .6rem;
|
|
border-bottom:1px solid var(--line);padding-bottom:.4rem}
|
|
.fmap a{display:inline-block;color:var(--ink);text-decoration:none;margin:.3rem .35rem 0 0}
|
|
.fmap a:hover{text-decoration:underline}
|
|
.fmap div{color:var(--faint);line-height:1.5}
|
|
.fend{border-top:1px solid var(--line);padding-top:1.25rem;font-size:.82rem}
|
|
|
|
@media (max-width:640px){
|
|
.hero .wrap{padding-top:3.25rem;padding-bottom:2.75rem}
|
|
.btns{gap:.5rem}
|
|
.btn{padding:.75rem 1.15rem;font-size:.68rem}
|
|
.copy,.copy .btn{width:100%;justify-content:center}
|
|
.menu{left:0;right:0;min-width:0}
|
|
.strip .in{flex-direction:column;align-items:flex-start;gap:.6rem;padding:.9rem 1.75rem}
|
|
.strip b{border-right:0;padding-right:0}
|
|
.bar{width:100%}
|
|
}
|
|
</style>
|
|
<link rel="icon" href="/favicon.svg">
|
|
<link rel="canonical" href="https://hanzoskills.com/testing-e2e-testing">
|
|
<link rel="alternate" type="text/markdown" href="/testing-e2e-testing.md">
|
|
<script type="module" src="/webmcp.js"></script>
|
|
</head>
|
|
<!-- Reading this with a machine? Every page here is also plain markdown.
|
|
This one: https://hanzoskills.com/testing-e2e-testing.md
|
|
Index: https://hanzoskills.com/llms.txt
|
|
Corpus: https://hanzoskills.com/all.md
|
|
Append .md to any path for the markdown twin. -->
|
|
<body>
|
|
<nav><div class="in">
|
|
<a class="brand" href="/"><svg class="mark" viewBox="0 0 67 67" fill="currentColor" aria-hidden="true"><path d="M22.21 67V44.6369H0V67H22.21Z"/><path d="M66.7038 22.3184H22.2534L0.0878906 44.6367H44.4634L66.7038 22.3184Z"/><path d="M22.21 0H0V22.3184H22.21V0Z"/><path d="M66.7198 0H44.5098V22.3184H66.7198V0Z"/><path d="M66.7198 67V44.6369H44.5098V67H66.7198Z"/></svg> HANZO<i>SKILLS</i></a>
|
|
<a class="up" href="/">All skills</a>
|
|
</div></nav>
|
|
|
|
<div class="wrap">
|
|
<h1>testing-e2e-testing</h1><p class="lede">Test complete user workflows from UI to backend</p><h1>End-to-End Testing</h1>
|
|
<h2>When to Use This Skill</h2>
|
|
<p>Use this skill when you need to:</p>
|
|
<ul><li>Test complete user workflows from UI to backend</li><li>Verify cross-browser compatibility</li><li>Implement Page Object Model (POM) for maintainable tests</li><li>Handle waiting strategies (explicit vs implicit waits)</li><li>Test complex user interactions (drag-drop, file uploads)</li><li>Implement visual regression testing</li><li>Debug flaky E2E tests</li><li>Balance E2E coverage with speed and reliability</li></ul>
|
|
<p><strong>ACTIVATE THIS SKILL</strong>: When testing full user journeys, browser automation, or UI workflows</p>
|
|
<h2>Core Concepts</h2>
|
|
<h3>E2E Testing Philosophy</h3>
|
|
<p><strong>E2E tests verify complete user workflows</strong>:</p>
|
|
<ul><li>Simulate real user behavior (clicks, typing, navigation)</li><li>Test against real browser (Chrome, Firefox, Safari)</li><li>Exercise full stack (UI, API, database)</li><li>Highest confidence, slowest execution</li><li>Focus on critical user paths</li></ul>
|
|
<p><strong>Testing Pyramid</strong>:</p>
|
|
<pre><code> /\
|
|
/E2E\ <- Few, slow, high confidence
|
|
/-----\
|
|
/Integr\ <- More, medium speed
|
|
/--------\
|
|
| Unit | <- Many, fast, focused
|
|
----------</code></pre>
|
|
<h3>Playwright vs Cypress</h3>
|
|
<p><strong>Playwright</strong> (Recommended):</p>
|
|
<ul><li>Multi-browser (Chrome, Firefox, Safari, Edge)</li><li>True parallelization</li><li>Native mobile viewports</li><li>Auto-wait for elements</li><li>Network interception</li><li>Multiple tabs/contexts</li></ul>
|
|
<p><strong>Cypress</strong>:</p>
|
|
<ul><li>Excellent DX (developer experience)</li><li>Time-travel debugging</li><li>Real-time reloads</li><li>Limited to Chromium-based browsers</li><li>Single tab limitation</li></ul>
|
|
<h3>Page Object Model (POM)</h3>
|
|
<p><strong>Encapsulate page structure and actions</strong>:</p>
|
|
<pre><code class="lang-typescript">// ❌ WITHOUT POM: Brittle, duplicated selectors
|
|
test('user login', async ({ page }) => {
|
|
await page.goto('https://example.com/login');
|
|
await page.fill('#username', 'alice');
|
|
await page.fill('#password', 'secret');
|
|
await page.click('button[type="submit"]');
|
|
await expect(page.locator('.welcome-message')).toBeVisible();
|
|
});
|
|
|
|
// ✅ WITH POM: Reusable, maintainable
|
|
class LoginPage {
|
|
constructor(private page: Page) {}
|
|
|
|
async goto() {
|
|
await this.page.goto('https://example.com/login');
|
|
}
|
|
|
|
async login(username: string, password: string) {
|
|
await this.page.fill('#username', username);
|
|
await this.page.fill('#password', password);
|
|
await this.page.click('button[type="submit"]');
|
|
}
|
|
|
|
get welcomeMessage() {
|
|
return this.page.locator('.welcome-message');
|
|
}
|
|
}
|
|
|
|
test('user login', async ({ page }) => {
|
|
const loginPage = new LoginPage(page);
|
|
await loginPage.goto();
|
|
await loginPage.login('alice', 'secret');
|
|
await expect(loginPage.welcomeMessage).toBeVisible();
|
|
});</code></pre>
|
|
<h2>Patterns</h2>
|
|
<h3>Waiting Strategies</h3>
|
|
<p><strong>Auto-Wait (Playwright)</strong>: Built-in smart waiting</p>
|
|
<pre><code class="lang-typescript">// Playwright auto-waits for:
|
|
// 1. Element to be visible
|
|
// 2. Element to be enabled
|
|
// 3. Element to be stable (not animating)
|
|
|
|
await page.click('button'); // Waits automatically
|
|
await page.fill('input', 'text'); // Waits for enabled state
|
|
await expect(page.locator('.message')).toBeVisible(); // Waits up to timeout</code></pre>
|
|
<p><strong>Explicit Waits</strong>: Wait for specific conditions</p>
|
|
<pre><code class="lang-typescript">// Wait for element
|
|
await page.waitForSelector('.dynamic-content', { state: 'visible' });
|
|
|
|
// Wait for network idle
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
// Wait for custom condition
|
|
await page.waitForFunction(() => {
|
|
return document.querySelectorAll('.item').length > 5;
|
|
});
|
|
|
|
// Wait for response
|
|
const responsePromise = page.waitForResponse(
|
|
response => response.url().includes('/api/users') && response.status() === 200
|
|
);
|
|
await page.click('button');
|
|
await responsePromise;</code></pre>
|
|
<p><strong>Polling Pattern</strong>: Retry until condition met</p>
|
|
<pre><code class="lang-typescript">async function waitForCondition(
|
|
condition: () => Promise<boolean>,
|
|
timeout = 5000
|
|
) {
|
|
const startTime = Date.now();
|
|
while (Date.now() - startTime < timeout) {
|
|
if (await condition()) return;
|
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
}
|
|
throw new Error('Condition not met within timeout');
|
|
}
|
|
|
|
await waitForCondition(async () => {
|
|
const count = await page.locator('.item').count();
|
|
return count > 5;
|
|
});</code></pre>
|
|
<h3>Page Object Model Patterns</h3>
|
|
<p><strong>Basic POM</strong>:</p>
|
|
<pre><code class="lang-typescript">// pages/LoginPage.ts
|
|
export class LoginPage {
|
|
constructor(private page: Page) {}
|
|
|
|
// Selectors
|
|
private usernameInput = '#username';
|
|
private passwordInput = '#password';
|
|
private submitButton = 'button[type="submit"]';
|
|
private errorMessage = '.error-message';
|
|
|
|
// Actions
|
|
async goto() {
|
|
await this.page.goto('/login');
|
|
}
|
|
|
|
async login(username: string, password: string) {
|
|
await this.page.fill(this.usernameInput, username);
|
|
await this.page.fill(this.passwordInput, password);
|
|
await this.page.click(this.submitButton);
|
|
}
|
|
|
|
async loginAsAdmin() {
|
|
await this.login('admin', 'admin123');
|
|
}
|
|
|
|
// Assertions
|
|
async expectErrorMessage(message: string) {
|
|
await expect(this.page.locator(this.errorMessage)).toHaveText(message);
|
|
}
|
|
}</code></pre>
|
|
<p><strong>POM with Components</strong>:</p>
|
|
<pre><code class="lang-typescript">// components/Header.ts
|
|
export class Header {
|
|
constructor(private page: Page) {}
|
|
|
|
async logout() {
|
|
await this.page.click('.user-menu');
|
|
await this.page.click('.logout-button');
|
|
}
|
|
|
|
async navigateTo(section: string) {
|
|
await this.page.click(`nav a:has-text("${section}")`);
|
|
}
|
|
}
|
|
|
|
// pages/DashboardPage.ts
|
|
export class DashboardPage {
|
|
readonly header: Header;
|
|
|
|
constructor(private page: Page) {
|
|
this.header = new Header(page);
|
|
}
|
|
|
|
async goto() {
|
|
await this.page.goto('/dashboard');
|
|
}
|
|
|
|
async getStatValue(statName: string): Promise<string> {
|
|
return await this.page.locator(`.stat[data-name="${statName}"] .value`).textContent();
|
|
}
|
|
}
|
|
|
|
// test
|
|
test('dashboard shows correct stats', async ({ page }) => {
|
|
const dashboard = new DashboardPage(page);
|
|
await dashboard.goto();
|
|
|
|
const userCount = await dashboard.getStatValue('users');
|
|
expect(userCount).toBe('1,234');
|
|
|
|
await dashboard.header.logout();
|
|
});</code></pre>
|
|
<h3>Network Mocking and Interception</h3>
|
|
<pre><code class="lang-typescript">// Mock API responses
|
|
test('displays users from API', async ({ page }) => {
|
|
// Intercept and mock API
|
|
await page.route('**/api/users', route => {
|
|
route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify([
|
|
{ id: 1, name: 'Alice' },
|
|
{ id: 2, name: 'Bob' },
|
|
]),
|
|
});
|
|
});
|
|
|
|
await page.goto('/users');
|
|
await expect(page.locator('.user-item')).toHaveCount(2);
|
|
await expect(page.locator('.user-item').first()).toContainText('Alice');
|
|
});
|
|
|
|
// Test error handling
|
|
test('handles API errors gracefully', async ({ page }) => {
|
|
await page.route('**/api/users', route => {
|
|
route.fulfill({ status: 500 });
|
|
});
|
|
|
|
await page.goto('/users');
|
|
await expect(page.locator('.error-message')).toBeVisible();
|
|
});
|
|
|
|
// Verify request payload
|
|
test('sends correct data to API', async ({ page }) => {
|
|
let requestBody: any;
|
|
|
|
await page.route('**/api/users', async route => {
|
|
requestBody = route.request().postDataJSON();
|
|
await route.fulfill({ status: 201, body: JSON.stringify({ id: 1 }) });
|
|
});
|
|
|
|
await page.goto('/users/new');
|
|
await page.fill('#name', 'Alice');
|
|
await page.click('button[type="submit"]');
|
|
|
|
expect(requestBody).toEqual({ name: 'Alice' });
|
|
});</code></pre>
|
|
<h3>Authentication Patterns</h3>
|
|
<p><strong>Reusable Auth State</strong>:</p>
|
|
<pre><code class="lang-typescript">// global-setup.ts
|
|
async function globalSetup() {
|
|
const browser = await chromium.launch();
|
|
const page = await browser.newPage();
|
|
|
|
await page.goto('https://example.com/login');
|
|
await page.fill('#username', 'admin');
|
|
await page.fill('#password', 'admin123');
|
|
await page.click('button[type="submit"]');
|
|
|
|
// Save authenticated state
|
|
await page.context().storageState({ path: 'auth.json' });
|
|
await browser.close();
|
|
}
|
|
|
|
// playwright.config.ts
|
|
export default defineConfig({
|
|
globalSetup: require.resolve('./global-setup'),
|
|
use: {
|
|
storageState: 'auth.json', // Reuse auth across tests
|
|
},
|
|
});
|
|
|
|
// Tests start already authenticated
|
|
test('access protected page', async ({ page }) => {
|
|
await page.goto('/dashboard'); // Already logged in
|
|
await expect(page.locator('.welcome')).toBeVisible();
|
|
});</code></pre>
|
|
<p><strong>Auth Fixture</strong>:</p>
|
|
<pre><code class="lang-typescript">// fixtures/auth.ts
|
|
export const test = base.extend({
|
|
authenticatedPage: async ({ page }, use) => {
|
|
await page.goto('/login');
|
|
await page.fill('#username', 'admin');
|
|
await page.fill('#password', 'admin123');
|
|
await page.click('button[type="submit"]');
|
|
await page.waitForURL('/dashboard');
|
|
await use(page);
|
|
},
|
|
});
|
|
|
|
// Use in tests
|
|
test('admin can access settings', async ({ authenticatedPage }) => {
|
|
await authenticatedPage.goto('/settings');
|
|
await expect(authenticatedPage.locator('h1')).toContainText('Settings');
|
|
});</code></pre>
|
|
<h3>Visual Regression Testing</h3>
|
|
<pre><code class="lang-typescript">// Playwright visual comparison
|
|
test('homepage visual regression', async ({ page }) => {
|
|
await page.goto('/');
|
|
await expect(page).toHaveScreenshot('homepage.png', {
|
|
fullPage: true,
|
|
maxDiffPixels: 100, // Allow small differences
|
|
});
|
|
});
|
|
|
|
// Component-level screenshot
|
|
test('button visual states', async ({ page }) => {
|
|
await page.goto('/components');
|
|
|
|
const button = page.locator('button.primary');
|
|
await expect(button).toHaveScreenshot('button-default.png');
|
|
|
|
await button.hover();
|
|
await expect(button).toHaveScreenshot('button-hover.png');
|
|
|
|
await button.focus();
|
|
await expect(button).toHaveScreenshot('button-focus.png');
|
|
});
|
|
|
|
// Cross-browser visual testing
|
|
test.describe('cross-browser visuals', () => {
|
|
test.use({ browserName: 'chromium' });
|
|
test('renders correctly in Chrome', async ({ page }) => {
|
|
await page.goto('/');
|
|
await expect(page).toHaveScreenshot('chrome-homepage.png');
|
|
});
|
|
|
|
test.use({ browserName: 'firefox' });
|
|
test('renders correctly in Firefox', async ({ page }) => {
|
|
await page.goto('/');
|
|
await expect(page).toHaveScreenshot('firefox-homepage.png');
|
|
});
|
|
});</code></pre>
|
|
<h3>Handling Complex Interactions</h3>
|
|
<p><strong>File Uploads</strong>:</p>
|
|
<pre><code class="lang-typescript">test('upload profile picture', async ({ page }) => {
|
|
await page.goto('/profile');
|
|
|
|
const fileInput = page.locator('input[type="file"]');
|
|
await fileInput.setInputFiles('path/to/image.png');
|
|
|
|
await page.click('button:has-text("Upload")');
|
|
await expect(page.locator('.success-message')).toBeVisible();
|
|
});</code></pre>
|
|
<p><strong>Drag and Drop</strong>:</p>
|
|
<pre><code class="lang-typescript">test('reorder items with drag and drop', async ({ page }) => {
|
|
await page.goto('/kanban');
|
|
|
|
const source = page.locator('.task[data-id="1"]');
|
|
const target = page.locator('.column[data-status="done"]');
|
|
|
|
await source.dragTo(target);
|
|
|
|
await expect(target.locator('.task[data-id="1"]')).toBeVisible();
|
|
});</code></pre>
|
|
<p><strong>Keyboard Navigation</strong>:</p>
|
|
<pre><code class="lang-typescript">test('navigate menu with keyboard', async ({ page }) => {
|
|
await page.goto('/');
|
|
|
|
await page.keyboard.press('Tab'); // Focus first element
|
|
await page.keyboard.press('Enter'); // Activate
|
|
await page.keyboard.press('ArrowDown'); // Navigate menu
|
|
await page.keyboard.press('Enter'); // Select item
|
|
|
|
await expect(page).toHaveURL('/selected-page');
|
|
});</code></pre>
|
|
<h2>Examples by Framework</h2>
|
|
<h3>Playwright</h3>
|
|
<pre><code class="lang-typescript">// playwright.config.ts
|
|
import { defineConfig } from '@playwright/test';
|
|
|
|
export default defineConfig({
|
|
testDir: './tests',
|
|
fullyParallel: true,
|
|
workers: process.env.CI ? 1 : undefined,
|
|
retries: process.env.CI ? 2 : 0,
|
|
use: {
|
|
baseURL: 'http://localhost:3000',
|
|
trace: 'on-first-retry',
|
|
screenshot: 'only-on-failure',
|
|
},
|
|
projects: [
|
|
{ name: 'chromium', use: { browserName: 'chromium' } },
|
|
{ name: 'firefox', use: { browserName: 'firefox' } },
|
|
{ name: 'webkit', use: { browserName: 'webkit' } },
|
|
],
|
|
});
|
|
|
|
// tests/example.spec.ts
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
test('complete user journey', async ({ page }) => {
|
|
// Navigate to homepage
|
|
await page.goto('/');
|
|
await expect(page.locator('h1')).toContainText('Welcome');
|
|
|
|
// Search for product
|
|
await page.fill('input[name="search"]', 'laptop');
|
|
await page.click('button[type="submit"]');
|
|
await page.waitForURL('**/search?q=laptop');
|
|
|
|
// Add to cart
|
|
await page.click('.product-card:first-child .add-to-cart');
|
|
await expect(page.locator('.cart-count')).toContainText('1');
|
|
|
|
// Checkout
|
|
await page.click('.cart-icon');
|
|
await page.click('button:has-text("Checkout")');
|
|
|
|
// Fill form
|
|
await page.fill('#email', '[email protected]');
|
|
await page.fill('#card', '4242424242424242');
|
|
await page.click('button:has-text("Pay")');
|
|
|
|
// Verify success
|
|
await expect(page.locator('.success-message')).toBeVisible();
|
|
await expect(page).toHaveURL('**/order-confirmation');
|
|
});</code></pre>
|
|
<h3>Cypress</h3>
|
|
<pre><code class="lang-typescript">// cypress/e2e/user-journey.cy.ts
|
|
describe('User Journey', () => {
|
|
beforeEach(() => {
|
|
cy.visit('/');
|
|
});
|
|
|
|
it('completes purchase flow', () => {
|
|
// Search
|
|
cy.get('input[name="search"]').type('laptop');
|
|
cy.get('button[type="submit"]').click();
|
|
|
|
// Add to cart
|
|
cy.get('.product-card').first().find('.add-to-cart').click();
|
|
cy.get('.cart-count').should('contain', '1');
|
|
|
|
// Checkout
|
|
cy.get('.cart-icon').click();
|
|
cy.contains('button', 'Checkout').click();
|
|
|
|
// Fill form
|
|
cy.get('#email').type('[email protected]');
|
|
cy.get('#card').type('4242424242424242');
|
|
cy.contains('button', 'Pay').click();
|
|
|
|
// Verify
|
|
cy.get('.success-message').should('be.visible');
|
|
cy.url().should('include', '/order-confirmation');
|
|
});
|
|
});
|
|
|
|
// Custom commands (cypress/support/commands.ts)
|
|
Cypress.Commands.add('login', (username: string, password: string) => {
|
|
cy.visit('/login');
|
|
cy.get('#username').type(username);
|
|
cy.get('#password').type(password);
|
|
cy.get('button[type="submit"]').click();
|
|
cy.url().should('include', '/dashboard');
|
|
});
|
|
|
|
// Use custom command
|
|
it('admin accesses settings', () => {
|
|
cy.login('admin', 'admin123');
|
|
cy.visit('/settings');
|
|
cy.contains('h1', 'Settings').should('be.visible');
|
|
});</code></pre>
|
|
<h3>Selenium (Python)</h3>
|
|
<pre><code class="lang-python"># test_user_journey.py
|
|
from selenium import webdriver
|
|
from selenium.webdriver.common.by import By
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
|
from selenium.webdriver.support import expected_conditions as EC
|
|
import pytest
|
|
|
|
@pytest.fixture
|
|
def driver():
|
|
driver = webdriver.Chrome()
|
|
driver.implicitly_wait(10)
|
|
yield driver
|
|
driver.quit()
|
|
|
|
def test_user_login(driver):
|
|
driver.get("https://example.com/login")
|
|
|
|
# Fill form
|
|
driver.find_element(By.ID, "username").send_keys("alice")
|
|
driver.find_element(By.ID, "password").send_keys("secret")
|
|
driver.find_element(By.CSS_SELECTOR, "button[type='submit']").click()
|
|
|
|
# Wait for dashboard
|
|
WebDriverWait(driver, 10).until(
|
|
EC.presence_of_element_located((By.CLASS_NAME, "welcome-message"))
|
|
)
|
|
|
|
assert "Dashboard" in driver.title</code></pre>
|
|
<h2>Checklist</h2>
|
|
<p><strong>Before Writing E2E Tests</strong>:</p>
|
|
<ul><li>[ ] Identify critical user paths to test</li><li>[ ] Set up test environment (test database, API)</li><li>[ ] Choose E2E framework (Playwright recommended)</li><li>[ ] Plan Page Object Model structure</li><li>[ ] Configure browser targets (Chrome, Firefox, Safari)</li></ul>
|
|
<p><strong>Writing Tests</strong>:</p>
|
|
<ul><li>[ ] Use Page Object Model for maintainability</li><li>[ ] Implement proper waiting strategies (avoid sleep)</li><li>[ ] Test realistic user workflows (multi-step)</li><li>[ ] Mock external services when appropriate</li><li>[ ] Handle authentication (fixtures or global setup)</li><li>[ ] Add visual regression tests for critical pages</li></ul>
|
|
<p><strong>Reliability</strong>:</p>
|
|
<ul><li>[ ] Tests pass consistently (no flakiness)</li><li>[ ] Use data-testid for stable selectors</li><li>[ ] Avoid timing-dependent assertions</li><li>[ ] Retry failed tests in CI (2-3 retries)</li><li>[ ] Clean test data between runs</li></ul>
|
|
<p><strong>Performance</strong>:</p>
|
|
<ul><li>[ ] Run tests in parallel (multiple workers)</li><li>[ ] Reuse authentication state</li><li>[ ] Limit visual regression tests (slow)</li><li>[ ] Keep test count focused (critical paths only)</li></ul>
|
|
<p><strong>After Writing Tests</strong>:</p>
|
|
<ul><li>[ ] Tests run in CI/CD pipeline</li><li>[ ] Screenshots/videos on failure</li><li>[ ] Clear failure messages</li><li>[ ] Tests complete in reasonable time (< 10 min suite)</li></ul>
|
|
<h2>Anti-Patterns</h2>
|
|
<pre><code>❌ NEVER: Use sleep/wait for fixed time
|
|
→ Flaky tests, slow execution
|
|
|
|
❌ NEVER: Test everything with E2E
|
|
→ Slow feedback, expensive to maintain
|
|
|
|
❌ NEVER: Use fragile selectors (nth-child, absolute XPath)
|
|
→ Breaks with UI changes
|
|
|
|
❌ NEVER: Share state between tests
|
|
→ Order dependencies, flakiness
|
|
|
|
❌ NEVER: Skip Page Object Model
|
|
→ Duplicated selectors, hard to maintain
|
|
|
|
❌ NEVER: Test browser quirks with E2E
|
|
→ Use unit tests for logic, E2E for flows
|
|
|
|
❌ NEVER: Ignore flaky tests
|
|
→ Undermines trust in test suite</code></pre>
|
|
<h2>Related Skills</h2>
|
|
<p><strong>Foundation</strong>:</p>
|
|
<ul><li><code>unit-testing-patterns.md</code> - Testing individual components</li><li><code>integration-testing.md</code> - API and database testing</li></ul>
|
|
<p><strong>E2E Specific</strong>:</p>
|
|
<ul><li><code>visual-regression-testing.md</code> - Advanced screenshot comparison</li><li><code>cross-browser-testing.md</code> - Multi-browser strategies</li></ul>
|
|
<p><strong>Supporting</strong>:</p>
|
|
<ul><li><code>test-driven-development.md</code> - TDD workflow</li><li><code>test-coverage-strategy.md</code> - What to test</li></ul>
|
|
<p><strong>Tools</strong>:</p>
|
|
<ul><li>Playwright: Modern, multi-browser, fast</li><li>Cypress: Great DX, Chromium-only</li><li>Selenium: Legacy, wide language support</li><li>Puppeteer: Chrome-only, good for scraping</li></ul>
|
|
<h2>Level 3: Resources</h2>
|
|
<h3>Comprehensive Reference</h3>
|
|
<p><strong><a href="resources/REFERENCE.md">REFERENCE.md</a></strong> (99KB) - Complete E2E testing guide:</p>
|
|
<ol><li>E2E Testing Philosophy and Strategy</li><li>The Testing Pyramid and E2E Position</li><li>Choosing an E2E Framework (Playwright vs Cypress vs Selenium)</li><li>Page Object Model (POM) - Design patterns and architecture</li><li>Selector Strategies (CSS, XPath, test IDs, accessibility)</li><li>Waiting Strategies (explicit, implicit, auto-wait)</li><li>Authentication and Session Management</li><li>Test Data Management (fixtures, factories, seeding)</li><li>Network Interception and Mocking</li><li>Visual Regression Testing</li><li>Cross-Browser Testing</li><li>Handling Complex Interactions (drag-drop, file uploads, iframes)</li><li>Test Organization and Structure</li><li>Flakiness Reduction Techniques</li><li>Parallelization and Performance</li><li>CI/CD Integration</li><li>Debugging Strategies</li><li>Accessibility Testing</li><li>Mobile and Responsive Testing</li><li>Common Anti-Patterns</li><li>Best Practices</li><li>Real-World Test Suites</li></ol>
|
|
<p><strong>Coverage</strong>: Framework selection, POM architecture, selector strategies, waiting patterns, authentication, mocking, visual regression, cross-browser, flakiness reduction, CI/CD, debugging, accessibility, mobile testing, and production examples.</p>
|
|
<h3>Automation Scripts</h3>
|
|
<p><strong><a href="resources/scripts/run_e2e_tests.py">run_e2e_tests.py</a></strong> (600 lines) Execute E2E test suites with comprehensive orchestration and reporting:</p>
|
|
<pre><code class="lang-bash"># Run Playwright tests across browsers
|
|
./run_e2e_tests.py --framework playwright --browsers chromium firefox webkit
|
|
|
|
# Run with test environment
|
|
./run_e2e_tests.py --start-env --compose-file docker-compose.test.yml
|
|
|
|
# Parallel execution with retries
|
|
./run_e2e_tests.py --parallel --retries 2 --timeout 60
|
|
|
|
# Output JSON results
|
|
./run_e2e_tests.py --json</code></pre>
|
|
<p><strong>Features</strong>:</p>
|
|
<ul><li>Multi-framework support (Playwright, Cypress, Selenium)</li><li>Browser matrix testing (chromium, firefox, webkit, edge)</li><li>Parallel execution with configurable workers</li><li>Retry logic for flaky tests</li><li>Test environment orchestration (Docker Compose)</li><li>Detailed reporting with pass rates</li><li>Artifact collection (screenshots, videos, traces)</li><li>JSON output for CI integration</li></ul>
|
|
<p><strong><a href="resources/scripts/analyze_flakiness.py">analyze_flakiness.py</a></strong> (600 lines) Analyze E2E test stability and identify flaky tests:</p>
|
|
<pre><code class="lang-bash"># Analyze flakiness over 30 days
|
|
./analyze_flakiness.py --results-dir test-results --days 30
|
|
|
|
# Find tests with >10% failure rate
|
|
./analyze_flakiness.py --threshold 0.1 --min-runs 5
|
|
|
|
# Detailed analysis with recommendations
|
|
./analyze_flakiness.py --verbose
|
|
|
|
# Export as JSON
|
|
./analyze_flakiness.py --json</code></pre>
|
|
<p><strong>Features</strong>:</p>
|
|
<ul><li>Historical analysis across multiple test runs</li><li>Flake rate calculation per test</li><li>Root cause identification (timeouts, timing, network, state, race conditions)</li><li>Severity classification (high, medium, low)</li><li>Browser-specific flakiness detection</li><li>Common error pattern recognition</li><li>Actionable recommendations</li><li>Trend analysis over time</li></ul>
|
|
<p><strong><a href="resources/scripts/generate_page_object.py">generate_page_object.py</a></strong> (800 lines) Generate Page Object Model classes from HTML, URLs, or existing tests:</p>
|
|
<pre><code class="lang-bash"># Generate from URL
|
|
./generate_page_object.py --url https://example.com/login \
|
|
--framework playwright --language typescript
|
|
|
|
# Generate from HTML file
|
|
./generate_page_object.py --html page.html --framework cypress
|
|
|
|
# Generate from existing test
|
|
./generate_page_object.py --test tests/login.spec.ts --framework playwright
|
|
|
|
# Output as JSON structure
|
|
./generate_page_object.py --url https://example.com/dashboard --json</code></pre>
|
|
<p><strong>Features</strong>:</p>
|
|
<ul><li>Multi-framework support (Playwright, Cypress, Selenium)</li><li>Multi-language output (TypeScript, Python, Java)</li><li>HTML parsing and element extraction</li><li>Test ID discovery (data-testid, data-test, data-cy)</li><li>Action inference (login, search, form submission)</li><li>Component composition</li><li>Selector optimization</li><li>Best practice patterns</li></ul>
|
|
<h3>Production Examples</h3>
|
|
<p><strong>Playwright Examples</strong> (<a href="resources/examples/playwright/">resources/examples/playwright/</a>):</p>
|
|
<ul><li><strong>fixtures/</strong> - Custom fixtures for authentication, test data</li><li><strong>pages/</strong> - Page Object Model implementations</li><li><strong>tests/</strong> - Complete test suites with real-world patterns</li></ul>
|
|
<p><strong>Cypress Examples</strong> (<a href="resources/examples/cypress/">resources/examples/cypress/</a>):</p>
|
|
<ul><li>Complete e-commerce checkout flow</li><li>Custom commands and utilities</li><li>API mocking strategies</li><li>Visual regression tests</li></ul>
|
|
<p><strong>Selenium Examples</strong> (<a href="resources/examples/selenium/">resources/examples/selenium/</a>):</p>
|
|
<ul><li>Python pytest integration</li><li>Page Object Model architecture</li><li>Cross-browser test configuration</li></ul>
|
|
<p><strong>Configuration Examples</strong> (<a href="resources/examples/config/">resources/examples/config/</a>):</p>
|
|
<ul><li><code>playwright.config.ts</code> - Multi-browser, parallel, retry config</li><li><code>cypress.config.ts</code> - Video recording, screenshots, baseUrl</li><li><code>pytest.ini</code> - Selenium with pytest configuration</li></ul>
|
|
<p><strong>Docker Examples</strong> (<a href="resources/examples/docker/">resources/examples/docker/</a>):</p>
|
|
<ul><li><code>docker-compose.test.yml</code> - Complete test environment</li><li><code>Dockerfile.playwright</code> - Playwright container image</li><li><code>Dockerfile.cypress</code> - Cypress container image</li></ul>
|
|
<h3>Usage Workflow</h3>
|
|
<p><strong>1. Choose Framework and Setup</strong>:</p>
|
|
<pre><code class="lang-bash"># Playwright (recommended)
|
|
npm install -D @playwright/test
|
|
npx playwright install
|
|
|
|
# Cypress
|
|
npm install -D cypress
|
|
|
|
# Selenium + pytest
|
|
pip install selenium pytest pytest-xdist</code></pre>
|
|
<p><strong>2. Generate Page Objects</strong>:</p>
|
|
<pre><code class="lang-bash"># Generate from your application
|
|
./generate_page_object.py --url http://localhost:3000/login \
|
|
--framework playwright --output-dir tests/pages/</code></pre>
|
|
<p><strong>3. Write Tests Using POM</strong>:</p>
|
|
<pre><code class="lang-typescript">// tests/auth.spec.ts
|
|
import { test, expect } from '@playwright/test';
|
|
import { LoginPage } from './pages/LoginPage';
|
|
|
|
test('user can login', async ({ page }) => {
|
|
const loginPage = new LoginPage(page);
|
|
await loginPage.goto();
|
|
await loginPage.login('[email protected]', 'password123');
|
|
|
|
await expect(page).toHaveURL('/dashboard');
|
|
});</code></pre>
|
|
<p><strong>4. Run Tests</strong>:</p>
|
|
<pre><code class="lang-bash"># Local development
|
|
./run_e2e_tests.py --framework playwright --headed --verbose
|
|
|
|
# CI/CD pipeline
|
|
./run_e2e_tests.py --framework playwright \
|
|
--browsers chromium firefox webkit \
|
|
--parallel --retries 2 \
|
|
--start-env --compose-file docker-compose.test.yml \
|
|
--json > results.json</code></pre>
|
|
<p><strong>5. Analyze Flakiness</strong>:</p>
|
|
<pre><code class="lang-bash"># After accumulating test history
|
|
./analyze_flakiness.py --results-dir test-results \
|
|
--days 14 --threshold 0.15 --verbose</code></pre>
|
|
<p><strong>6. Iterate and Improve</strong>:</p>
|
|
<ul><li>Review flakiness report recommendations</li><li>Update selectors to use test IDs</li><li>Add explicit waits for dynamic content</li><li>Mock flaky external dependencies</li><li>Refactor highly flaky tests</li></ul>
|
|
<h3>Integration Points</h3>
|
|
<p><strong>CI/CD (GitHub Actions)</strong>:</p>
|
|
<pre><code class="lang-yaml">- name: Run E2E Tests
|
|
run: |
|
|
./run_e2e_tests.py \
|
|
--framework playwright \
|
|
--parallel \
|
|
--retries 2 \
|
|
--json > results.json
|
|
|
|
- name: Analyze Flakiness
|
|
if: always()
|
|
run: |
|
|
./analyze_flakiness.py --json > flakiness.json
|
|
|
|
- name: Upload Artifacts
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: e2e-results
|
|
path: |
|
|
test-results/
|
|
results.json
|
|
flakiness.json</code></pre>
|
|
<p><strong>Local Development</strong>:</p>
|
|
<pre><code class="lang-bash"># Quick feedback loop
|
|
npm run dev & # Start app
|
|
./run_e2e_tests.py --headed --pattern "login*"</code></pre>
|
|
<p><strong>Quality Gates</strong>:</p>
|
|
<pre><code class="lang-bash"># Enforce flakiness threshold
|
|
if [ $(./analyze_flakiness.py --json | jq '.summary.overall_flake_rate') -gt 0.05 ]; then
|
|
echo "Flake rate >5%, failing build"
|
|
exit 1
|
|
fi</code></pre>
|
|
<h3>Best Practices from Resources</h3>
|
|
<p><strong>From REFERENCE.md</strong>:</p>
|
|
<ul><li>Follow the 10/20/70 rule (10% E2E, 20% integration, 70% unit)</li><li>Use Page Object Model for all E2E tests</li><li>Prefer data-testid selectors over CSS/XPath</li><li>Implement auto-wait (Playwright) or explicit waits</li><li>Mock external dependencies</li><li>Run critical path tests first</li><li>Parallelize independent tests</li><li>Retry flaky tests (max 2-3 retries)</li><li>Clean test data between runs</li><li>Use visual regression sparingly</li></ul>
|
|
<p><strong>From Scripts</strong>:</p>
|
|
<ul><li>Automate test execution with run_e2e_tests.py</li><li>Monitor flakiness continuously</li><li>Generate Page Objects to reduce boilerplate</li><li>Use JSON output for CI integration</li><li>Collect artifacts (screenshots, videos) on failure</li><li>Start test environment automatically</li><li>Configure retries per test or suite</li><li>Analyze trends over time</li></ul>
|
|
<p><strong>From Examples</strong>:</p>
|
|
<ul><li>Organize tests by feature/workflow</li><li>Use fixtures for authentication</li><li>Create reusable components</li><li>Document test intent clearly</li><li>Handle loading/error states</li><li>Test keyboard navigation</li><li>Verify accessibility</li><li>Test responsive layouts</li></ul>
|
|
<footer>
|
|
<div class="fmap">
|
|
<div><b>Build</b>
|
|
<a href="https://hanzo.app">hanzo.app</a> app builder
|
|
<a href="https://hanzo.codes">hanzo.codes</a> code with an agent
|
|
<a href="https://hanzoskills.com">hanzoskills.com</a> what an agent reads</div>
|
|
<div><b>Run</b>
|
|
<a href="https://console.hanzo.ai">console.hanzo.ai</a> cloud console
|
|
<a href="https://api.hanzo.ai">api.hanzo.ai</a> the API</div>
|
|
<div><b>Account</b>
|
|
<a href="https://hanzo.id">hanzo.id</a> sign in
|
|
<a href="https://pay.hanzo.ai">pay.hanzo.ai</a> top up
|
|
<a href="https://billing.hanzo.ai">billing.hanzo.ai</a> invoices and usage</div>
|
|
<div><b>Company</b>
|
|
<a href="https://hanzo.ai">hanzo.ai</a> canonical
|
|
<a href="https://hanzo.ventures">hanzo.ventures</a> ventures</div>
|
|
</div>
|
|
<div class="fend"><a href="/testing-e2e-testing.md">This page as plain text</a> · <a href="/llms.txt">Index for agents</a></div>
|
|
</footer>
|
|
</div></body></html> |