Complete test automation framework for the Expense Tracker application using Selenium, Pytest, and Allure Reports.
- Project Structure
- Prerequisites
- Installation
- Configuration
- Running Tests
- Generating Allure Reports
- Test Coverage
- Page Object Model
TestAutomation/
βββ Pages/
β βββ __init__.py
β βββ ExpensePage.py # Page Object Model for Expense Tracker page
βββ Tests/
β βββ __init__.py
β βββ ExpenseTest.py # All test cases
βββ Utils/
β βββ __init__.py
β βββ UtilLib.py # Utility functions and helpers
βββ __init__.py
βββ conftest.py # Pytest fixtures and configuration
βββ pytest.ini # Pytest configuration
βββ requirements-test.txt # Python dependencies
βββ README_AUTOMATION.md # This file
- Python: 3.8 or higher
- Chrome Browser: Latest version
- ChromeDriver: Compatible with your Chrome version
- pip: Python package manager
- Python 3.8+ - Download Python
- Chrome Browser - Download Chrome
- ChromeDriver - Download ChromeDriver
- Ensure ChromeDriver version matches your Chrome browser version
- Add ChromeDriver to your PATH or place it in the project directory
cd c:\Automation\Assess# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activatepip install -r requirements-test.txt# Check Chrome version
chrome --version
# Verify chromedriver is accessible
chromedriver --versionThe base URL is configured in conftest.py:
base_url="http://127.0.0.1:5000"To change the URL, edit the navigate_to_app fixture in TestAutomation/conftest.py:
@pytest.fixture(scope="function")
def navigate_to_app(common_methods):
common_methods.navigate_to_url("http://your-new-url:port")
yield common_methodsEdit TestAutomation/Utils/UtilLib.py in the DriverFactory.get_chrome_driver() method:
@staticmethod
def get_chrome_driver(headless=False):
options = webdriver.ChromeOptions()
options.add_argument("--no-sandbox")
# Add more options as needed
driver = webdriver.Chrome(options=options)
return driverLogs are automatically generated in the Logs/ directory with timestamp:
- File format:
automation_YYYYMMDD_HHMMSS.log - Log level: DEBUG (file) and INFO (console)
pytest TestAutomation/Tests/ExpenseTest.py -v --alluredir=allure-results# Run Add Expense tests
pytest TestAutomation/Tests/ExpenseTest.py::TestAddExpense -v --alluredir=allure-results
# Run Delete Expense tests
pytest TestAutomation/Tests/ExpenseTest.py::TestDeleteExpense -v --alluredir=allure-results
# Run Clear Expenses tests
pytest TestAutomation/Tests/ExpenseTest.py::TestClearExpenses -v --alluredir=allure-results
# Run Filter & Navigation tests
pytest TestAutomation/Tests/ExpenseTest.py::TestFilterAndNavigation -v --alluredir=allure-resultspytest TestAutomation/Tests/ExpenseTest.py::TestAddExpense::test_add_single_expense -v --alluredir=allure-results# Run only smoke tests
pytest TestAutomation/Tests/ExpenseTest.py -m smoke -v --alluredir=allure-results
# Run only regression tests
pytest TestAutomation/Tests/ExpenseTest.py -m regression -v --alluredir=allure-results
# Run add expense tests
pytest TestAutomation/Tests/ExpenseTest.py -m add_expense -v --alluredir=allure-results
# Run delete expense tests
pytest TestAutomation/Tests/ExpenseTest.py -m delete_expense -v --alluredir=allure-results
# Run clear expenses tests
pytest TestAutomation/Tests/ExpenseTest.py -m clear_expenses -v --alluredir=allure-results# Run tests using 4 workers
pytest TestAutomation/Tests/ExpenseTest.py -v -n 4 --alluredir=allure-results# Each test has a 300 second timeout
pytest TestAutomation/Tests/ExpenseTest.py -v --timeout=300 --alluredir=allure-resultsTo run tests in headless mode (no browser window):
Edit conftest.py and change:
@pytest.fixture(scope="function")
def driver():
browser_driver = DriverFactory.get_chrome_driver(headless=True) # Change to TrueInstall Allure:
# On Windows
choco install allure
# or download from: https://github.com/allure-framework/allure2/releases
# On macOS
brew install allure
# On Linux
sudo apt-add-repository ppa:qameta/allure
sudo apt-get update
sudo apt-get install allure# Run tests with allure results
pytest TestAutomation/Tests/ExpenseTest.py -v --alluredir=allure-results
# Generate HTML report from results
allure generate allure-results --clean -o allure-report
# Serve the report (opens in browser)
allure serve allure-resultsOpen the generated report:
# Navigate to report directory
cd allure-report
# Open index.html in browser
start index.html # Windows
open index.html # macOS
xdg-open index.html # Linux| Test Case | Description |
|---|---|
test_add_single_expense |
Add a single expense with valid data |
test_add_multiple_expenses |
Add multiple expenses sequentially |
test_add_expense_with_custom_date |
Add expense with custom date |
test_add_expense_all_categories |
Add expenses in all categories |
test_total_amount_calculation |
Verify total calculation after adding |
| Test Case | Description |
|---|---|
test_delete_single_expense |
Delete a single expense |
test_delete_multiple_expenses |
Delete multiple expenses |
test_total_updates_after_deletion |
Verify total updates after deletion |
| Test Case | Description |
|---|---|
test_clear_all_expenses |
Clear all expenses at once |
test_total_zero_after_clear |
Verify total becomes zero after clearing |
test_add_after_clear |
Add expenses after clearing |
| Test Case | Description |
|---|---|
test_filter_by_category |
Filter expenses by category |
test_get_all_expenses |
Retrieve all expenses from table |
The ExpensePage class encapsulates all interactions with the Expense Tracker page:
Navigation & Verification:
verify_page_loaded()- Verify page is loadedverify_expense_added(description)- Verify expense was addedverify_expense_deleted(description)- Verify expense was deletedverify_expenses_cleared()- Verify all expenses clearedverify_error_message(expected_text)- Verify error messageverify_success_message(expected_text)- Verify success message
Add Expense:
add_expense(amount, category, description, date=None)- Add new expense
Delete Expense:
delete_expense(description)- Delete expense by description
Clear Expenses:
clear_all_expenses()- Clear all expenses
Filtering & Retrieval:
filter_by_category(category)- Filter by categoryget_all_expenses()- Get all expenses from tableget_total_amount()- Get total amountget_expense_count()- Get expense count
All UI element locators are defined as class variables using various strategies (ID, CLASS_NAME, XPATH, etc.):
AMOUNT_INPUT = (By.ID, "amount")
CATEGORY_DROPDOWN = (By.ID, "category")
EXPENSES_TABLE = (By.CLASS_NAME, "expenses-table")
# ... more locatorsget_logger(logger_name)- Create configured logger instance
get_chrome_driver(headless=False)- Create Chrome WebDriver
wait_for_element_visible(locator, timeout)- Wait for element visibilitywait_for_element_clickable(locator, timeout)- Wait for element clickabilitywait_for_element_presence(locator, timeout)- Wait for element presencewait_for_text_in_element(locator, text, timeout)- Wait for text
click_element(locator)- Click elemententer_text(locator, text)- Enter textget_text(locator)- Get element textselect_from_html_select(locator, value)- Select dropdown valueaccept_alert()- Accept alertdismiss_alert()- Dismiss alert
navigate_to_url(url)- Navigate to URLrefresh_page()- Refresh pagemaximize_window()- Maximize windowclose_driver()- Close WebDrivertake_screenshot(filename)- Take screenshot
# Smoke tests - Quick validation tests
@pytest.mark.smoke
# Regression tests - Full test suite
@pytest.mark.regression
# Feature-specific markers
@pytest.mark.add_expense
@pytest.mark.delete_expense
@pytest.mark.clear_expensesKey configurations:
- Test discovery patterns
- Allure report directory:
allure-results - Timeout: 300 seconds per test
- Logging enabled with file output
- Custom markers defined
# Download correct ChromeDriver version
# Match your Chrome version from:
# chrome://version/
# Add to PATH or specify in code:
options.add_argument(f"webdriver.chrome.driver=/path/to/chromedriver")If port 5000 is already in use:
- Update the base URL in conftest.py
- Or stop the Flask app: Press Ctrl+C in Flask terminal
Increase timeout in pytest.ini:
timeout = 600 # 10 minutespip install --upgrade seleniumpip install allure-pytest
# And install Allure CLI from: https://github.com/allure-framework/allure2/releasesname: Test Automation
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.10'
- run: pip install -r requirements-test.txt
- run: pytest TestAutomation/Tests/ExpenseTest.py --alluredir=allure-results
- uses: actions/upload-artifact@v2
with:
name: allure-results
path: allure-results/- Use Page Object Model - Encapsulate UI interactions
- Meaningful Test Names - Self-documenting test cases
- Setup & Teardown - Use fixtures for initialization
- Logging - Enable detailed logging for debugging
- Screenshots - Automatic on failure
- Markers - Organize tests by type and feature
- Assertions - Use meaningful assertion messages
- Waits - Use explicit waits instead of sleep()
- Data Isolation - Clear data between tests
- Parallel Execution - Use pytest-xdist for speed
For issues or questions:
- Check the logs in
Logs/directory - Review Allure reports for detailed test information
- Enable debug logging for more details
- Check screenshots in
Screenshots/directory on failures
This test automation framework is provided for testing the Expense Tracker application.
Version: 1.0.0
Last Updated: February 2026
Framework: Selenium + Pytest + Allure