0
0
Selenium Javatesting~10 mins

Browser profile management in Selenium Java - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a browser with a custom profile to verify that the profile settings are applied correctly. It checks if the browser loads a specific page and confirms the profile's effect.

Test Code - JUnit
Selenium Java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class BrowserProfileTest {
    private WebDriver driver;

    @BeforeEach
    public void setUp() {
        FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference("browser.startup.homepage", "https://example.com");
        profile.setPreference("browser.startup.page", 1);
        FirefoxOptions options = new FirefoxOptions();
        options.setProfile(profile);
        driver = new FirefoxDriver(options);
    }

    @Test
    public void testHomePageWithProfile() {
        driver.get("about:blank");
        String currentUrl = driver.getCurrentUrl();
        assertTrue(currentUrl.contains("example.com"), "Browser did not start with the profile homepage");
    }

    @AfterEach
    public void tearDown() {
        if (driver != null) {
            driver.quit();
        }
    }
}
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Create FirefoxProfile and set homepage preference to 'https://example.com'FirefoxProfile object created with custom homepage preference-PASS
2Create FirefoxOptions and assign the custom profileFirefoxOptions configured with the custom profile-PASS
3Launch FirefoxDriver with the configured optionsFirefox browser opens with the custom profile loaded-PASS
4Check initial URL after launch to verify profile homepageBrowser opens to the homepage set in profileCheck if current URL contains 'example.com'PASS
5Verify that the browser homepage is 'https://example.com'Browser URL is 'https://example.com' or contains itassertTrue(currentUrl.contains("example.com"))PASS
6Close the browser and quit the driverBrowser closed, WebDriver session ended-PASS
Failure Scenario
Failing Condition: The browser does not load the homepage set in the custom profile
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after launching the browser with the custom profile?
AThe browser opens a blank page
BThe browser homepage is set to 'https://example.com'
CThe browser profile is empty
DThe browser crashes on startup
Key Result
Always verify that custom browser profiles are correctly loaded by checking the browser state or URL after launch to ensure your preferences are applied.