Playwright API Testing Demo for Beginners

Automation Step by Step October 5, 2023
Video Thumbnail
Automation Step by Step Logo

Automation Step by Step

@raghavpal

About

Simple Basic Beginners Step-by-Step tutorials ❤️ I create videos on Automation, Testing, DevOps, CI and related tools, technologies and platform Raghav is a teacher and founder of AutomationStepByStep.com He was an Automation Architect and has led multiple teams of Automation and DevOps Engineers. For over a decade, Raghav witnessed, worked, and delivered multiple Automation Testing Projects and worked with some awesome people in this industry ► https://automationstepbystep.com/ Some topics covered: - Jenkins - JMeter - Selenium - Appium - Cypress - Playwright - Katalon Studio - API Testing - Postman - Docker - Kubernetes - Other DevOps topics Words from Raghav We often need someone to hold our hand and help us take the first few steps before we learn to walk and run. I am on a mission to spread education and make it available to anyone willing to learn Never Stop Learning Raghav All education here is FREE FOR ALL, FOREVER Share with as many people as you can in your lifetime

Video Description

00:00 - Setting up API testing project with Playwright 02:41 - Setting up playwright in VS code using npm init playwright 08:04 - Setting up project and running tests in Playwright API 11:05 - Setting up project for API testing using Playwright 16:55 - Demonstrating API testing using Playwright methods 19:31 - Checking response content and handling errors 24:36 - Changing method from get to post 27:07 - Demonstration of API Post and Put Requests 32:19 - Using the delete API request in Playwright All Free Tutorials 🟢 https://AutomationStepByStep.com/ Project Setup Create a API Test Step-by-Step How to run a GET API Request How to run a POST API Request How to run a PUT API Request How to run a DELETE API Request How to validate API Response Check response, logs, errors in UI Mode Check HTML Report *API Testing with Playwright - Project Setup* Step 1 - Create a new folder for API Testing Project Step 2 - Open the folder in VS Code Step 3 - Open terminal on the location of the folder and run command npm init playwright@latest Step 4 - Check if demo tests are running fine using commands npx playwright test npx playwright test --ui npx playwright show-report Step 5 - Create a new file for API Tests (api-tests.spec.js) *How to run a GET API Request * Step 1 - Add imports import { test, expect } from '@playwright/test'; Step 2 - Create a test using request context test.only('Demo API Test', async({request}) => { }) Step 3 - Send a GET request & store response in a variable const response = await request.get('https://reqres.in/api/users/2') Step 4 - Verify the status code of the response is 200 expect(response.status()).toBe(200); Step 5 - Check response contains some text const text = await response.text(); expect(text).toContain('Janet'); Step 6 - Write response on the console console.log(await response.json()); Step 7 - Run and check results *How to run a POST API Request* Step 1 - Add imports import { test, expect } from '@playwright/test'; Step 2 - Create a test using request context test.only('Demo API POST request’, async({request}) => {...}) Step 3 - Send a POST request along with request body & store response in a variable const response = await request.post("https://reqres.in/api/users", { data: { "name": "Raghav", "job": "teacher" } }) Step 4 - Verify response status code is 201 expect(response.status()).toBe(201); Step 5 - Check response contains some text const text = await response.text(); expect(text).toContain(Raghav); Step 6 - Write response on the console console.log(await response.json()); Step 7 - Run and check results *How to run a PUT API Request* test('Demo API PUT Request', async ({ request }) => { const response = await request.put("https://reqres.in/api/users/2", { data: { "name": "Raghav", "job": "teacher" } }) expect(response.status()).toBe(200); const text = await response.text(); expect(text).toContain('Raghav'); console.log(await response.json()); }) *How to run a DELETE API Request* test('Demo API DELETE Request', async ({ request }) => { const response = await request.delete("https://reqres.in/api/users/2") expect(response.status()).toBe(204); }) References https://playwright.dev/docs/api-testing#writing-api-test https://playwright.dev/docs/api/class-apirequestcontext https://playwright.dev/docs/api/class-response#methods https://playwright.dev/docs/api/class-apiresponseassertions https://reqres.in/ What is Package.json - https://youtu.be/04pqkGnAAkc?si=s9zi01ZYfJazP9zV ▬▬▬▬▬▬▬ Every Like & Subscription gives me great motivation to keep working for you You can support my mission for education by sharing this knowledge and helping as many people as you can If my work has helped you, consider helping any animal near you, in any way you can Never Stop Learning Raghav Pal ▬▬▬▬ USEFUL LINKS ▬▬▬▬ Ask Raghav - https://bit.ly/2CoJGWf Shorts Eng - https://bit.ly/3H9bifV Shorts Hindi - https://bit.ly/3XY7XqN GitHub Repositories - https://github.com/Raghav-Pal Udemy - https://automationstepbystep.com/udemy-discounts/ Stories - https://automationstepbystep.com/stories/ —

