The setDriver method for browser

In the main setDriver method, we had first set up a series of switch cases for each browser and mobile type. In those cases, we set the browser/mobile preferences and desired capabilities. Once that was done, we cast them to the local WebDriver and it was launched.

Now, we need to check and see if the user passed in the environment parameter as "local" or "remote" and cast caps to the correct driver:

// setDriver method - create the WebDriver or AppiumDriver instance

@SafeVarargs
public final void setDriver(String browser,
String platform,
String environment,
Map<String, Object>... optPreferences)
throws Exception {

DesiredCapabilities caps = null;
String ffVersion = "55.0";
String remoteHubURL = "http://myGridHubURL:4444/wd/hub";

switch ( browser ) {
case "firefox":
// set up the browser prefs and capabilities
...
caps = DesiredCapabilities.firefox();

// then pass them to the local WebDriver or RemoteWebDriver
if ( environment.equalsIgnoreCase("local") ) {
webDriver.set(new FirefoxDriver(caps));
}

break;
}

if ( environment.equalsIgnoreCase("remote") ) {

caps.setCapability("browserName", browser);
caps.setCapability("version", ffVersion);
caps.setCapability("platform", platform);
caps.setCapability("applicationName",
platform.toUpperCase() + "-" +
browser.toUpperCase());

webDriver.set(new RemoteWebDriver(
new URL(remoteHubURL), caps));

((RemoteWebDriver) webDriver.get()).setFileDetector(
new LocalFileDetector());
}
}

In this example, the Firefox driver capabilities were set up in the switch statement and either cast to local WebDriver or, if running remotely on the grid, cast to RemoteWebDriver.

Notice the remote hub URL was passed to RemoteWebDriver, along with several capabilities that would cause the Selenium hub to direct traffic to a specific node. Those were browserName, version, platform, and applicationName. We will explain them in more detail as we build the JSON configuration files.

Also, RemoteWebDriver called setFileDetector, which allowed files residing in the local workspace to be uploaded to the application remotely.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.116.183