Key takeaways
- You can write a real automated UI test in an afternoon with Playwright, a free browser automation tool, and Node.js. You need no prior programming, just patience to follow the steps.
- A good test has three parts: arrange (go to the page), act (do something), assert (check the result). Without an assertion, it isn't a test.
- Save your work with Git and push it to GitHub. A small, clean repository of tests is one of the strongest things a beginner can show an employer.
Before you start
You've seen what manual and automated testing are good for, and why most automated tests should sit below the UI in the test pyramid. Still, a browser test is the most satisfying first step: you can see it work.
You'll need:
- Node.js (the LTS version) from nodejs.org;
- Visual Studio Code, a free code editor;
- Git, from git-scm.com, and a free GitHub account.
We'll test Sauce Demo (https://www.saucedemo.com), a public shop built for practising test automation. It provides test users such as standard_user and locked_out_user, with the password secret_sauce.
Step 1: create the project
Open a terminal (in VS Code: Terminal → New Terminal), and run:
mkdir my-first-tests
cd my-first-tests
npm init playwright@latest
Accept the defaults (TypeScript, a tests folder, install browsers). Playwright creates a project with an example test and a configuration file. Run the example to check everything works:
npx playwright test
Step 2: write a login test
Create tests/login.spec.ts:
import { test, expect } from "@playwright/test";
test("a standard user can log in and sees the products", async ({ page }) => {
// Arrange: open the login page
await page.goto("https://www.saucedemo.com/");
// Act: log in
await page.getByPlaceholder("Username").fill("standard_user");
await page.getByPlaceholder("Password").fill("secret_sauce");
await page.getByRole("button", { name: "Login" }).click();
// Assert: we reached the products page
await expect(page).toHaveURL(/inventory/);
await expect(page.getByText("Products")).toBeVisible();
});
Run only this file, with the browser visible:
npx playwright test tests/login.spec.ts --headed
You'll see a browser open, type the username and password, and log in. The terminal reports 1 passed.
Step 3: add a negative test
Good testers don't only test the happy path. Add a second test to the same file:
test("a locked-out user sees an error", async ({ page }) => {
await page.goto("https://www.saucedemo.com/");
await page.getByPlaceholder("Username").fill("locked_out_user");
await page.getByPlaceholder("Password").fill("secret_sauce");
await page.getByRole("button", { name: "Login" }).click();
await expect(page.getByText("Sorry, this user has been locked out")).toBeVisible();
await expect(page).not.toHaveURL(/inventory/);
});
Step 4: make it fail on purpose
Change "Products" to "Produkts" and run again. The test fails, and Playwright tells you what it expected and what it found.
Open the report:
npx playwright show-report
You'll see each test, each step, and for failures, the error and a screenshot. Change it back afterwards.
Step 5: explore with UI mode
npx playwright test --ui
UI mode lets you run tests one by one, step through them and see the page at each moment. There's also a codegen tool, npx playwright codegen https://www.saucedemo.com, that records your clicks as code. It's great for learning locators, but always clean up and add assertions to what it generates.
Step 6: save it with Git and GitHub
Git records versions of your code. GitHub hosts it online, where others can see it.
git init
git add .
git commit -m "Add login tests for Sauce Demo"
Then create an empty repository on GitHub and follow its instructions to connect and push:
git remote add origin https://github.com/<your-username>/my-first-tests.git
git branch -M main
git push -u origin main
Playwright's setup already created a .gitignore, so large folders like node_modules and test reports aren't uploaded.
Add a short README.md explaining what the project tests and how to run it. Employers read READMEs.
What to add next
- More tests: add a product to the cart, check the cart count, complete a checkout, and log out.
- Readable structure: move repeated login steps into a helper or a
beforeEach. - Run in CI: GitHub Actions can run your tests on every push. Playwright's setup can create the workflow file for you.
- API tests: combine with your Postman collection, or try Playwright's API testing.
When you're ready for more, read UI testing without click robots for how to keep UI tests stable as a suite grows.
A junior tester's first automated test logged in to an app and clicked through to the orders page. It passed every day for a month.
Then a bug broke the orders page: it showed an empty list for everyone. The test still passed. Looking closer, the team found the test had no assertion at all. It clicked, and if nothing crashed, it passed.
The tester added three checks: the URL, the page heading, and that at least one order row was visible for the test user. The next run failed straight away, as it should have.
Lesson: a test is only as good as its assertions. Arrange, act, assert, and watch it fail once.
Do
Use locators users can see: labels, placeholders, roles and visible text, such as getByRole("button", { name: "Login" }). They survive design changes and also nudge the app towards accessibility.
Don't
Copy long CSS paths like div > div:nth-child(3) > form > button. They break the moment a designer moves a box.
Check yourself
Your new test passes. A colleague asks: 'How do you know it actually checks anything?' What do you do?
Show answer
Make it fail on purpose: break the expected value (wrong text, wrong URL) or use data that should fail, and confirm the test goes red with a clear message. Then check it has assertions about the outcome, not just steps. A test that has never failed hasn't proven it can detect a problem.