You May Also Like

iPhone 13 Upgrade Essentials

AI-recommended products based on this video

Loading...
for Magsafe Car Mount【20 Strong Magnets 】Magnetic Phone Holder for Car Phone Holder Mount Dash【360°】Cell Phone Mount for Car Accessories,Car Mount for iPhone 16 Pro Max 15 14 13 12 Plus MagSafe Cases

for Magsafe Car Mount【20 Strong Magnets 】Magnetic Phone Holder for Car Phone Holder Mount Dash【360°】Cell Phone Mount for Car Accessories,Car Mount for iPhone 16 Pro Max 15 14 13 12 Plus MagSafe Cases

(11,563)
$16.98
FREE delivery Tue, Jun 17 on your first order
3K+ bought in past month
Loading...
Magnetic Wireless Charger for iPhone - 3 in 1 Mag-Safe Charging Station for Multiple Devices Apple - Charger Stand Dock for Apple Watch iPhone 16 15 14 13 12 Pro Max Plus Airpods

Magnetic Wireless Charger for iPhone - 3 in 1 Mag-Safe Charging Station for Multiple Devices Apple - Charger Stand Dock for Apple Watch iPhone 16 15 14 13 12 Pro Max Plus Airpods

(750)
$59.99
PrimeFREE delivery Sat, Jun 14
Loading...
4-in-1 Wireless Magnetic Power Bank 10800mAh Portable Charger with iWatch Charger, QC4.0+20W PD Fast Charging USB C Battery Pack for Magsafe, iPhone 16/15/14/13/12 Series, Apple Watch etc. (White)

4-in-1 Wireless Magnetic Power Bank 10800mAh Portable Charger with iWatch Charger, QC4.0+20W PD Fast Charging USB C Battery Pack for Magsafe, iPhone 16/15/14/13/12 Series, Apple Watch etc. (White)

(581)
$42.95
PrimeFREE delivery Sat, Jun 14
Loading...
eazpower for Magsafe Power Bank 10000mAh, Magnetic Battery Pack Wireless, 20W PD Fast Charging, Compact Portable Charger with Built-in Cables and Stand for iPhone 16/15/14/13/12/ Apple Watch/Airpods

eazpower for Magsafe Power Bank 10000mAh, Magnetic Battery Pack Wireless, 20W PD Fast Charging, Compact Portable Charger with Built-in Cables and Stand for iPhone 16/15/14/13/12/ Apple Watch/Airpods

(330)
$39.99
PrimeFREE delivery Sat, Jun 14
200+ bought in past month
Loading...
FNTCASE for iPhone 13 Phone Case: iPhone 14 Phone Clear Case Magnetic Military Grade Drop Protection Anti Yellowing Cell Phone Cover - Rugged Durable Shockproof Protective Bumper - 6.1 Inch (Clear A) Global Recycled Standard

FNTCASE for iPhone 13 Phone Case: iPhone 14 Phone Clear Case Magnetic Military Grade Drop Protection Anti Yellowing Cell Phone Cover - Rugged Durable Shockproof Protective Bumper - 6.1 Inch (Clear A) Global Recycled Standard

(3,619)
$7.19
FREE delivery Sat, Jun 14 on your first order
100+ bought in past month
Loading...
JETech Case for iPhone 13 Pro 6.1-Inch, Non-Yellowing Shockproof Phone Bumper Cover, Anti-Scratch Clear Back (Clear)

JETech Case for iPhone 13 Pro 6.1-Inch, Non-Yellowing Shockproof Phone Bumper Cover, Anti-Scratch Clear Back (Clear)

(15,570)
$11.99
FREE delivery Sat, Jun 14 on your first order
200+ bought in past month
Loading...
Spigen Case for iPhone 15, iPhone 14, and iPhone 13, Ultra Hybrid MagFit Designed for Apple iPhone 15/14/13 - Crystal Clear

Spigen Case for iPhone 15, iPhone 14, and iPhone 13, Ultra Hybrid MagFit Designed for Apple iPhone 15/14/13 - Crystal Clear

(1,204)
$20.99
FREE delivery Sat, Sep 20 on your first order
100+ bought in past month
Loading...
OHLPRO Tablet Holder for Car, iPad Holder for Car Air Vent Mount, Universal Dashboard Windshield 2-in-1 Cradle TPU Suction Sticky Gel for iPad/iPad mini Samsung Galaxy Size 6"- 10.5" iPad Car Holder

