|

Day 8 of 100: Arrays — Storing and Slicing Test Data

Day 8 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.


Arrays hold test cases, expected values, retrieved rows. Core operations today, power methods tomorrow.

Contents

Creating and Accessing

const browsers = ['chromium', 'firefox', 'webkit'];
browsers[0];          // 'chromium'
browsers.length;      // 3
browsers.at(-1);      // 'webkit' — last element
browsers.includes('firefox'); // true

Adding and Removing

const results = [];
results.push('pass');        // add to end
results.unshift('setup-ok'); // add to start
const last = results.pop();  // remove from end
results.indexOf('setup-ok'); // 0

🚀 Level Up Your Playwright

From locators to CI pipelines — build a production-grade Playwright + TypeScript framework step by step.

Slicing Without Mutation

const tests = ['t1', 't2', 't3', 't4', 't5'];
const firstTwo = tests.slice(0, 2);  // ['t1','t2'] — original untouched
const shard = tests.slice(2);        // ['t3','t4','t5']

// splice MUTATES — avoid in test code
// tests.splice(1, 2) changes the original array

QA Pattern: Collecting Failures

const failures = [];
for (const tc of [{id:1,ok:true},{id:2,ok:false},{id:3,ok:false}]) {
  if (!tc.ok) failures.push(tc.id);
}
console.log('Failed: ' + failures.join(', ')); // Failed: 2, 3

Tomorrow (Day 9): Array power methods — map, filter, reduce, find.

🎓 Master Playwright End to End

Join hundreds of SDETs building real automation frameworks. Lifetime access, hands-on projects, and a job-ready portfolio.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.