0
0
Selenium Javatesting~8 mins

Properties file for configuration in Selenium Java - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Properties file for configuration
Folder Structure
project-root/
├── pom.xml                        # Maven build file
├── testng.xml                    # TestNG suite configuration
└── src/
    ├── main/
    │   └── java/
    │       └── com/example/app/
    │           └── pages/          # Page Object classes
    └── test/
        ├── java/
        │   └── com/example/
        │       ├── tests/          # Test classes
        │       └── utils/
        │           └── ConfigReader.java            # Utility to read properties
        └── resources/
            └── config.properties            # Properties file for configuration
  
Test Framework Layers
  • Configuration Layer: Reads config.properties using ConfigReader utility.
  • Page Object Layer: Classes representing UI pages, using config values if needed.
  • Test Layer: Test classes that use page objects and config data.
  • Utility Layer: Helpers like ConfigReader to load properties, WebDriver setup, waits.
  • Resource Layer: Stores properties files and test data files.
Configuration Patterns

Use a config.properties file in src/test/resources to store environment variables like URLs, browser types, timeouts, and credentials.

Example config.properties:

baseUrl=https://example.com
browser=chrome
timeout=10
username=testuser
password=testpass
  

Create a ConfigReader utility class to load these properties once and provide getters.

Use Maven profiles or system properties to switch environments by loading different properties files or overriding values.

Test Reporting and CI/CD Integration
  • Use TestNG reports for test execution results.
  • Integrate with CI tools like Jenkins or GitHub Actions to run tests automatically on code changes.
  • Pass environment or browser parameters via CI build parameters to control config values dynamically.
  • Generate HTML or XML reports for easy review.
Best Practices
  • Keep sensitive data like passwords out of version control by using environment variables or encrypted files.
  • Load properties once per test run to improve performance.
  • Use descriptive keys in properties files for clarity.
  • Use fallback default values in code if a property is missing.
  • Separate environment-specific properties (dev, test, prod) into different files.
Self Check

Where in this folder structure would you add a new property for the test environment URL?

Key Result
Use a properties file in src/test/resources with a ConfigReader utility to manage test configuration cleanly.