
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)
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
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.