The Sauce Labs Cookbook

Sauce Headless

Front End Performance Testing

Analytics

External Resources

More Info


Page tree
Skip to end of metadata
Go to start of metadata

Creating a WebDriver Instance

The WebDriver instance is the starting point for all uses of the Mobile JSON Wire Protocol.

You create an instance of the WebDriver interface using a constructor for either Android or iOS. For mobile native application tests, you set both the platform and browser to test against by setting the browserName desired capability. 

Once you have created an instance of the WebDriver interface, you use this instance to invoke methods, such as tap and swipe, to access other interfaces used in basic test steps. You do so by assigning the instance to a variable when you create it, and by using that variable to invoke methods.

WebDriver Examples

These psuedo-code examples illustrate how to instantiate iOS and Android WebDriver objects in the various Appium language bindings.

Visit the java-client page for more information on the Java Appium language bindings.

iOS Example
WebDriver driver = new iOSDriver<WebElement>( new URL("https://ondemand.saucelabs.com/wd/hub"), capabilities);
Android Example
WebDriver driver = new AndroidDriver<WebElement>( new URL("https://ondemand.saucelabs.com/wd/hub"), capabilities);

Visit the python-client page for more information on the Python Appium language bindings.

iOS Example
desired_caps = {}
desired_caps['platformName'] = 'iOS'
desired_caps['app'] = PATH('../../apps/MyIOS.app.zip')
self.driver = webdriver.Remote('https://ondemand.saucelabs.com/wd/hub', desired_caps)
Android Exmaple
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['app'] = PATH('../../apps/MyIOS.apk')
self.driver = webdriver.Remote('https://ondemand.saucelabs.com/wd/hub', desired_caps)

We recommend using the webdriverio testing utility as your WebDriver testing framework for node.js. For more information, refer to the documentation.

iOS Example
const opts = {
  capabilities: {
    platformName: "iOS",
    app: "/path/to/the/downloaded/MyiOS.app.zip",
  }
};

const client = wdio.remote(opts);
Android Example
const opts = {
  capabilities: {
    platformName: "Android",
    app: "/path/to/the/downloaded/MyAndroid.apk",
  }
};

const client = wdio.remote(opts);

Visit appium_lib for more information about the Ruby Appium language bindings.

iOS Example
opts = { caps: { platformName: :ios, app: '/path/to/MyiOS.app'}, appium_lib: { wait_timeout: 30 }}
appium_driver = Appium::Driver.new(opts, true)
appium_driver.start_driver
Android Example
opts = { caps: { platformName: :android, app: '/path/to/MyAndroid.apk'}, appium_lib: { wait_timeout: 30 }}
appium_driver = Appium::Driver.new(opts, true)
appium_driver.start_driver

Visit the appium-dot-net page for more information about the C# Appium language bindings.

iOS Example
var sauceURL = "https://ondemand.saucelabs.com/wd/hub";
var driver = new IOSDriver<IWebElement>(new Uri(sauceURL));
Android Example
var sauceURL = "https://ondemand.saucelabs.com/wd/hub";
var driver = new AndroidDriver<IWebElement>(new Uri(sauceURL));
  • No labels