public WebDriver setupDriver ( ) throws InvalidBrowserException { WebDriver driver ; // check the browser switch ( browser . getName ( ) ) { case HTMLUNIT : System . getProperties ( ) . put ( "org.apache.commons.logging.simplelog.defaultlog" , "fatal" ) ; java . util . logging . Logger . getLogger ( "com.gargoylesoftware.htmlunit" ) . setLevel ( Level . OFF ) ; java . util . logging . Logger . getLogger ( "org.apache.http" ) . setLevel ( Level . OFF ) ; driver = new HtmlUnitDriver ( desiredCapabilities ) ; break ; case FIREFOX : WebDriverManager . firefoxdriver ( ) . forceCache ( ) . setup ( ) ; FirefoxOptions firefoxOptions = new FirefoxOptions ( desiredCapabilities ) ; firefoxOptions . addArguments ( getBrowserOptions ( ) ) ; if ( Property . runHeadless ( ) ) { firefoxOptions . setHeadless ( true ) ; } driver = new FirefoxDriver ( firefoxOptions ) ; break ; case CHROME : WebDriverManager . chromedriver ( ) . forceCache ( ) . setup ( ) ; ChromeOptions chromeOptions = new ChromeOptions ( ) ; chromeOptions = chromeOptions . merge ( desiredCapabilities ) ; chromeOptions . addArguments ( getBrowserOptions ( ) ) ; if ( Property . runHeadless ( ) ) { chromeOptions . setHeadless ( true ) ; } driver = new ChromeDriver ( chromeOptions ) ; break ; case INTERNETEXPLORER : WebDriverManager . iedriver ( ) . forceCache ( ) . setup ( ) ; InternetExplorerOptions internetExplorerOptions = new InternetExplorerOptions ( desiredCapabilities ) ; driver = new InternetExplorerDriver ( internetExplorerOptions ) ; break ; case EDGE : WebDriverManager . edgedriver ( ) . forceCache ( ) . setup ( ) ; EdgeOptions edgeOptions = new EdgeOptions ( ) ; edgeOptions = edgeOptions . merge ( desiredCapabilities ) ; driver = new EdgeDriver ( edgeOptions ) ; break ; case SAFARI : SafariOptions safariOptions = new SafariOptions ( desiredCapabilities ) ; driver = new SafariDriver ( safariOptions ) ; break ; case OPERA : WebDriverManager . operadriver ( ) . forceCache ( ) . setup ( ) ; OperaOptions operaOptions = new OperaOptions ( ) ; operaOptions = operaOptions . merge ( desiredCapabilities ) ; driver = new OperaDriver ( operaOptions ) ; break ; case PHANTOMJS : WebDriverManager . phantomjs ( ) . forceCache ( ) . setup ( ) ; driver = new PhantomJSDriver ( desiredCapabilities ) ; break ; // if the browser is not listed, throw an error default : throw new InvalidBrowserException ( "The selected browser " + browser . getName ( ) + " is not an applicable choice" ) ; } return driver ; }
this creates the webdriver object which will be used to interact with for all browser web tests