0
0
Selenium Pythontesting~8 mins

Logging setup in Selenium Python - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Logging setup
Folder Structure
selenium-python-project/
├── tests/
│   ├── test_login.py
│   └── test_checkout.py
├── pages/
│   ├── login_page.py
│   └── checkout_page.py
├── utils/
│   ├── logger.py
│   └── helpers.py
├── config/
│   ├── config.yaml
│   └── credentials.yaml
├── drivers/
│   └── chromedriver.exe
├── reports/
│   └── test_report.html
├── conftest.py
└── pytest.ini
Test Framework Layers
  • Driver Layer: Manages browser drivers and WebDriver setup (e.g., in conftest.py).
  • Page Objects: Classes representing web pages with locators and actions (in pages/).
  • Tests: Test cases using pytest in tests/ folder.
  • Utilities: Helper modules like logger.py for logging setup and other helpers.
  • Configuration: Environment settings, credentials, and test parameters in config/.
  • Reports: Test execution reports stored in reports/.
Configuration Patterns
  • Environment Config: Use config/config.yaml to store URLs, timeouts, and environment-specific settings.
  • Credentials: Store sensitive data like usernames and passwords in config/credentials.yaml, keep it secure and out of version control.
  • Logging Setup: Configure logging in utils/logger.py to create log files with timestamps and set log levels (INFO, DEBUG, ERROR).
  • Browser Options: Define browser type and options in conftest.py or config files for flexibility.
Test Reporting and CI/CD Integration
  • Use pytest built-in options or plugins like pytest-html to generate readable HTML reports saved in reports/.
  • Integrate logging output with test reports for detailed debugging information.
  • Configure CI/CD pipelines (e.g., GitHub Actions, Jenkins) to run tests automatically and publish reports.
  • Ensure logs are archived or uploaded as artifacts for troubleshooting failed tests.
Best Practices for Logging Setup in Selenium Python Framework
  • Centralize Logging: Create a single logger setup module (utils/logger.py) to maintain consistency.
  • Use Appropriate Log Levels: Use DEBUG for detailed info, INFO for general events, WARNING for potential issues, and ERROR for failures.
  • Timestamp Logs: Include timestamps in log messages to track when events happen.
  • Log to File and Console: Configure logging to output both to console and to rotating log files for persistence.
  • Keep Logs Clean: Avoid logging sensitive information like passwords.
Self Check

Where in this framework structure would you add a new logger configuration to capture detailed test execution logs?

Key Result
Centralize logging setup in a utility module to maintain consistent, timestamped logs across tests.