Lesson 1 of 85 min read
Why automation testers need JavaScript
Playwright, Cypress, WebdriverIO and Postman scripts all use JavaScript or TypeScript. A little JS unlocks all of them.
Key takeaways
- 1Install Node.js (LTS) and VS Code; run a file with: node hello.js
- 2console.log() prints values, your first debugging tool.
- 3You don't need to be a developer: tests use a small, repeatable part of the language.
Your first script
// hello.js
const tester = 'Asha';
console.log('Hello ' + tester + ', ready to automate!');
// Run in a terminal:
// node hello.js
Go deeper
Expert notes beyond the basics
- 01
Node.js is just JavaScript outside the browser
Node.js takes the same JavaScript engine that runs in Chrome (V8) and lets it run from a terminal, with no web page needed. That is exactly what Playwright and most test runners use: your test file is a plain .js or .ts file executed by Node, not loaded in a browser tab. When you run node hello.js, Node reads the file top to bottom and executes each statement. Knowing this helps when debugging: if a script 'does nothing', check you ran it with node, not opened it as a webpage. Most CI servers also run tests this way, inside a Docker container with Node installed, so the same script behaves the same locally and in CI.
- 02
console.log is your first and most-used debugging tool
Before learning breakpoints or debuggers, console.log(value) prints whatever you pass it, including objects and arrays, which Node formats for readability. In automation you will sprinkle console.log(await page.title()) or console.log(response.status()) while writing a new test, then delete or replace it with proper assertions once it works. Playwright also has its own trace viewer and the DEBUG=pw:api environment variable for deeper logging, but console.log remains the fastest way to answer 'what value did I actually get here' when a test behaves unexpectedly.
- 03
npm and package.json tie your scripts together
Real projects are not single files; they use npm (Node Package Manager) to install libraries like @playwright/test, and a package.json file that lists those dependencies and defines scripts such as "test": "playwright test". Running npm install reads package.json and downloads everything into a node_modules folder. When you clone a Playwright project for the first time, npm install (or npm ci in CI) is the first command you run, before npx playwright test. Forgetting this step causes 'module not found' errors that have nothing to do with your test logic.
- 04
Why TypeScript often follows JavaScript for testers
TypeScript is JavaScript with optional type annotations, for example function login(email: string, password: string): Promise<void>. Playwright projects scaffolded with npm init playwright@latest default to TypeScript because it catches mistakes like passing a number where a string is expected before the test even runs, which is valuable in large suites maintained by many people. You do not need to master TypeScript to start; almost everything in this course is valid in both languages, and tools quietly infer types for you until you choose to add them.
Common mistakes to avoid
- - Trying to run a script by double-clicking the file instead of using node filename.js in a terminal.
- - Confusing Node.js (runs JavaScript on your machine) with a browser (runs JavaScript inside a web page).
- - Skipping npm install and then being confused by 'Cannot find module' errors.
- - Thinking you need to be a full developer before touching automation; most test code reuses a small, repeated set of patterns.
First Node.js commands cheat sheet
| Command | What it does |
|---|---|
| node file.js | Runs file.js with Node.js |
| npm install | Installs dependencies listed in package.json |
| npm init playwright@latest | Scaffolds a new Playwright project |
| npx playwright test | Runs the Playwright test suite |
| console.log(value) | Prints value to the terminal for debugging |
Try it yourself
Write a one-line JavaScript file called version.js that imports nothing and simply prints the running Node.js version to the console, then write the terminal command to run it.
Write your answer on paper or in a sheet first, then compare.
Interview questions
How to answer like a confident QA engineer
- Q1
Why did you choose JavaScript for automation?
Model answer
Modern tools like Playwright and Cypress are built for it, the same language runs the web app, and it has a huge ecosystem. TypeScript adds type checks on top, which helps keep large test suites reliable.
- Q2
What is Node.js used for in test automation?
Model answer
Node.js runs JavaScript or TypeScript outside the browser, so it can execute test scripts, call APIs with fetch, read files, and drive tools like Playwright from the command line. Test runners, reporters and CI pipelines all run on top of Node.
- Q3
What is the difference between JavaScript and TypeScript?
Model answer
JavaScript is the language browsers and Node run directly. TypeScript adds optional static types on top and is compiled down to plain JavaScript before running. TypeScript catches type mistakes during development, which helps a lot in large test suites, but anything valid in TypeScript is built on JavaScript fundamentals.
- Q4
What does npm install do?
Model answer
It reads the dependencies listed in package.json and downloads them into a node_modules folder so the project can use them. It is usually the first command to run after cloning a test automation repository, before trying to run any tests.
Knowledge check
+5 points
Which command runs a JavaScript file called test.js?
