
Discover how Playwright enables reliable end-to-end testing of web apps and APIs across browsers and OSes, as a free, multi-language, open-source tool.
https://youtu.be/cnnkb0AuIFI
node -v or node --version
npm -v or npm --version
Install using command as npm package
Step 1 - Create a new folder and open in VS Code
Step 2 - Goto Terminal and run command - npm init playwright@latest
Step 3 - Following will be added
- package.json - node project management file
- playwright.config.js - Configuration file
- tests folder - basic example test
- tests-examples folder - detailed example tests
- .gitignore - to be used during git commit and push
- playwright.yml - to be used during ci cd pipeline (github workflows)
Step 4 - Check playwright added - npm playwright -v
Step 5 - Check playwright command options - npx playwright -h
Using VS Code extension
------------
Step 1 - Create a new folder and open in VS Code
Step 2 - Goto Extensions section and install Playwright extension from Microsoft
Step 3 - Goto View - Command Palette and type playwright - select install playwright
Step 4 - Select the browsers and click ok
Step 5 - It will install the libraries and create the project folders
to run test....
npx playwright test
to get report.....
npx playwright show-report
npx playwright test --headed
2 different ways
-----
1) Without using plugin Codegen - Test Generator
2) Codegen - Test Generator
------------
Step 1 - Create a new file under test folder
Step 2 - Add module ‘playwright/test’
const { test, expect } = require('@playwright/test');
** test, expect ---> functions from @playwright/test module
Playwright Test provides a test function to declare tests and expect function to write assertions
Step 3 - Create a test block - test(title, testFunction)
test('My First Test', async ({page}) => {
await page.goto('https://google.com');
await expect(page).toHaveTitle('Google');
})
The keyword 'async' before a function makes the function return a promise
The keyword 'await' before a function makes the function wait for a promise
to run login test
--------
npx playwright test --project=chromium --headed FirstTest.spec.js
npx playwright test runs all tests on all browsers in headless mode
npx playwright test MyTest1.spec.js runs a specific test file
npx playwright test MyTest1.spec.js MyTest2.spec.js runs the files specified
npx playwright test -g "test title" runs test with the title
npx playwright test --project=chromium runs on specific browser
npx playwright test --headed runs tests in headed mode
npx playwright test --debug debug tests
npx playwright test example.spec.js --debug debug specific test file
Locating Elements in Playwright
---------------------------------
property
css
xpath
Locate single element
-----
link/button
------
await page.locator('locator').click()
await page.click('locator');
inputbox
-----
await page.locator('locator').fill('value')
await page.locator('locator').type('value')
await page.fill('locator', 'value')
await page.type('locator', 'value')
Locate multiple web elements
------------
const elements=await page.$$(locator)
Explore built-in locators in Playwright, including get by alt text, placeholder, role, text, label, title, and test ID, and learn practical usage for locating elements in automated tests.
Learn to use playwright codegen to record browser actions, generate a test script with built-in locators, and export code in JavaScript, Python, or other targets for rapid test creation.
Explore the full range of Playwright assertions using expect to validate URL, title, visibility, enabled or disabled states, text and value checks, attributes, and element counts with practical examples.
Explore hard vs soft assertions in Playwright and how expect.soft preserves test execution for titles, the page url, and element visibility.
Learn to handle checkboxes with Playwright using check, uncheck, and is checked actions, and validate states with to be true/false while managing single and multiple checkboxes with locators.
Learn how to handle dropdowns in Playwright with JavaScript, covering select tag, bootstrap and hidden dropdowns, and select options by label, value, or index with targeted assertions.
Learn to handle bootstrap dropdowns in Playwright, supporting single and multi-select options, counting items with selectors, and selecting or deselecting Angular and Java.
Learn how to handle auto suggest dropdowns in Playwright by entering a value, waiting for dynamic suggestions, enumerating options, and selecting the matching item such as Anand Vihar.
Learn to handle hidden dropdowns in Playwright by using a debugger to inspect and select options from bootstrap dropdowns, including locating and clicking the desired item.
Learn to manage multiple pages in Playwright by creating a browser, a context, and multiple pages, then switch between them and handle new pages opened in the context.
Learn how to work with frames and iframes in Playwright by switching to frames via name or URL, or using frame locator to access and interact with elements inside frames.
Learn to handle inner frames and nested iframes in Playwright using frame objects and frame locators, capture child frames, and interact with elements inside.
Explore how to handle web tables with Playwright, including counting rows and columns, selecting products via checkboxes, filtering by name, and reading data across paginated pages.
Learn how to handle date pickers in Playwright with JavaScript, including direct fill, and building robust scripts that navigate months and years using while loops, next/previous arrows, and reusable patterns.
Learn to perform mouse hover actions in Playwright with JavaScript by hovering over desktop and Mac elements using the hover method, with selectors and wait steps.
Learn to perform a double click action in Playwright to copy text from the first input to the second and validate the result with an assertion.
Learn to perform drag and drop in Playwright with JavaScript using a direct drag to method and a hover-based approach, demonstrated by Rome to Italy and Washington to United States.
Group tests in Playwright using describe blocks, then orchestrate setup and teardown with before all, before each, after each, and after all hooks, and run groups with only and skip.
learn tagging concept in playwright by labeling tests with tags such as sanity and regression, and run selective tests using grep options, including combining or excluding tags.
Explore Playwright annotations such as test.only, test.skip, test.fixme, test.fail, and test.slow, with conditional skipping, timeout control, and practical examples for robust test design.
Explore the page object model in Playwright with JavaScript by organizing page elements into separate classes for login, home, and cart. Learn to reuse components across tests to improve maintainability.
Learn how Playwright automatically retries failed tests using the retrieve feature, understand flaky tests that pass on rerun, and configure retries globally or per test.
Allure Reports for Playwright (Steps)
==============================
1) Installation of "allure-playwright" module
npm i -D @playwright/test allure-playwright
2) Installing Allure command line
For Windows: npm install -g allure-commandline --save-dev
(or)
For Mac: sudo npm install -g allure-commandline --save-dev
3) add entry in "playwright.config.js" file
reporter= ['allure-playwright',{outputFolder: 'my-allure-results'}]
4) Run the tests
npx playwright test tests/Reporters.spec.js
5) Generate Allure Report:
allure generate my-allure-results -o allure-report --clean
6) Open Allure Report:
allure open allure-report
Learn to test rest APIs in Playwright using the request fixture to perform get, post, put, and delete requests. Validate responses and status codes such as 200, 201, and 204.
Explore the foundations of web applications, client-server architecture, and the roles of HTML, CSS, and JavaScript, then compare Java and JavaScript and trace JavaScript history.
Understand the document object model and how JavaScript manipulates HTML to create dynamic pages. Access the DOM with getElementById, update content with innerHTML, and connect JavaScript files for events.
Learn how to install Visual Studio Code, set up a Live Server extension, and write JavaScript with the document and console objects, including comments and statements for dynamic web pages.
Learn to use JavaScript conditional statements, including if, if else, and switch case, to control execution, compare values, and implement decision logic with practical examples.
Master JavaScript control flow with loops and jumping statements, including while, do while, for, and break/continue, and learn to iterate arrays and objects efficiently.
Explore creating and invoking JavaScript functions with parameters and return values, and build a dynamic HTML calculator that handles events and updates the UI.
Learn to create JavaScript objects, access and modify properties with dot and bracket notation, use for-in loops, and implement object methods with this keyword.
Create and manipulate a date object in JavaScript using getDate, getMonth, getFullYear, getHours, getMinutes, and getSeconds, then build a dynamic digital clock with HTML and JavaScript.
Explore strings and numbers in JavaScript, creating string literals and number values, and applying key methods like concat, replace, substring, split, trim, parseInt, parseFloat, and toString.
Learn how JavaScript uses object oriented programming with class, object, methods, and constructors, creating multiple objects, using this to store data, and automatic constructor invocation.
Learn how the static keyword in JavaScript creates shared class-level variables and methods, how to access them via the class name, and how static members differ from non-static ones.
Learn how JavaScript prototypes enable adding properties and methods to functions and classes at a later stage, and how objects share prototype-based attributes.
Explore polymorphism in JavaScript as a core object-oriented concept with shape, square, and circle classes, where the draw method is overridden to provide multiple forms.
Learn to convert JSON data to a JavaScript object using JSON.parse, then access data fields like employees, first name, last name, and address from the resulting object.
Course Mastering Web & API Automation with Playwright
Course Description: Playwright has emerged as a powerful tool in the realm of web automation, offering a comprehensive solution for testing and interacting with web applications across various browsers. This course is designed for professionals and enthusiasts eager to leverage Playwright's capabilities for efficient and robust web automation. With a focus on practical application, participants will gain hands-on experience in creating, running, and optimizing tests using Playwright.
Course Contents:
Introduction
Overview of Playwright and its significance in web automation.
Installation
Step-by-step guide on installing and setting up Playwright for different programming languages.
How to create & Run tests in Playwright
Creating a basic test script and executing it in different browsers.
Locators - XPath, CSS, Property
In-depth exploration of various locators and their usage in Playwright.
Built-in Locators
Understanding Playwright's built-in locators for efficient element identification.
Record and Play scripts - Test Generator
Utilizing the test generator to automate script creation for accelerated workflow.
Assertions
Introduction to assertions for validating expected outcomes.
Hard vs soft assertions
Differentiating between hard and soft assertions and their suitable applications.
Handle Web Elements
Practical guidance on interacting with input boxes, radio buttons, checkboxes, and dropdowns.
Handling multi-select dropdown
Techniques for handling multi-select dropdowns in web applications.
Handling bootstrap drop-down
Strategies for dealing with Bootstrap dropdown menus.
Handling Auto-suggest dropdown
Implementing automation for auto-suggest dropdowns.
Handling hidden dropdown
Techniques to interact with hidden dropdowns in web pages.
Handling Dialogs/Alerts
Managing pop-up dialogs and alerts during automation.
Handle Multiple windows
Strategies for automating scenarios involving multiple browser windows.
Handling frames
Techniques for working with frames within web pages.
Handling inner frames
In-depth exploration of handling nested frames.
Handling web table
Strategies for interacting with and validating data in web tables.
Handling date pickers
Techniques for handling date pickers in web applications.
Handling mouse actions
Performing mouse actions such as hover, right-click, double-click, and drag-and-drop.
Keyboard actions
Automating interactions using keyboard actions.
Upload files
Strategies for automating file uploads in web applications.
Playwright hooks
Leveraging Playwright hooks for advanced automation scenarios.
Grouping tests
Organizing and executing tests in logical groups.
Capture screenshots
Implementing screenshot capture for test result documentation.
Recording videos
Recording test execution for comprehensive analysis.
Tracing tests with trace viewer
Utilizing trace viewer for in-depth test analysis.
Tagging tests
Implementing test tagging for better organization and filtering.
Annotations
Adding annotations for improved test documentation.
Page Object Model
Introduction to the Page Object Model for scalable and maintainable test automation.
Reporters
Exploring different reporting options for test results.
Allure reports
Generating and interpreting reports using Allure.
API testing with Playwright
Extending Playwright for API testing.
JavaScript Fundamentals(Bonus Lectures)
Join us in this comprehensive journey to master web automation with Playwright and stay ahead in the ever-evolving landscape of software testing.