Categories
Automated Testing Python Selenium

Folder Structure Python Selenium Framework with Pytest

Here’s a recommended project structure for end-to-end (E2E) testing with Python, Selenium, and pytest:

project_folder/
├── tests/
│   ├── e2e/
│   │   ├── test_suite_1/
│   │   │   ├── test_case_1.py
│   │   │   └── test_case_2.py
│   │   └── test_suite_2/
│   │       ├── test_case_3.py
│   │       └── test_case_4.py
├── pages/
│   ├── home_page.py
│   ├── login_page.py
│   └── registration_page.py
├── utils/
│   ├── test_data.py
│   ├── configuration.py
│   └── logger.py
├── reports/
│   ├── screenshots/
│   ├── videos/
│   └── test_results.html
├── drivers/
│   ├── chromedriver.exe
│   └── geckodriver.exe
├── conftest.py
├── pytest.ini
├── main.py
└── README.md

Let’s break down the key components of this structure:

  • tests/e2e/: This folder contains all the E2E test suites and individual test cases. Group related test cases into separate directories to represent test suites.
  • pages/: This folder holds page object classes that represent different pages or components of the web application. Each page object class encapsulates the corresponding page’s elements and actions, promoting code reusability and maintainability.
  • utils/: This folder includes utility modules that provide common functions and resources for tests, such as test data management, configuration settings, and logging.
  • reports/: Used to store test reports, screenshots, videos, and other artifacts generated during test execution.
  • drivers/: Contains the necessary browser drivers (e.g., chromedriver, geckodriver) required for Selenium to interact with browsers.
  • conftest.py: This file is used by pytest to define fixtures, which are functions that provide reusable test resources or set up preconditions for tests.
  • pytest.ini: A configuration file used by pytest to customize test execution behavior, such as specifying test discovery patterns, test markers, and reporting options.
  • main.py: Serves as the entry point for running the tests, orchestrating test execution, importing necessary modules, and defining global test configurations.
  • README.md: Provides project documentation, installation instructions, prerequisites, and other relevant information for developers or contributors.

This structure promotes modularity, maintainability, and ease of navigation for your E2E testing project. It separates concerns by keeping tests, page objects, utilities, and configurations in distinct folders, making it easier to manage and scale your test suite.

Remember to use pytest fixtures for efficient test setup and teardown, adopt the Page Object Model for better maintainability, implement robust selector strategies, and consider using pytest markers to organize and categorize your tests.