0
0
Selenium Javatesting~10 mins

Configuration management in Selenium Java - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test verifies that the Selenium WebDriver correctly loads configuration settings from a properties file and uses them to open a specified URL and check the page title.

Test Code - JUnit 5 with Selenium WebDriver
Selenium Java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.junit.jupiter.api.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class ConfigManagementTest {
    static WebDriver driver;
    static Properties config = new Properties();

    @BeforeAll
    public static void setup() throws IOException {
        FileInputStream fis = new FileInputStream("config.properties");
        config.load(fis);
        System.setProperty("webdriver.chrome.driver", config.getProperty("chrome.driver.path"));
        driver = new ChromeDriver();
    }

    @Test
    public void testOpenUrlAndCheckTitle() {
        String url = config.getProperty("app.url");
        String expectedTitle = config.getProperty("app.title");
        driver.get(url);
        Assertions.assertEquals(expectedTitle, driver.getTitle());
    }

    @AfterAll
    public static void teardown() {
        if (driver != null) {
            driver.quit();
        }
    }
}
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Load configuration from 'config.properties' fileProperties object contains keys: 'chrome.driver.path', 'app.url', 'app.title'Check that properties file loaded without IOExceptionPASS
2Set system property 'webdriver.chrome.driver' with path from configSystem property set for ChromeDriver executable path-PASS
3Initialize ChromeDriver instanceChrome browser window opensDriver instance is not nullPASS
4Navigate to URL from configurationBrowser loads the page at configured URLPage title is retrievablePASS
5Assert that page title matches expected title from configBrowser shows the loaded pageassertEquals(expectedTitle, actualTitle)PASS
6Close browser and quit driverBrowser window closes, driver quits-PASS
Failure Scenario
Failing Condition: Configuration file missing or incorrect path to ChromeDriver
Execution Trace Quiz - 3 Questions
Test your understanding
What is the purpose of loading 'config.properties' in this test?
ATo get configuration values like URL and driver path
BTo store test results
CTo initialize the Chrome browser
DTo write logs during test execution
Key Result
Using external configuration files helps keep test data and environment settings separate from test code, making tests easier to maintain and adapt to different environments.