Back to All Scenarios
Scenario 60 of 100
Framework Design
Intermediate
Executing Cross-Browser Automation Suites
πScenario Overview
Executing Cross-Browser Automation Suites
Key Takeaways & Cheat Sheet
- βAbstract driver initialization using the dynamic Factory Pattern
- βPass target browsers dynamically using testng.xml execution settings
- βAvoid using browser-specific selectors (like webkit relative properties)
- βEnforce consistent window sizes across all target browsers
Short Direct Answer
To run cross-browser tests, build a dynamic Driver Factory pattern that accepts a browser name parameter. Map browser selections to ChromeDriver, FirefoxDriver, or EdgeDriver setups. In TestNG, use the `@Parameters` annotation to pass the browser variable from your `testng.xml` suite directly to your base setup class.
β οΈ Senior Warning (Red Flag)
Never write duplicate test methods for different browsers. Keep tests fully decoupled from the driver initialization logic.
π‘ STAR Deep Dive Explanation & Pro Tip
Enforce standard dimensions rather than maximize() across all browsers. Browsers react differently to maximize calls on remote systems, which can cause inconsistent responsive states.
SeleniumAutomation.java
Selenium 4 + Java// BaseTest class handling cross-browser parameterization
public class BaseTest {
protected WebDriver driver;
@Parameters("browser")
@BeforeMethod
public void setUp(@Optional("chrome") String browser) {
if (browser.equalsIgnoreCase("chrome")) {
driver = new ChromeDriver();
} else if (browser.equalsIgnoreCase("firefox")) {
driver = new FirefoxDriver();
} else if (browser.equalsIgnoreCase("edge")) {
driver = new EdgeDriver();
}
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
driver.manage().window().setSize(new Dimension(1920, 1080));
}
@AfterMethod
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
}