1. JavaScript Fundamentals for Test Automation

JavaScript Variables: const vs let vs var

In modern test automation, we avoid var due to variable hoisting and scope leak issues: - const: For values that remain fixed during test runs (Base URLs, selectors, timeouts). - let: For values that change dynamically (retry counts, loop indices, status flags).
const baseUrl = "https://targetqa.com";
let retryAttempts = 0;
retryAttempts += 1;

Primitive Data Types

1. string: Test locators, text assertions ("Sign In"). 2. number: Element counts, status codes (200, 5000). 3. boolean: Element states (true, false). 4. null: Deliberate empty value. 5. undefined: Unassigned variable.

Loops for Automation

// Loop through test items with for...of:
const menuItems = ["Dashboard", "Orders", "Settings"];
for (const item of menuItems) {
  console.log("Validating navigation item: " + item);
}

// Inspect configuration keys with for...in:
const config = { browser: "chromium", headless: true };
for (const key in config) {
console.log(key + ": " + config[key]);
}

Task

  • Complete the verification function:
  • 1. Declare const expectedTitle = "TargetQA - Learn Automation".
  • 2. Use if/else to check if actualTitle === expectedTitle.
  • 3. Return true if matching, otherwise false.
πŸ’‘Common doubts
Did you like the problem?
Lesson 1 of 35
JavaScript
Loading code editor…
Next