0
0
Selenium Javatesting~10 mins

Properties file for configuration in Selenium Java - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test reads a URL from a properties file and verifies that the browser navigates to the correct page. It checks the page title to confirm successful navigation.

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 ConfigPropertiesTest {
    static WebDriver driver;
    static Properties props = new Properties();

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

    @Test
    public void testNavigateToUrlFromProperties() {
        String url = props.getProperty("url");
        driver.get(url);
        String title = driver.getTitle();
        Assertions.assertEquals("Example Domain", title);
    }

    @AfterAll
    public static void teardown() {
        if (driver != null) {
            driver.quit();
        }
    }
}
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Load properties file 'config.properties' from file systemProperties object contains key 'url' with value 'https://example.com'-PASS
2Set system property for ChromeDriver and launch Chrome browserChrome browser window opens, ready for commands-PASS
3Navigate browser to URL read from properties fileBrowser loads 'https://example.com' page-PASS
4Get page title from browserPage title is 'Example Domain'Assert page title equals 'Example Domain'PASS
5Close browser and quit WebDriverBrowser window closes, WebDriver session ends-PASS
Failure Scenario
Failing Condition: Properties file missing or URL key not found
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after navigating to the URL from the properties file?
AThe page title matches the expected value
BThe URL is printed in the console
CThe browser window size is correct
DThe properties file is deleted
Key Result
Using a properties file for configuration helps keep test data like URLs separate from code, making tests easier to maintain and update without changing the test script.