OHLPRO Tablet Holder for Car, iPad Holder for Car Air Vent Mount, Universal Dashboard Windshield 2-in-1 Cradle TPU Suction Sticky Gel for iPad/iPad mini Samsung Galaxy Size 6"- 10.5" iPad Car Holder

(1,961)
$22.99$15.09
FREE delivery Tue, Jun 17 on your first order
50+ bought in past month
Loading...
Magnetic Car Mount Air Vent Cell Phone Holder, Universal Vehicle Dash Dashboard Ac Airvent Cellphone Magic Stand with Clip Hook, for iPhone 16 15 Samsung Lenovo Google etc

Magnetic Car Mount Air Vent Cell Phone Holder, Universal Vehicle Dash Dashboard Ac Airvent Cellphone Magic Stand with Clip Hook, for iPhone 16 15 Samsung Lenovo Google etc

(128)
$21.99
FREE delivery Tue, Jun 17 on your first order
Loading...
AINOPE Phone Holder for Car Vent 2025 Gravity Air Vent Car Phone Holder Mount for iPhone 17 Pro Max Vent Clip Hand Free Cell Phone Car Mount for iPhone Air 17 16 Pro Max Samsung S25 Car Accesorries

AINOPE Phone Holder for Car Vent 2025 Gravity Air Vent Car Phone Holder Mount for iPhone 17 Pro Max Vent Clip Hand Free Cell Phone Car Mount for iPhone Air 17 16 Pro Max Samsung S25 Car Accesorries

(30,765)
$18.98
FREE delivery Sat, Jan 3 on your first order
2K+ bought in past month
Loading...
Miracase Car Phone Mount, [2025 Upgraded Strong Military Grade Suction Cup] Long Arm Phone Holder for Car Dashboard Windshield Vent, Hands Free Cell Phone Holder Compatible with All Mobile Phones Global Recycled Standard

Miracase Car Phone Mount, [2025 Upgraded Strong Military Grade Suction Cup] Long Arm Phone Holder for Car Dashboard Windshield Vent, Hands Free Cell Phone Holder Compatible with All Mobile Phones Global Recycled Standard

(63,968)
$24.99
FREE delivery Sat, Jan 3 on your first order
4K+ bought in past month
Loading...
Snap Grip Mini Mop, Zero Touch Mini Mop, 360° Disposable Dust Mop with 4 Reusable Cloths, No Wash Lazy Mops Wet and Dry, 100cm Long Handle Mopping Sweeper Stick for Multi Cleaning (1pcs)

Snap Grip Mini Mop, Zero Touch Mini Mop, 360° Disposable Dust Mop with 4 Reusable Cloths, No Wash Lazy Mops Wet and Dry, 100cm Long Handle Mopping Sweeper Stick for Multi Cleaning (1pcs)

(0)
$26.29
$6.99 delivery Jan 13 - 23
Loading...
Wireless Earbuds, Bluetooth 5.3 Headphones HiFi Stereo, Mini in-Ear Bluetooth Earbuds, Wireless Earphones with 4 ENC Noise Cancelling Mic, IP7 Waterproof, LED Display, Touch Control Ear Buds, White

Wireless Earbuds, Bluetooth 5.3 Headphones HiFi Stereo, Mini in-Ear Bluetooth Earbuds, Wireless Earphones with 4 ENC Noise Cancelling Mic, IP7 Waterproof, LED Display, Touch Control Ear Buds, White

(10,124)
$23.99
FREE delivery Sat, Jun 14 on your first order
1K+ bought in past month
Loading...
DCNETWORK iPhone 4s Cable USB Sync and Charging Cable for iPhone 4 4s 3G 3GS iPad 1 2 3 iPod Touch Nano 30 Pin Charger Cord Dock Adapter Data 3.3 Feet (White)

DCNETWORK iPhone 4s Cable USB Sync and Charging Cable for iPhone 4 4s 3G 3GS iPad 1 2 3 iPod Touch Nano 30 Pin Charger Cord Dock Adapter Data 3.3 Feet (White)

(943)
$5.99
FREE delivery Sat, Jun 14 on your first order
500+ bought in past month
Loading...
Wireless Earbuds, Bluetooth 5.3 Headphones HiFi Stereo, Mini in-Ear Bluetooth Earbuds, Wireless Earphones with 4 ENC Noise Cancelling Mic, IP7 Waterproof, LED Display, Touch Control Ear Buds,Rose Gold

Wireless Earbuds, Bluetooth 5.3 Headphones HiFi Stereo, Mini in-Ear Bluetooth Earbuds, Wireless Earphones with 4 ENC Noise Cancelling Mic, IP7 Waterproof, LED Display, Touch Control Ear Buds,Rose Gold

(10,124)
$23.99
FREE delivery Sat, Jun 14 on your first order
400+ bought in past month