Skip to content

rshri2004/playwrightdemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Playwright Part1

A Python-based test automation framework using Playwright and pytest.

Setup

Create Virtual Environment

python3 -m venv env
source env/bin/activate #For mac/unix users

Install Dependencies

pip install -r requirements.txt
playwright install  # Install browser binaries

Running Tests

Basic Test Execution

# Run all tests
pytest

# Run specific test file
pytest src/tests/test_gap.py

# Run specific test
pytest src/tests/test_gap.py::test_search

# Run with verbose output
pytest -v

# Run in headed mode (see browser)
pytest --headed

# Run with slow motion (1000ms delay between actions)
pytest --headed --slowmo 1000

Generate HTML Report

# Generate HTML report in reports directory
pytest --html=reports/report.html --self-contained-html

# With verbose output
pytest -v --html=reports/report.html --self-contained-html

# Run specific test with HTML report
pytest src/tests/test_gap.py::test_search -v --html=reports/report.html --self-contained-html

Screenshots on Failure

Screenshots are automatically captured when tests fail and saved to the screenshots/ directory.

Filename format: {test_name}_{timestamp}.png

Project Structure

playwright_demo/
     src/
        pages/           # Page Object Model classes
             gap_home_page.py
             bestbuy_home_page.py
        tests/           # Test files
            conftest.py  # Pytest configuration and fixtures
            test_gap.py  # Test cases
            test_bestbuy.py  # Test cases
        screenshots/         # Auto-generated screenshots on failure
    reports/            # HTML test reports
    pytest.ini          # Pytest configuration
    requirements.txt    # Python dependencies

Configuration

pytest.ini

  • Default log level: INFO
  • Verbose output enabled
  • Short tracebacks
  • Custom log format with timestamps

conftest.py

  • Browser viewport: 1920x1080
  • Default expect timeout: 10s (configurable via --expect-timeout)
  • Automatic screenshot capture on test failure
  • Browser context and page fixtures

Custom Options

# Set custom expect timeout (in milliseconds)
pytest --expect-timeout=15000

Examples

# Run all tests with HTML report
pytest -v --html=reports/report.html --self-contained-html

# Run search test in headed mode with report
pytest src/tests/test_gap.py::test_search -v --headed --html=reports/report.html --self-contained-html

# Debug mode: headed + slow motion + verbose
pytest src/tests/test_gap.py::test_search -v --headed --slowmo 1000

About

Playwright test framework demo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published