In this session…
What is a test in Pytest
Run and verify
Write a Pytest function line by line
--
After learning take this QUIZ and let me know your score in comments
https://forms.gle/Vba2s1Z52WmRXLmk9
GitHub Repo - https://github.com/Raghav-Pal/Playwri...
What is a test in Pytest
A test is just a function whose name starts with test_
Pytest automatically finds and runs these functions
--
Write a pytest function line by line
Step 1 - In your project create a folder named: tests
Step 2 - Inside tests folder create a file test_google.py
Step 3 - Start writing a simple test line by line
Step 4 - Add import statements
import re
from playwright.sync_api import expect
Step 5 - Write the test function
def test_google_search(page):
Step 6 - Navigate to Google (and skip the "Before you proceed" screen)
page.goto("https://www.google.com/ncr")
Step 7 - Handle the “Accept All” popup (optional)
try:
page.get_by_role("button", name="Accept all").click(timeout=3000)
except:
print("No popup")
Step 8 - Type in the Search Box
page.get_by_role("combobox", name="Search").fill("Playwright Python")
Step 9 - Press Enter to search
page.keyboard.press("Enter")
Step 10 - Verify the page title contains the word "Playwright"
expect(page).to_have_title(re.compile("Playwright", re.IGNORECASE))
Step 11 - Run and verify pytest tests/test_google.py
Select browser
--browser=chromium (includes Chrome/Edge)
--browser=firefox
--browser=webkit (Safari engine)
Headed or Headless Mode
--headed
--headless
Capture Screenshots
--screenshot=on off (default)
on
only-on-failure
Record Video
--video=on off (default)
Retain-on-failure
On-first-retry
Can also generate html file after installing pytest-html and add option --html=report.html
pip install pytest-html
Check all options pytest --help
--
▬▬▬▬▬▬▬
Share with all who may need this
If my work has helped you, consider helping any animal near you, in any way you can
Never Stop Learning
Raghav Pal
▬▬▬▬ USEFUL LINKS ▬▬▬▬
✅ ALL TUTORIALS - https://AutomationStepByStep.com/
🙌 Connect with Raghav:
Ask Raghav: https://bit.ly/2CoJGWf
GitHub: https://github.com/Raghav-Pal
Udemy: https://www.udemy.com/user/raghav-pal-3/
Shorts Eng - https://bit.ly/3H9bifV
Shorts Hindi - https://bit.ly/3XY7XqN
➡️ Subscribe for more videos: / @raghavpal
—
Auf dieser Seite können Sie das Online-Video Playwright Python 3 | How to create First Pytest mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Automation Step by Step 12 June 2025 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 44,231 Mal angesehen und es wurde von 445 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!