Scaffold Playwright Tests
I started with Selenium and later with Puppeteer but my favorite of all now is Playwright. I’m assuming we are creating a folder in home directory ~/
To scaffold a Playwright project, run
cd
mkdir playwright-api-tests
cd playwright-api-tests
npm init playwright@latestIf you do not have npm in your macOS, run
brew install nodeI’m assuming you have homebrew installed, if not get it from brew.sh . And I’ve chosen these responses during the scaffold.
I am using Visual Studio Code to edit my tests.
I prefer to run the tests with UI
npx playwright test --uiAfter clicking the triangle play button, tests will begin and shows its results. If you needed an auth token prior to all your test. You can configure a global-setup.ts that will run before all your tests.
Get Kevin FOO’s stories in your inbox
Join Medium for free to get updates from this writer.
In playwright-api-tests folder, create a file name playwright.config.ts
In playwright-api-tests folder, create a file name global-setup.ts
I have started a local web server listening at 8080.
python3 -m http.server 8080Although it doesn’t require the JWT token. I am going to put a breakpoint to show that localhost.ts in fact had obtained the JWT token for its tests.
Create `localhost.spec.ts` in `playwright-api-tests/tests` folder
JWT token obtained prior to the test.









