-
-
Notifications
You must be signed in to change notification settings - Fork 2
Intro to Playwright and TypeScript
Carlos Kidman edited this page May 24, 2024
·
1 revision
In this first class workshop, we focused on doing our "one-time" setup of this project and writing some initial tests with Playwright.
- Free GitHub Account
- Git on your machine
- VS Code installed (recommended to follow along, but you can use any IDE)
- Create a new GitHub Repo
- Clone it to your machine
- Install bun (visit https://bun.sh)
- Open repo in VS Code
Within the Terminal, run this command to initialize this as a TypeScript project:
$ bun init💡 Multiple files, including
node_modules, are added
- Playwright Test for VSCode
- ESLint
- Gherkin (cucumber logo)
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.tsfile from our example repo (copy and paste) - Create a
/testsfolder at the project root
- 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 browsermode - Show
Pick locatortool while browser is open - See the Test Report folders and add
playwright-reportto.gitignore - Show the playwright test report
$ bun run playwright show-report- Run the test in
Show trace viewermode - Describe Trace Viewer and how it’s valuable
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/featuresfolder under/tests - Use Gherkin
.featurefiles as our "standard format" for this
login.featureFeature: Login
- Have the class try and organize their Features and Scenarios into Gherkin files
- 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
- 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
- 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!