Playwright + JavaScript + Cucumber BDD
Handbook (Starter Edition)
This PDF is the first volume of a complete handbook. It introduces the core topics needed for
Playwright automation. A full 300+ page handbook cannot be generated accurately in a single
response, so this serves as a structured foundation.
1. Introduction
Playwright is Microsoft's end-to-end automation framework supporting Chromium, Firefox and
WebKit. It offers auto-waiting, parallel execution, API testing, tracing, screenshots and excellent
reliability.
2. JavaScript Essentials
Understand variables, functions, objects, arrays, async/await, promises and modules before
starting automation.
3. Playwright Project Structure
Recommended folders: pages/, tests/, fixtures/, utils/, data/, reports/, screenshots/, traces/, videos/.
4. Locators
Use getByRole(), getByTestId(), getByLabel(), getByPlaceholder(), getByText(), locator(), CSS
selectors and XPath. Prefer semantic locators over XPath whenever possible.
5. Locator Methods
Common methods: click, fill, press, type, hover, check, uncheck, selectOption, dragTo, clear, focus,
blur, first, last, nth, filter, count, inputValue, textContent, innerText, innerHTML, getAttribute.
6. Assertions
Use expect().toBeVisible(), toHaveText(), toHaveValue(), toHaveURL(), toHaveTitle(),
toHaveCount(), toBeChecked(), toHaveClass(), toHaveAttribute().
7. Fixtures
Fixtures provide reusable setup and teardown logic. Create browser, page, authenticated user and
API fixtures.
8. Hooks
Playwright: beforeAll, beforeEach, afterEach, afterAll. Cucumber: Before, After, BeforeAll, AfterAll,
BeforeStep, AfterStep.
9. Frames
Interact with iframes using frameLocator(). Handle nested frames by chaining frame locators.
10. Multiple Tabs & Windows
Capture new tabs using [Link]('page') and switch using the returned page object.
11. Alerts & Popups
Handle dialogs with [Link]('dialog') and use accept() or dismiss().
12. File Upload & Download
Upload with setInputFiles(). Capture downloads using waitForEvent('download').
13. Network
Mock and inspect requests using route(), continue(), fulfill() and abort().
14. API Testing
Use Playwright's request context for GET, POST, PUT, PATCH and DELETE requests.
15. Page Object Model
Separate locators and business actions into page classes to improve maintainability.
16. BDD Cucumber
Feature files describe behaviour using Gherkin. Step definitions connect Gherkin steps to
Playwright code. Use Scenario Outline and Examples for data-driven scenarios.
17. Reporting
Generate HTML, JSON, JUnit or Allure reports. Capture screenshots and traces on failure.
18. Best Practices
Avoid hard waits, keep tests independent, use fixtures, prefer semantic locators, reuse
authentication state and keep assertions meaningful.
19. Interview Preparation
Know BrowserContext, auto-waiting, locator strategy, fixtures, hooks, POM, network mocking, API
testing and BDD concepts.
Roadmap
• Week 1: JavaScript fundamentals
• Week 2: Locators and assertions
• Week 3: Page methods and waits
• Week 4: Fixtures and hooks
• Week 5: POM and data-driven testing
• Week 6: API and network mocking
• Week 7: Cucumber BDD
• Week 8: CI/CD and interview practice