|

Day 6 of 100: Functions — Building Reusable Test Helpers

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


Functions turn repeated test steps into reusable helpers. The foundation of every utility file.

Contents

Declaring Functions

// Function declaration — hoisted
function buildUrl(path) {
  return 'https://api.example.com' + path;
}

// Function expression
const validate = function(status) {
  return status >= 200 && status < 300;
};

console.log(buildUrl('/users'));  // https://api.example.com/users
console.log(validate(201));        // true

🚀 Level Up Your Playwright

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

Parameters and Defaults

function createUser(name, role = 'viewer', active = true) {
  return { name, role, active };
}

createUser('Jane');                  // role defaults to viewer
createUser('Admin', 'admin', false); // all explicit

Return Early, Return Often

function getTestEnv(name) {
  if (name === 'prod') return 'https://example.com';
  if (name === 'staging') return 'https://staging.example.com';
  return 'http://localhost:3000';
}

Tomorrow (Day 7): Arrow functions — the syntax Playwright uses everywhere.

🎓 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.