The setDriver method for mobile

Now, here is a slight variation on the same method using the mobile drivers. Of course, these conditions would be built into the same setDriver method, as would support for all browsers and mobile devices.

The Appium driver has its own remote driver capabilities, and casting a remote URL to the driver will start it on the appropriate grid node:

// 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 platformVersion = "9.3";
String localHubURL = "http://127.0.0.1:4723/wd/hub";
String remoteHubURL = "http://myGridHubURL:4444/wd/hub";

switch ( browser ) {
case "iphone":
// set up the mobile device capabilities
...
caps = DesiredCapabilities.iphone();
// caps = DesiredCapabilities.android();

// then pass them to the local WebDriver or RemoteWebDriver
if ( environment.equalsIgnoreCase("local") ) {
mobileDriver.set(new IOSDriver<MobileElement>
(new URL(localHubURL), caps));
// mobileDriver.set(new AndroidDriver<MobileElement>
// (new URL(localHubURL, caps));
}

break
;
}

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

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

caps.setCapability("automationName", "XCUITest");

mobileDriver.set(new IOSDriver<MobileElement>
(new URL(remoteHubURL), caps));
// mobileDriver.set(new AndroidDriver<MobileElement>
// (new URL(remoteHubURL), caps));
}
}

In this example, both the iPhone and Android drivers were noted for simplicity's sake; they would be in a separate case for each.

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

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