GroTechMinds

playwright interview question for freshers

PlayWright Interview Questions And Answers - Freshers & experienced up to 2 years

1. What is a playwright?

Ans. Playwright is an open source tool developed by Microsoft for automation testing of web applications and mobile applications. It is also used for API automation.

2. Which operating systems are supported by playwright?

Ans. The operating systems which are supported by playwright are:Windows,MacOS and Linux operating systems.

3. What are the browsers supported by the playwright?

Ans. The browsers supported by playwright are Chromium,Webkit,Firefox,Chrome etc.

4. What programming languages are supported by playwrights?

Ans. The programming languages supported by Playwright are Javascript,Typescript,Java,C#,Python.

5. Mention some playwright locators?

Ans. Locators are used to detect the elements or components present in the web page. The various locators used in Playwright are ID,Name,ClassName,CSS selector, Xpath,Text Content,TagName,AltText,Attribute,Label,Role,Title,TestID

6. Write syntax to launch URL.

Ans. await page.goto(“url link”);

7. What is the syntax to get the current page URL?

Ans. const currentUrl= await page.url();

8. What is the command for getting the title of the webpage?

Ans. const title = await page.title();

9. What is the difference between Selenium and playwright?
Playwright Selenium
Supports cross browser automation chromium,webkit Does not support cross browser automation in chromium, webkit,
Does not require webdriver installations since drivers are in built. Requires webdriver installations since drivers are not inbuilt.
Playwright supports programming languages like NodeJS, JavaScript. Selenium does not support programming languages like NodeJS, JavaScript.
Playwright supports running of test scripts through inbuilt test plugins as well as through third party tools like Mocha ,Jest ,Jasmine etc. Selenium does not support running of test scripts through inbuilt test plugins but rather it only depends on third party tools likeTestNG,Junit, Mocha ,Jest ,Jasmine etc. for running test scripts.
It does not require browser specific drivers for performing parallel testing and cross browser testing. It requires browser specific drivers for performing parallel testing and cross browser testing.
The architecture of Playwright is that it follows Web Socket protocol. The architecture of Selenium is that it follows JSON wire/HTTP protocol.
It supports API Automation and mobile application testing. It does not support API Automation and mobile application testing.For mobile application testing a third party tool like Appium is required.
It can be used for visual and screenshot comparison. It cannot be used for visual and screenshot comparison.style=#000000
10. What are the advantages of Playwright?

Ans. 1. Using Playwright, testers can perform cross browser testing in different browsers like chrome,firefox, chromium etc. which involves running test scripts in different browsers one after another.

  1. Playwright is helpful in automation testing of advanced web applications using React,NodeJs as well as in automation of more complex single page applications.
  1. Playwright helps immensely in performing System testing which is also the end to end testing, involving navigation from the home page of the application to the last page of that application as well as interaction with different components of each page.
  1. With the help of Playwright, testers can perform parallel testing using different browsers which involves running test scripts simultaneously in different browsers.
  1. Using Playwright testers can keep a record of the test cases or scripts executed.
  1. Playwright does not require the use of any wait command like explicit wait for running test scripts since it automatically performs wait actions.  
  1. Testers can perform image based testing like screenshot comparison,visual comparison through playwright.  
  1. Playwright can be used in performing automated regression testing by integrating with CI/CD pipeline to make sure that any code changes do not affect the existing functionality of the application.
  1. Using Playwright automation scripts can be run in different operating systems like windows, Linux and MacOS.
  1. Testers can also perform mobile testing effectively using Playwright
11. What are the disadvantages of Playwright?

Ans. 1. Playwright is not compatible with Safari Browser.

  1. Since it is relatively new to the market, sometimes effective test execution may not happen.
  1. Although Playwright supports mobile application testing,it still does not support automation testing of native mobile applications.
  1. Playwright is difficult to learn for those people who have zero knowledge of coding.
  1. Not suitable for performing unit testing.
  1. Playwright does not support cloud based testing.
  1. Whenever testers do not perform cross browser testing, use of playwright becomes unnecessary.  
  1. For very small projects with limited budget usage of playwright is not justifiable.
12. What are the different types of testing playwright support?

Ans. Playwright supports API Testing,Parallel Testing,CrossBrowser Testing, System Testing, Component Testing, Functional Testing.

13. What is the syntax to type values in a textfield?

Ans. await page.locator(‘input[type=”text”]’).fill(‘Hello, world’);

         await page.locator(‘input[type=”text”]’).type(‘Hello, world’);

14. What is the syntax to clear values in the text field?

Ans. await page.locator(‘selectorname’).clear();

15. What is the syntax for getting the text values?

Ans. await page.locator(‘selectorname’).innerText();

16. What is the method used to check if given element is displayed or not?Write the syntax.

Ans. Using isVisible() method we can check if given element is displayed or not. Syntax: await page.locator(‘selectorname’).isVisible();

17. What is the method to check if a given element is selected or not? Write the syntax.

Ans. Using isChecked() method we can check if given element is selected or not. Syntax: await page.locator(‘selectorname’).isChecked();

18. Write syntaxes to check if button is enabled and disabled respectively?

Ans. Syntax to check whether button is enabled:

        await page.locator(‘your-selector’).isEnabled();

        Syntax to check whether button is disabled:

        await page.locator(‘your-selector’).isDisabled();

19. Mention the different assertions used in playwright.

Ans. The different assertions used in playwright are 

  •              expect(value).toEqual(expected) 
  •               expect(value).toBeTruthy()
  •                expect(value).toBeFalsy()
  •                expect(locator).toContainText(expected_text): 
  •               expect(locator).toHaveClass(expected_class)
  •               expect(value).toBe(expected)
20. What is soft assert in Playwright and mention the syntax.

Ans. Using Assertion if the test fails the test execution stops.By using soft assert text execution continues even if the test fails and the test status will be marked as failed at the end of execution.

21. Mention different navigation commands.

Ans. page.goto(‘https://example.com’);

 

await page.reload();  // Refresh your current page

 

await page.goBack(); // Takes one page backward based on browser’s history

 

await page.goForward(); // Takes one page forward based on browser’s history

22. Mention syntax for right click.

Ans. await page.locator(‘your-selector’).contextMenu();

          await page.locator(‘your-selector’).click({ button: ‘right’ });

23. Mention syntax for double click.

Ans. await page.locator(‘your-selector’).dblclick();

24. What are the types of reports supported by Playwright?

Ans. The various reports supported by Playwright are 

  • Dot reporter
  • Line reporter
  • HTML reporter
  • JSON reporter
  • JUnit reporter
  • Custom reporter

Also read:

Upskill Yourself
Consult Us