Intro to Playwright and TypeScript - qa-at-the-point/base GitHub Wiki
In this first class workshop, we focused on doing our "one-time" setup of this project and writing some initial tests with Playwright.
🛑 Prerequisites
- Free GitHub Account
- Git on your machine
- VS Code installed (recommended to follow along, but you can use any IDE)
💻 Setup Machine
- Create a new GitHub Repo
- Clone it to your machine
- Install bun (visit https://bun.sh)
- Open repo in VS Code
📂 Setup Workspace
Within the Terminal, run this command to initialize this as a TypeScript project:
$ bun init
💡 Multiple files, including
node_modules
, are added
🧰 VS Code Extensions
- Playwright Test for VSCode
- ESLint
- Gherkin (cucumber logo)
👀 Setup Project
Within the Terminal:
- Install playwright
$ bun add playwright
- Install playwright's types
$ bun add @playwright/test --dev
- Add
"@playwright/test"
totscong.json
> "types" list - Add the
playwright.config.ts
file from our example repo (copy and paste) - Create a
/tests
folder at the project root
🧪 Record a Test
- Use Playwright extension to Record new test
- Install drivers (opens prompt only if you need them)
- Browser opens!
- Navigate to https://saucedemo.com
- Add items to cart and complete checkout with assertions along the way
- Review the newly generated test and break it into parts
- Use the Playwright extension to run the test in
Show browser
mode - Show
Pick locator
tool while browser is open - See the Test Report folders and add
playwright-report
to.gitignore
- Show the playwright test report
$ bun run playwright show-report
- Run the test in
Show trace viewer
mode - Describe Trace Viewer and how it’s valuable
1️⃣ Activity: Define Features and Scenarios
We don’t just start at a company and start writing tests! We need to learn the context first - the industry, company, apps, personas, problems we’re solving, etc.
- Have the class break down the Sauce Labs app into Features however they want (ie notepad)
- Have the class create some test cases or scenarios for a feature
- Review some examples
- Create a new
/sauce/features
folder under/tests
- Use Gherkin
.feature
files as our "standard format" for this
login.feature
Feature: Login
- Have the class try and organize their Features and Scenarios into Gherkin files
2️⃣ Activity: Write the automated test for a Scenario
- Have the class pick a Feature and one scenario to automate
- They can use everything they’ve learned so far to automate it
- Review some examples
3️⃣ Activity: Write the automated test for another Scenario
- Have the class write automated tests for at least one more Scenario in the same Feature
- Review examples and see what’s good and what’s bad
4️⃣ Activity: Write the automated tests for another Feature
- Have the class pick another Feature and write all of its Scenarios as automated tests
- Review examples and see what’s good and what’s bad
📝 Homework: Create the Features, Scenarios, and automated tests to get 100% Test Coverage of SauceDemo
- Use the #autobots channel to share work and ask questions
- Make your repo public so others can review
- Share findings, tips, and tricks as you learn more about Playwright and Test Automation
💡 Remember: This is to learn and expand your skillset. You can copy others' work, but make sure you understand each bit, can explain it in an interview, and can eventually do this on your own!