- Introduction
- Prerequisites
- Project Structure
- Getting Started
- Test Execution
- Data-Driven Testing
- BDD Tests
- Reporting
- CI/CD Using GitHub Actions
- Contacts
This repository contains a comprehensive automation framework built with Playwright and Python, designed to automate both UI and API tests. The framework follows the Page Object Model (POM) pattern, which separates test logic from the UI structure, enhancing maintainability and reusability. Test execution is managed through pytest, with parallel test execution capabilities for faster results.
The framework includes features like detailed Allure reporting with screenshots captured at critical points, API payload attachments, and comprehensive test results. It also leverages Object-Oriented Programming principles for code organization and reusability.
Key features include:
- Hybrid architecture supporting both UI and API automation
- Optional (Just for Demo) BDD test approach using Cucumber-style Gherkin syntax with pytest-bdd
- Comprehensive logging and exception handling
- Screenshot capture for all validations and failures
- API request/response payload capture for detailed analysis
- Cross-browser testing support (Chrome, Firefox, WebKit)
Before you start, ensure you have the following installed on your machine:
- Python: Version 3.8 or later
- Pip: Python package manager
- Git: To clone the repository
- Allure: For detailed reporting (optional, but recommended)
This project follows a modular architecture designed for scalability and maintainability. Below is the high-level structure of the project:
| EcomAppAutomationFramework/
├── PageObjects/ # Page Object classes for different website pages
│ ├── loginPage.py # Handles login page interactions
│ ├── dashboardPage.py # Dashboard page interactions
│ ├── cartPage.py # Cart page interactions
│ ├── checkoutPage.py # Checkout page interactions
│ ├── orderDetailsPage.py # Order details page interactions
│ └── ordersPage.py # Orders page interactions
├── TestCases/ # Test scripts
│ ├── test_001_VerifyPlaceOrder.py # Tests for order placement
│ ├── test_002_VerifyInvalidLogin.py # Tests for invalid login attempts
│ ├── test_003_VerifyAddToCart.py # Tests for adding products to cart
│ ├── test_004_VerifyRemoveFromCart.py # Tests for removing products from cart
│ ├── test_005_VerifyProductSearch.py # Tests for product search functionality
│ ├── conftest.py # Pytest fixtures and configuration
├── API_Utils/ # API testing utilities
│ ├── API_Client.py # Generic API client with methods for HTTP requests
│ ├── API_Factory.py # Factory pattern implementation for API testing
├── Common_Utils/ # Shared utilities
│ ├── logger.py # Custom logging implementation
│ ├── allure_utils.py # Utilities for Allure reporting
├── TestData/ # Test data files
│ └── creds.json # Credentials and test data in JSON format
├── BDD/ # Behavior-Driven Development tests
│ ├── features/ # Gherkin feature files
│ │ └── e2e.feature # Feature file for E2E scenarios
│ ├── step_definitions/ # Step implementation files
│ │ └── e2e_steps.py # Steps implementation for e2e.feature
├── allure-results/ # Generated Allure results
├── allure-report/ # Generated Allure report
├── requirements.txt # Python dependencies
└── pytest.ini # Pytest configuration
- Clone the repository:
git clone https://github.com/avdhutssh/Playwright-Pytest.git
- Navigate to the project directory:
cd Playwright-Pytest
- Install dependencies:
pip install -r requirements.txt
You can run the tests using pytest with various options:
pytest EcomAppAutomationFramework/TestCases/
pytest EcomAppAutomationFramework/TestCases/test_001_VerifyPlaceOrder.py
pytest EcomAppAutomationFramework/TestCases/ --alluredir=./allure-results
pytest EcomAppAutomationFramework/TestCases/ --headed
pytest EcomAppAutomationFramework/TestCases/ --browser_name=firefox
Available options: chrome
(default), firefox
, webkit
allure serve ./allure-results
The framework supports data-driven testing using parameterization in pytest. Test data is stored in JSON files and loaded dynamically during test execution.
Example of data-driven test:
@pytest.mark.parametrize('user_credentials', users_data)
def test_e2e_web_api(playwright:Playwright, browserInstance, user_credentials):
username = user_credentials['userEmail']
password = user_credentials['userPassword']
# Test steps using the provided credentials
This project integrates Allure Reports for detailed test execution reporting, including:
- Test execution results with pass/fail status
- Detailed logs from each test step
- Screenshots captured during test execution
- API request and response payloads
- Test execution timeline and duration
To view the reports:
- Run tests with Allure reporting enabled
- Generate and open the report
Feel free to reach out if you have any questions, or suggestions.
Happy Testing!
Avdhut Shirgaonkar