How to record tests using Playwright: Test Generator

woman sitting while operating macbook pro
Reading Time: 3 minutes

What is the Playwright framework:

Built by the Microsoft team, It is a framework for end-to-end testing and automation, slowly gaining popularity.

Moreover, It is an open-source test automation library and It’s easy to set up, feature-packed, and one of the fastest, most reliable frameworks.

Test Generator:

Playwright comes with the ability to generate tests out of the box and hence is a great way to quickly get started with testing.

It will open two windows, a browser window where you interact with the website you wish to test and The Playwright Inspector window where you can record your tests, copy the tests, clear your tests as well as change the language of your tests.

Steps for record test in Playwright:

  1. Firstly, we will enter the command ” npx playwright codegen ” in the terminal. we can also use the command with the URL of the website like ” npx playwright codegen ” further after entering the above command you will get a playwright inspector (recording window) like this and also open a given website
playwright inspector

2. After that we will test the website In the above website I am testing login and logout functionality and as you start you don’t have to write the code It will automatically write in the playwright inspector .

In this case we will click the stop or pause button and copy the code and also as you start testing then you will get locator as you click on the element.

In addition, there are features like you can stop the recording, and copy the code.

3. In the next step we copy the code from the playwright inspector and paste it into the visual studio in the javascript file name Test.spec.js to run the test we will give the command npx playwright test tests/Test.spec.js in the terminal furthermore we will see our test will run successfully.

4. In addition, to see the reports give the command npx playwright show-report in the terminal and you will see the reports in the browser in HTML format.

It is very easy to record tests in a playwright you just have to follow the above steps


Written by 

I am a software Consultant-QA at knoldus Inc in test automation studio. She is familiar with the core concepts of manual testing and automated testing using Selenium and cypress. She is always eager to acquire new tech skills and learn new & advanced concepts to advance herself. She likes to watch web series and listening music.