Day 5 of 100: Loops — Data-Driven Tests and Retry Logic
Day 5 of 100 — 100 Days of Playwright with TypeScript Challenge. Phase: JavaScript Fundamentals. JavaScript (Days 1-33) → TypeScript (Days 34-63) → Playwright (Days 64-96) → AI Framework Capstone (Days 97-100).
🎭 Want to master this with real projects? Join the Playwright Automation Mastery course at The Testing Academy.
Loops drive data-driven tests, retries, and bulk validations.
Contents
The Loops That Matter
const browsers = ['chromium', 'firefox', 'webkit'];
// for...of — the workhorse for test data
for (const browser of browsers) {
console.log('Testing on ' + browser);
}
// Classic for — when you need the index
for (let i = 0; i < browsers.length; i++) {
console.log(i + ': ' + browsers[i]);
}
// while — retry pattern
let attempts = 0;
let success = false;
while (!success && attempts < 3) {
attempts++;
success = attempts === 2; // simulate pass on 2nd try
}
🚀 Level Up Your Playwright
From locators to CI pipelines — build a production-grade Playwright + TypeScript framework step by step.
Data-Driven Test Pattern (Preview)
const loginCases = [
{ email: 'valid@test.com', pass: 'ok123', expect: 'dashboard' },
{ email: 'bad@test.com', pass: 'wrong', expect: 'error' },
{ email: '', pass: 'ok123', expect: 'error' },
];
for (const tc of loginCases) {
console.log('Case: ' + tc.email + ' expects ' + tc.expect);
// In Playwright this becomes: test('login ' + tc.email, ...)
}
break and continue
for (const tc of loginCases) {
if (tc.skip) continue; // skip marked cases
if (tc.critical && failed) break; // stop on critical failure
}
Tomorrow (Day 6): Functions — reusable test helpers.
🎓 Master Playwright End to End
Join hundreds of SDETs building real automation frameworks. Lifetime access, hands-on projects, and a job-ready portfolio.
