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.
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.
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(); } } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Create FirefoxProfile and set homepage preference to 'https://example.com' | FirefoxProfile object created with custom homepage preference | - | PASS |
| 2 | Create FirefoxOptions and assign the custom profile | FirefoxOptions configured with the custom profile | - | PASS |
| 3 | Launch FirefoxDriver with the configured options | Firefox browser opens with the custom profile loaded | - | PASS |
| 4 | Check initial URL after launch to verify profile homepage | Browser opens to the homepage set in profile | Check if current URL contains 'example.com' | PASS |
| 5 | Verify that the browser homepage is 'https://example.com' | Browser URL is 'https://example.com' or contains it | assertTrue(currentUrl.contains("example.com")) | PASS |
| 6 | Close the browser and quit the driver | Browser closed, WebDriver session ended | - | PASS |