Playwright Interview Questions
Q1. What is Playwright and why is it used?
Sample Answer:
Playwright is an open-source test automation framework developed by Microsoft. It is used to automate web applications and supports testing across multiple browsers like Chromium, Firefox, and WebKit. It is mainly used for UI and API testing.
Q2. Which browsers are supported by Playwright?
Sample Answer:
Playwright supports Chromium, Firefox, and WebKit. These cover most modern browsers like Chrome, Edge, Safari, and Firefox.
Q3. How is Playwright different from Selenium?
Sample Answer:
Playwright does not use WebDriver, so it is faster and more reliable. It has built-in auto-waiting, better handling of modern web apps, and supports multiple browsers in a single setup.
Q4. What is auto-waiting in Playwright?
Sample Answer:
Auto-waiting means Playwright automatically waits for elements to be visible, enabled, and stable before performing actions, which reduces the need for explicit waits.
Q5. How do you locate elements in Playwright?
Sample Answer:
Elements can be located using methods like getByRole(), getByText(), getByLabel(), and locator(). Playwright encourages using user-facing locators.
Q6. How do you click a button and type text?
Sample Answer:
To click a button:await page.click('selector')
To type text:await page.fill('selector', 'text')
Q7. What is the Playwright test runner?
Sample Answer:
The Playwright test runner is a built-in framework that helps organize, execute, and report tests. It supports parallel execution, retries, and reporting.
Q8. What is beforeEach() used for?
Sample Answer:beforeEach() runs before every test case. It is commonly used for setup tasks like launching a page or logging into the application.
Q9. How do you run Playwright tests?
Sample Answer:
Tests can be run using the command:npx playwright test
Q10. How do you validate results in Playwright?
Sample Answer:
Validation is done using assertions from the expect() library, such as checking page title, text, or element visibility.
Q11. How do you handle pop-up alerts?
Sample Answer:
Playwright handles alerts using the page.on('dialog') event, where we can accept or dismiss the alert.
Q12. Can Playwright capture screenshots or videos?
Sample Answer:
Yes, Playwright can capture screenshots, record videos, and collect traces for debugging.
Q13. What is Trace Viewer?
Sample Answer:
Trace Viewer is a Playwright tool that allows us to see test execution step-by-step, including actions, screenshots, and network activity.
Q14. Can Playwright run tests in parallel?
Sample Answer:
Yes, Playwright supports parallel test execution by default, which helps reduce test execution time.
Q15. Is Playwright suitable for beginners? Why?
Sample Answer:
Yes, Playwright is beginner-friendly because it has auto-waiting, simple syntax, good documentation, and reliable execution.