private static WebDriver getDriver ( final Builder builder ) { // this is the default value DesiredCapabilities capabilities = getCapabilitiesBrowser ( builder . browser ) ; WebDriver driver = null ; /** * Setting the proxy */ LOG . info ( "Proxy seetings set" ) ; org . openqa . selenium . Proxy proxy = new org . openqa . selenium . Proxy ( ) ; if ( builder . proxyHost != null && ! builder . proxyHost . isEmpty ( ) ) { if ( ! builder . proxyHost . equals ( "direct" ) ) { proxy . setAutodetect ( false ) ; proxy . setHttpProxy ( builder . proxyHost + ":" + builder . proxyPort ) . setFtpProxy ( builder . proxyHost + ":" + builder . proxyPort ) . setSslProxy ( builder . proxyHost + ":" + builder . proxyPort ) . setNoProxy ( builder . noProxyFor ) ; } else { proxy . setProxyType ( ProxyType . DIRECT ) ; } capabilities . setCapability ( CapabilityType . PROXY , proxy ) ; } /** * the Driver will take screenshots */ LOG . info ( "Screenshot capability set" ) ; capabilities . setCapability ( CapabilityType . TAKES_SCREENSHOT , true ) ; /** * setting the platform: LINUX, MAC or Windows. Remember that sometimes * the browsers are linked to a platform like IE for example */ if ( builder . platform != null ) { capabilities . setCapability ( CapabilityType . PLATFORM , builder . platform ) ; } if ( builder . browserVersion != null ) { capabilities . setCapability ( CapabilityType . VERSION , builder . browserVersion ) ; } /** * set if javascript is enabled */ capabilities . setJavascriptEnabled ( builder . jsEnabled ) ; /** * set if the browser will accept all certificates, including the * self-signed ones */ capabilities . setCapability ( CapabilityType . ACCEPT_SSL_CERTS , builder . acceptAllCertificates ) ; /** * this will actually create firefox profiles, chrome options and others */ LOG . info ( "Adding specific browser settings" ) ; addSpecificBrowserSettings ( capabilities , builder ) ; /** * getting an actual WebDriver implementation now */ LOG . info ( "Detecting running mode" ) ; if ( builder . runMode . equalsIgnoreCase ( Constants . RunMode . GRID ) ) { LOG . info ( "Run mode GRID. Setting GRID properties" ) ; try { driver = new RemoteWebDriver ( new URL ( builder . gridUrl ) , capabilities ) ; ( ( RemoteWebDriver ) driver ) . setLogLevel ( Level . SEVERE ) ; } catch ( Exception e ) { LOG . debug ( "Exception while initiating remote driver:" , e ) ; } } else { LOG . info ( "Normal run mode. Getting driver instance" ) ; driver = getDriverInstance ( capabilities , builder ) ; } LOG . info ( "Returning the following driver: " + driver ) ; LOG . info ( "With capabilities: " + capabilities ) ; return driver ; }
This method returns a fully configured WebDriver instance based on the parameters sent .