Introduction
After understanding what Playwright is, the next step is installing it on your computer.
When I started learning Playwright, I thought installation would take just a few minutes. But I quickly realised there were a few things I needed to understand first—like Node.js, npm, and even which terminal to use.
I also faced some common issues, such as npm not being recognised or confusion about whether to use Command Prompt or PowerShell.
In this article, I'll show you the complete installation process and share the solutions to the common problems I encountered.
By the end of this guide, you'll have Playwright with TypeScript installed and you'll be able to run your first automation test.
Prerequisites
Before installing Playwright, make sure you have:
- A Windows, macOS, or Linux computer
- Internet connection
- Basic knowledge of JavaScript or TypeScript (helpful but not mandatory)
- Administrator permission to install software
Step 1: Install Node.js
Playwright runs on Node.js, so this is the first thing you need.
Visit the official Node.js website and download the LTS (Long-Term Support) version.
After installation, restart your computer if prompted.
Step 2: Verify Node.js Installation
Open Command Prompt or PowerShell and type:
node -v
Example output:
v22.18.0
If you see a version number, Node.js has been installed successfully.
Step 3: Check npm Version
One of the most common issues beginners face is with npm.
npm stands for Node Package Manager. It installs Playwright and other JavaScript packages.
To verify npm is installed, run:
npm -v
Example output:
10.9.3
If you see a version number, npm is working correctly.
What if "npm is not recognised"?
You might see an error like:
'npm' is not recognised as an internal or external command.
This usually means:
- Node.js was not installed correctly.
- The PATH environment variable was not updated.
- The terminal was open before Node.js was installed.
Solution
- Close the terminal and open it again.
- Restart your computer.
- Reinstall Node.js if necessary.
- Run
node -vandnpm -vagain.
This is one of the most common problems beginners encounter, so don't worry if it happens.
Step 4: Install Visual Studio Code
Download and install Visual Studio Code (VS Code).
VS Code is one of the most popular editors for Playwright development because it provides:
- Code suggestions
- Built-in terminal
- Debugging support
- Extensions for JavaScript and TypeScript
Which Terminal Should You Use?
Many beginners ask:
Should I use Command Prompt or PowerShell?
The answer is simple:
✅ Both work perfectly.
Personally, I use the VS Code integrated terminal, which opens PowerShell by default on Windows. It keeps everything in one place, so I don't need to switch between applications.
If you're following online tutorials, the commands usually work the same in Command Prompt, PowerShell, or the VS Code terminal.
Step 5: Create a Playwright Project
Open VS Code.
Open the terminal (Terminal → New Terminal).
Create a new project:
mkdir PlaywrightDemo
Move into the folder:
cd PlaywrightDemo
Now install Playwright:
The installer will ask a few questions.
I recommend selecting:
- TypeScript → Yes
- Tests folder → Default
- GitHub Actions → Optional
- Install browsers → Yes
Once completed, your Playwright project is ready.
Step 6: Understand the Project Structure
After installation, you'll see several files and folders.
tests/
Contains all your test scripts.
Example:
login.spec.ts
playwright.config.ts
This is the main configuration file.
Here you can configure:
- Browser
- Base URL
- Timeout
- Reporter
- Parallel execution
package.json
This file stores:
- Project information
- Dependencies
- Scripts
package-lock.json
Keeps track of the exact package versions installed.
node_modules
Contains all downloaded packages required for Playwright.
You should never edit files inside this folder.
tsconfig.json
Contains TypeScript compiler settings.
Step 7: Run Your First Test
Run:
npx playwright test
Playwright will automatically launch the browser and execute the sample test.
If everything is installed correctly, you'll see:
1 Passed
Congratulations! 🎉
You've just executed your first Playwright automation test.
Step 8: Generate the HTML Report
One feature I really like about Playwright is its built-in HTML Report.
To open the report:
npx playwright show-report
The report displays:
- Passed tests
- Failed tests
- Execution time
- Error details
- Screenshots (if configured)
This makes debugging much easier.
Common Installation Problems and Solutions
1. npm is not recognised
Reason:
Node.js is missing or PATH isn't updated.
Solution:
Restart the terminal or reinstall Node.js.
2. node command not working
Solution:
Run:
node -v
If it fails, reinstall Node.js.
3. PowerShell blocks scripts
Sometimes PowerShell displays an execution policy error.
Solution:
Open PowerShell as Administrator and run:
Set-ExecutionPolicy RemoteSigned
Then type:
Y
This usually resolves the issue. If you're using a company-managed laptop, check with your IT team before changing execution policies.
4. Browser download failed
Sometimes antivirus software or a firewall blocks browser downloads.
Solution:
Run:
npx playwright install
after your internet connection is stable.
Tips for Beginners
- Learn one concept at a time.
- Don't worry if you get installation errors—they're common and usually easy to fix.
- Practice every day, even if it's just 30–60 minutes.
- Read the error messages carefully instead of guessing.
- Experiment with the sample project before creating your own framework.
Conclusion
Installing Playwright with TypeScript is easier than it first appears. Once Node.js, npm, and VS Code are set up correctly, the rest of the process takes only a few minutes.
If you encounter installation problems, don't be discouraged. Almost every beginner faces similar issues, and solving them is part of the learning process.
In the next article, we'll explore the Playwright Project Structure and understand the purpose of every file and folder created during installation.
Frequently Asked Questions
Do I need JavaScript before learning Playwright?
Basic JavaScript knowledge is helpful, but you can learn it alongside Playwright.
Which terminal is best for Playwright?
Command Prompt, PowerShell, and the VS Code integrated terminal all work. The VS Code terminal is convenient because you can code and run commands in one place.
Is Node.js mandatory?
Yes. Playwright depends on Node.js for JavaScript and TypeScript projects.
Why is npm not working?
This usually happens when Node.js isn't installed correctly, the terminal hasn't been restarted, or the PATH environment variable hasn't updated.
- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
Comments
Post a Comment
आपल्या सुचनांचे स्वागत आहे.
भेट दिल्या बद्दल धन्यवाद. 🙏