How to run cuucmber script on multiple browser

 

  We can write start method in base class like below
  
  
  @Before
   public WebDriver start() {

        String webdriver = System.getProperty("browser", "chrome");
        switch(webdriver) {
            case "firefox":
                System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir") + "/geckodriver");
                driver = new FirefoxDriver();
                driver.get("http://live.guru99.com/");
                driver.manage().window().maximize();
                waitDriver = new WebDriverWait(driver, TIMEOUT);
                driver.manage().timeouts().implicitlyWait(TIMEOUT, TimeUnit.SECONDS);
                driver.manage().timeouts().pageLoadTimeout(PAGE_LOAD_TIMEOUT, TimeUnit.SECONDS);
                return driver;
            case "chrome":
                System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/chromedriver");
                driver = new ChromeDriver();
                driver.get("http://live.guru99.com/");
                driver.manage().window().maximize();
                waitDriver = new WebDriverWait(driver, TIMEOUT);
                driver.manage().timeouts().implicitlyWait(TIMEOUT, TimeUnit.SECONDS);
                driver.manage().timeouts().pageLoadTimeout(PAGE_LOAD_TIMEOUT, TimeUnit.SECONDS);
                return driver;
            default:
                throw new RuntimeException("Unsupported webdriver: " + webdriver);
        }

}
  
  
  Then we can run like mvn test -Dbrowser=chrome or mvn test -Dbrowser=firefox
  
  Default browser we set chrome
  
  mvn test