DEV Community

Liang Wang
Liang Wang

Posted on

Playwright tips

Lesson 0
Use .env file to store the constants.

Lesson 1
In .env file, USERNAME is a default value that cannot be overwritten. Use something else, like test_username.

Lesson 2
install the dotenv package from npm.
npm i dotenv

then use it

require('dotenv').config();
Enter fullscreen mode Exit fullscreen mode

Lesson 3
Project dependency is good to have, for example, log in before each test.
Follow this article

Lesson 4
Use npx playwright test in the Terminal runs the tests in headless mode.

Lesson 5
Learn the shortcuts of VS Code is really handy to have. I like the split view, show and hide the side menu, bottom menu etc, and Zen mode a lot.

Lesson 6
Add log after each test for better readability.

test.afterEach(async ({ page }, testInfo) => {
  console.log('Done with test -', testInfo.title);
  await page.close();
});
Enter fullscreen mode Exit fullscreen mode

Read more from the documentation

Top comments (0)