Setup Playwright Automation Project

In this article, we will discuss how to set up playwright project.

Pre-requisite

  • Node JS need to be installed.

Steps

Open the command prompt

Type the command,

npm init playwright@latest playwright-course

It will ask you whether to install the packages, provide the option yes in the terminal

While installing the playwright, it will also ask which language are you going to use for playwright tests, Javascript/typescript.

Note
The default language is Typescript

  1. Which folder you are going to keep the tests? yes/no
  2. Do you want to add a github action workflow to your project? yes/no
  3. Do you want to install the playwright browsers? yes/no

Select the appropriate option and hit enter.

All the dependencies will get installed inside a folder name (playwright-course)

Inside the playwrighttest folder, you will have the package.json file created with the dependency installed.

Screenshot of folder structure created,

playwright.config.ts

This file is the most important file which contains the configuration for the test like baseurl, connection timeout, desired capability, etc. We call it as a runner file. 

Test-Examples

Default folder which gets downloaded with examples of test files inside.

Tests Folder

Contains all the test files.

Playwright-report folder

Contains HTML report files for the test which we run. This folder will only be created after running the tests plus user should run the command

npx playwright show-report. The report will open in localhost URL in browser and at the same time the folder will also be created with the HTML files present.

Github/workflow folder

Contains a yml file that is used to run the tests using github actions if you are using Github as a code repository.

playwright will provide a default yml which you can make use of running your tests in github actions.

.gitignore file

Default file which gets automatically added while installation. It also has the contents in which folder which needs to be ignored while pushing our code to github.

node_modules

Default folder which contains the code for libraries that we are using in the node project.

Thanks, Happy Learning


Similar Articles