0
0
Selenium Pythontesting~8 mins

Browser profile configuration in Selenium Python - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Browser profile configuration
Folder Structure
selenium-python-project/
├── src/
│   ├── pages/
│   │   └── login_page.py
│   ├── tests/
│   │   └── test_login.py
│   ├── utils/
│   │   └── browser_factory.py
│   └── config/
│       ├── config.yaml
│       └── credentials.yaml
├── reports/
│   └── test_report.html
├── requirements.txt
└── pytest.ini
Test Framework Layers
  • Driver Layer: utils/browser_factory.py manages browser setup including profiles and options.
  • Page Objects: src/pages/ contains page classes encapsulating UI elements and actions.
  • Tests: src/tests/ holds test scripts using page objects and driver instances.
  • Utilities: Helper functions and browser configuration logic reside in utils/.
  • Configuration: Environment settings, browser preferences, and credentials are stored in config/ files.
Configuration Patterns

Browser profiles are configured in utils/browser_factory.py using Selenium's Options and profile settings.

  • Use config/config.yaml to specify environment variables like browser type and profile paths.
  • Load configurations at runtime to create browser instances with custom profiles (e.g., Chrome user data directory or Firefox profile).
  • Keep sensitive data like credentials separate in credentials.yaml and load securely.
  • Example: For Chrome, set options.add_argument('--user-data-dir=path') to use a specific profile.
Test Reporting and CI/CD Integration
  • Use pytest with plugins like pytest-html to generate readable HTML reports in reports/.
  • Integrate tests into CI/CD pipelines (GitHub Actions, Jenkins) to run with configured browser profiles on different environments.
  • Store reports as artifacts for review after automated runs.
  • Configure headless mode in browser profiles for CI environments without GUI.
Best Practices
  1. Isolate Browser Profiles: Use separate profiles per test or environment to avoid state conflicts.
  2. Keep Configurations External: Store profile paths and browser options outside code for easy updates.
  3. Use Explicit Waits: Combine profile setup with waits to ensure stable tests.
  4. Support Multiple Browsers: Design browser_factory.py to handle Chrome, Firefox, and others with profile options.
  5. Secure Sensitive Data: Never hardcode credentials or profile paths; load them securely.
Self Check

Where in this folder structure would you add a new browser profile configuration for Firefox?

Key Result
Use a dedicated browser factory utility to configure and manage browser profiles externally from test logic.