Comprehensive automation testing framework for AutomationExercise.com e-commerce platform using Playwright and Python
AutomationExercise.Tests.Python/
βββ src/
β βββ api_client/ # API client and controllers
β β βββ base_client.py # Base API client class
β β βββ controllers/ # Domain controllers (Products, Brands, User, etc.)
β βββ configs/ # Test configurations
β βββ data/ # Static data and test files
β β βββ attachments/ # Test documents and images
β βββ fixtures/ # Test data fixtures
β βββ helpers/ # Utilities and helper functions
β βββ mailing/ # Email notification system
β βββ models/ # Page Objects and data models
β β βββ pages/ # Page Object Models
β β βββ product/ # Product-related models
β β βββ user/ # User-related models
β β βββ order/ # Order-related models
β βββ tests/ # Test suites
β βββ api/ # API tests
β βββ user_interface/ # E2E/UI tests
βββ results/ # Reports and results (auto-generated)
βββ conftest.py # Global pytest configuration
βββ pytest.ini # Pytest configuration
βββ requirements.txt # Python dependencies
βββ README.md # This file
- Python (version 3.8 or higher)
- Pip (Python package installer)
- Git
-
Clone the repository:
git clone [REPOSITORY_URL] cd AutomationExercise.Tests.Python -
Create virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Install Playwright browsers:
playwright install
-
Setup environment variables:
cp env.example .env
Edit
.envfile with your configuration:# AutomationExercise.com Configuration BASE_URL=https://automationexercise.com API_BASE_URL=https://automationexercise.com/api # Test User Credentials TEST_EMAIL=test.user@example.com TEST_PASSWORD=testpassword123 TEST_USERNAME=TestUser # Email Configuration (for reporting) EMAIL_USER=your.email@gmail.com EMAIL_PASS=your_app_password EMAIL_RECIPIENTS="recipient@example.com" # Test Configuration HEADLESS=true BROWSER=chromium TIMEOUT=30000
Run all API tests:
pytest src/tests/api/ -vRun all UI tests:
pytest src/tests/user_interface/ -v# Run products API tests
pytest src/tests/api/test_products_api.py -v
# Run login UI tests
pytest src/tests/user_interface/test_e2e_login.py -v# Run only API tests
pytest -m api -v
# Run only UI tests
pytest -m ui -v
# Run smoke tests
pytest -m smoke -vpytest -n auto -v# Generate HTML report
pytest --html=results/playwright-report-python/index.html --self-contained-html
# Generate JUnit XML report
pytest --junitxml=results/test-results-python/python-junit-results.xml
# Generate coverage report
pytest --cov=src --cov-report=html:results/coverage-reportOur framework covers all 14 AutomationExercise.com API endpoints:
- β API 1: GET All Products List
- β API 2: POST To All Products List (Error handling)
- β API 5: POST To Search Product
- β API 6: POST To Search Product without parameter (Error handling)
- β API 3: GET All Brands List
- β API 4: PUT To All Brands List (Error handling)
- β API 7: POST To Verify Login with valid details
- β API 8: POST To Verify Login without email parameter
- β API 9: DELETE To Verify Login (Error handling)
- β API 10: POST To Verify Login with invalid details
- β API 11: POST To Create/Register User Account
- β API 12: DELETE METHOD To Delete User Account
- β API 13: PUT METHOD To Update User Account
- β API 14: GET user account detail by email
- Authentication Flow: Login, Signup, Logout
- Product Browsing: Product listing, search, filtering, details
- Shopping Cart: Add/remove items, quantity updates, checkout
- User Account: Registration, profile management
- Navigation: Menu navigation, responsive design
HomePage: Main landing page interactionsLoginPage: Authentication and registrationProductsPage: Product catalog and searchCartPage: Shopping cart functionality
# Base API Client
class BaseAPIClient:
def __init__(self, request_context: APIRequestContext, base_url: str = None):
self.request = request_context
self.base_url = base_url or os.getenv('API_BASE_URL')
def get(self, endpoint: str, params: Dict[str, Any] = None) -> Dict[str, Any]:
response = self.request.get(f"{self.base_url}{endpoint}")
return {"status": response.status, "data": response.json()}
# Domain-specific Controllers
class ProductsController(BaseAPIClient):
def get_all_products(self) -> Dict[str, Any]:
return self.get("/productsList")
def search_product(self, search_term: str) -> Dict[str, Any]:
form_data = {"search_product": search_term}
return self.post_form("/searchProduct", form_data)class ProductsPage(BasePage):
def __init__(self, page: Page):
super().__init__(page)
self.products_section = page.locator('.features_items')
self.search_product_input = page.locator('#search_product')
self.add_to_cart_buttons = page.locator('a.add-to-cart[data-product-id]')
def search_for_product(self, search_term: str) -> None:
self.search_product_input.fill(search_term)
self.submit_search_button.click()
def add_product_to_cart(self, index: int) -> None:
self.add_to_cart_buttons.nth(index).click()After test execution, reports are available in:
- HTML Report:
./results/playwright-report-python/index.html - JUnit Report:
./results/test-results-python/python-junit-results.xml - Coverage Report:
./results/coverage-report/index.html
Automated email reports include:
- Test execution summary
- Failed test details
- Compressed artifacts (screenshots, videos, traces)
The framework uses pytest.ini for configuration:
[tool:pytest]
testpaths = src/tests
python_files = test_*.py *_test.py
addopts =
--strict-markers
--verbose
--html=results/playwright-report-python/index.html
--junitxml=results/test-results-python/python-junit-results.xml
--cov=srcAll environment-specific settings are managed through .env file:
- Base URLs for different environments
- Test user credentials
- Email notification settings
Test data is organized using Pytest fixtures:
@pytest.fixture
def test_data():
return {
"valid_user": {
"email": "test.user@example.com",
"password": "testpassword123",
"name": "TestUser"
},
"products_data": {
"search_terms": ["dress", "tshirt", "jean"],
"expected_product_count": 10
}
}Strongly-typed data models ensure consistency:
class Product(BaseModel):
id: int
name: str
price: str
brand: str
category: ProductCategoryname: E2E Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- run: pip install -r requirements.txt
- run: playwright install
- run: pytest src/tests/api/ -v
- run: pytest src/tests/user_interface/ -v- API Tests: Create new test files in
src/tests/api/ - UI Tests: Create new test files in
src/tests/user_interface/ - Page Objects: Add new page objects in
src/models/pages/ - API Controllers: Add new controllers in
src/api_client/controllers/
- Use Python type hints for better code clarity
- Follow Page Object Model for UI tests
- Implement proper error handling
- Add comprehensive assertions
- Use descriptive test names
- Maintain test independence
- Clean up test data after execution
- AutomationExercise.com - Test application
- AutomationExercise API Documentation - API documentation
- Playwright Documentation - Testing framework
- Python Documentation - Programming language
- Pytest Documentation - Testing framework
- Fork the repository
- Create a feature branch:
git checkout -b feature/new-feature - Commit changes:
git commit -am 'Add new feature' - Push to branch:
git push origin feature/new-feature - Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Built with β€οΈ using Playwright and Python