**Python Selenium Automation Framework Architecture (With Example)
Introduction
**
In this blog, we will be seeing a basic scalable Selenium automation framework architecture using Python.
This structure is suitable for real-time projects, supports maintainability, with the Page Object Model (POM) design pattern.
**1. Let see first what is selenium architecture
selenium is the architecture that is used to test code and to maintain it in a organized way.
1.1. In Python, Selenium frameworks are commonly built using:
Py-Test – Test execution & reporting
Selenium WebDriver – Browser automation
Page Object Model (POM) – Design pattern
1.2 See how the architecture flow works:
Test Case
↓
Page Object
↓
WebDriver
↓
Browser
*1.3 Recommended Folder Structure:
*
selenium_framework/
│
├── tests/
├── pages/
├── utilities/
├── configs/
├── reports/
├── screenshots/
├── conftest.py
├── pytest.ini
└── requirements.txt
1.4 Component-by-Component Explanation
1️⃣ Tests Layer (tests/)
📌 Purpose
Contains only test logic
Validates application behavior
No Selenium locators or driver setup
📌 Responsibilities
✔ Calling page methods
✔ Assertions
✔ Test data usage
✅ Example
def test_login(setup):
login.login("Admin", "admin123")
assert dashboard.is_displayed()
Page Object Layer (pages/)📌 Purpose
Implements Page Object Model (POM)
📌 Responsibilities
✔ Locators
✔ Page actions
✔ Page validations
❌ What NOT to add
Assertions
Test logic
3️⃣ Utilities / Core Layer (utilities/)
📌 Purpose
Reusable framework components
Common functionality shared across tests
4️⃣ Configuration Layer (configs/)
📌 Purpose
Environment-based data storage
Avoid hard-coded values
📌 Common Data
✔ URLs
✔ Browser names
✔ Timeouts
✔ Credentials (secured)
✅ Example
[env]
url=https://example.com
browser=chrome
5️⃣ PyTest Fixture Layer (conftest.py)
📌 Purpose
Centralized test setup & teardown
Dependency injection for tests
📌 Responsibilities
✔ Driver initialization
✔ Browser cleanup
✔ Test environment setup
6️⃣ Reporting Layer (reports/)
📌 Purpose
Test execution visibility
Failure analysis
📌 Common Tools
✔ Allure
✔ PyTest HTML
✔ Extent Reports
7️⃣ Screenshots Layer (screenshots/)
📌 Purpose
Capture failures
Debugging support
📌 When Captured
✔ On test failure
✔ On exceptions
🔄 Execution Flow (Step-by-Step)
PyTest starts execution
conftest.py initializes WebDriver
Test case starts
Test calls Page Object methods
Page Object interacts with browser
Assertion validates result
Screenshot captured on failure
Browser closes
🎯 Design Principles Followed
✅ Separation of Concerns
Each layer has only one responsibility
✅ Reusability
Page objects and utilities reused across tests
✅ Maintainability
UI changes affect only page classes
✅ Scalability
Easy to add:
New pages
New test cases
New browsers
Top comments (0)