Selenium + Java · Lesson 40 of 44
Module 40: Cross-Browser Testing
Your task
Implement normalizeBrowserName:
Write it in the editor, then press Check answer (Ctrl + Enter).
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.edge.EdgeDriver;
public class DriverFactory {
public static WebDriver createDriver(String browser) {
switch (browser.toLowerCase()) {
case "firefox":
return new FirefoxDriver();
case "edge":
return new EdgeDriver();
case "chrome":
default:
return new ChromeDriver();
}
}
}Users interact with your product across various browsers. In this lesson, you will architect a flexible DriverFactory that dynamically instantiates ChromeDriver, FirefoxDriver, or EdgeDriver based on configuration parameters. Let's build a cross-browser factory!
Part of the Selenium + Java course (Selenium with Java). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.
No, Safari and safaridriver run only on macOS. Cross-browser testing for Safari from Windows requires Selenium Grid or cloud machines.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___