|

Day 12 of 100: String Methods — Parsing Text and URLs

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


Tests constantly inspect text: page content, URLs, error messages. These methods do the work.

Contents

The Inspection Set

const msg = '  Order #1234 confirmed!  ';

msg.trim();                  // strip whitespace
msg.includes('confirmed');   // true
msg.startsWith('  Order');   // true
msg.toLowerCase();           // normalize before compare
msg.replace('!', '.');       // swap text
msg.split('#');              // ['  Order ', '1234 confirmed!  ']

🚀 Level Up Your Playwright

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

Extracting Values

const url = 'https://shop.com/orders/1234?status=paid';

// Get order id from URL
const id = url.split('/orders/')[1].split('?')[0];  // '1234'

// Better: URL API
const u = new URL(url);
u.pathname;                    // '/orders/1234'
u.searchParams.get('status');  // 'paid'

QA Pattern: Normalize Before Assert

function normalize(text) {
  return text.trim().toLowerCase().replace(/\s+/g, ' ');
}
normalize('  Welcome   Back ') === 'welcome back'; // true
// Avoids flaky failures from whitespace differences

Tomorrow (Day 13): Template literals — readable dynamic strings.

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