1. JavaScript Basics for Automation
Even if you’re a Test Automation Engineer, you need to understand the basics of JavaScript.
Core Concepts
-
Variables:
let
,const
,var
-
Data Types: String, Number, Boolean, Object, Array
-
Operators:
+
,-
,*
,/
,%
,===
,!==
,&&
,||
-
Functions:
-
Conditional Statements:
if
,else if
,else
,switch
-
Loops:
for
,while
,for...of
,for...in
-
Arrays & Objects:
-
DOM Manipulation (if needed for front-end testing):
2. Setting Up Your Automation Environment
Prerequisites
-
Install Node.js (comes with npm)
-
Install a code editor: VS Code recommended
Create a Project
3. Choosing an Automation Framework
There are several frameworks for JavaScript automation:
Popular Frameworks
-
Playwright
-
Modern, cross-browser automation
-
Supports JavaScript/TypeScript
-
-
Puppeteer
-
Headless Chrome automation
-
-
Selenium WebDriver (via WebDriverIO)
-
Traditional, widely used
-
-
Cypress
-
End-to-end testing, developer-friendly
-
We’ll focus on Playwright, which is widely used today.
4. Installing Playwright
npm i -D @playwright/test
npx playwright install
@playwright/test
– test runner-
npx playwright install
– installs browsers (Chromium, Firefox, WebKit)
5. Writing Your First Test
Create a file: example.spec.js
Run the test:
6. Playwright Concepts for Automation
-
Selectors:
page.locator('selector')
-
Actions:
click()
,fill()
,hover()
,selectOption()
-
Assertions:
expect(locator).toHaveText()
-
Waiting:
page.waitForSelector()
,await locator.waitFor()
-
Screenshots & Videos:
7. Organizing Tests
-
Page Object Model (POM)
-
Keeps locators and actions in a separate file
-
-
Test Suite Structure
8. Integration with CI/CD
-
Run tests in Jenkins/GitHub Actions/GitLab CI
-
Example GitHub Actions workflow:
9. Advanced Automation Topics
-
Parallel Execution
-
Data-Driven Testing
-
Handling Popups/Alerts
-
API Testing
10. Reporting and Debugging
-
Playwright Reports:
-
Debug Mode:
-
Tracing (record test run for debugging):
11. Best Practices
-
Use Page Object Model for maintainability.
-
Keep selectors unique and stable.
-
Use explicit waits instead of random sleep.
-
Integrate with CI/CD for automated execution.
-
Use environment variables for sensitive data.
-
Write reusable utility functions for repeated actions.