protected WebDriver createHtmlUnitDriver() {
   DesiredCapabilities capabilities = DesiredCapabilities.htmlUnitWithJs();
   capabilities.merge(createCommonCapabilities());
   capabilities.setCapability(HtmlUnitDriver.INVALIDSELECTIONERROR, true);
   capabilities.setCapability(HtmlUnitDriver.INVALIDXPATHERROR, false);
   if (browser.indexOf(':') > -1) {
     // Use constants BrowserType.IE, BrowserType.FIREFOX, BrowserType.CHROME etc.
     String emulatedBrowser = browser.replaceFirst("htmlunit:(.*)", "$1");
     capabilities.setVersion(emulatedBrowser);
   }
   return new HtmlUnitDriver(capabilities);
 }
  private static void initDriver(String browser) {
    String browserName = System.getProperty("browser", browser);
    String browserRemoteName = System.getProperty("remote", "local");

    if (browserRemoteName.equals("local")) {
      switch (browserName) {
        case "chrome":
        default:
          driver = new ChromeDriver();
          break;
        case "firefox":
          driver = new FirefoxDriver();
          break;
        case "ie":
          driver = new InternetExplorerDriver();
          break;
        case "html":
          driver = new HtmlUnitDriver();
          break;
        case "phantomjs":
          driver = new PhantomJSDriver();
          break;
      }
    } else {
      DesiredCapabilities caps;
      switch (browserName) {
        case "chrome":
        default:
          caps = DesiredCapabilities.chrome();
          break;
        case "firefox":
          caps = DesiredCapabilities.firefox();
          break;
        case "ie":
          caps = DesiredCapabilities.internetExplorer();
          break;
        case "html":
          caps = DesiredCapabilities.htmlUnitWithJs();
          break;
        case "phantomjs":
          caps = DesiredCapabilities.phantomjs();
          break;
      }
      try {
        driver = new RemoteWebDriver(new URL(browserRemoteName), caps);
      } catch (Exception ex) {
        System.out.println(ex.getMessage());
      }
    }

    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.manage().window().maximize();
  }