Appium + Sauce Labs Bootcamp: Chapter 1, Language Bindings

Sauce AI for Test Authoring: Move from intent to execution in minutes.|xBack to ResourcesBlogPosted

May 30, 2026 · 13 min read · Tool Comparison

Sauce AI for Test Authoring: Move from intent to execution in minutes.

|

x

Back to Resources

Blog

Posted June 1, 2015

Appium + Sauce Labs Bootcamp: Chapter 1, Language Bindings

quote

Welcome to the first in our new series, Appium + Sauce Labs Bootcamp. This first chapter will extend an overview of Appium and its command, establish with detailed examples of the Java and Python language bindings. Later we will postdate up with examples in Ruby. This series locomote from fundamental concepts to supercharge techniques using Appium and Sauce Labs. The trouble is Beginner- & gt; Advanced. In Chapter 2 discussesTouch Actions; Chapter 3 coversTesting Hybrid Apps & amp; Mobile Web; and Chapter 4 is aboutAdvanced Desired Capabilities.

The Sauce & lt; - & gt; Client Relationship

Sauce Labs provides a service consisting of two APIs which operate at different conceptual levels — the Sauce API and the Webdriver API. Both go as HTTP (fix with SSL/TLS) and encode their data as mere JSON objects:

  • Commands which moderate an item-by-item Mobile Device (such as an iOS simulator or an Android copycat) are direct through the Webdriver API (urls which begin with ondemand.saucelabs.com/wd/hub).

  • Commands which interact with how Sauce Labs stores Tests and Builds eg: “ Passing/Failing ” are sent through the Sauce API (urls which begin with saucelabs.com/rest/).

When running an machine-controlled tryout script, every dictation, such as tip on the screen or typing into an input field, is sent as an HTTP request to an Appium server through the Sauce Labs Webdriver API. Since commands are sent as standard HTTP packets and every language has method for communicating over the Internet, automated trial can be run and written using any programming language. Automated tryout scripts are description of scenarios that users enact when using an app and it would be cumbersome to fill them full of code which assembles HTTP packets and sends them off to specific URL. For this reason, there exist a number ofwords bindings(sometimes phoneAppium Clients or driverssince they “ drive ” a mobile device) which provide a set of methods and use which handle communication with the Appium servers running in the Sauce cloud. The Appium Java client may provide a method for pressing the HOME button:

driver.sendKeyEvent (AndroidKeyCode.HOME);

And the Appium Python client may ply a slightly different use:

driver.keyevent (3)

But both functions render the same exact HTTP packet which is sent to: ondemand.saucelabs.com/wd/hub/session/ [session Id number] /appium/device/keyevent

{
“ keycode ”: 3
}

Developers and QA specializer who write automated examination scripts take ne'er concern themselves with long URLs like the one in the example above; this is the advantage provided by the language binding. The bidding that Appium accepts are a superset of the standard protocol used by Selenium host for automating web browsers. In order to extenuate the effort of learning something completely new, the Appium language bindings all continue and modify existing Selenium language binding. Though in some cases the method are very different, the documentation for the various Selenium clients is usually applicable to the Appium customer.

Test Configuration

In order to specify the environment that Sauce Labs will set up and use for run your app, you must populate a set of & quot; trust capabilities & quot;. The total list of capabilities that Appium can understand is specifiedhere, and the set of capabilities that Sauce Labs understands is here. The three most important capableness for mobile testing on Sauce with Appium are:platformName, which fix whether you are testing an & quot; Android & quot; or & quot; iOS & quot; app;platformVersion, which let you to stipulate a specific version of the platform (e.g., iOS & quot; 7.1 & quot; or & quot; 8.0 & quot;, or Android & quot; 4.3 & quot; or & quot; 4.4 & quot;); anddeviceName, through which iOS allows you to distinguish & quot; iPhone & quot; from & quot; iPad & quot;, and for Android, allows you to specify the device itself (e.g., & quot; Samsung Galaxy S3 & quot; or & quot; Nexus 7 & quot;). Further, there are two mutually exclusive capabilities for specifying the app under test:appallows you to define the native app, and must be an app you & # x27; ve already placed in Sauce Storage or the URL of the app somewhere on the internet;browserNameis expend for mobile web testing, allowing you to get a specific browser running on the mobile device (e.g., & quot; Safari & quot; or & quot; Chrome & quot;). If you are testing a native app, donot use browserName, and vice versa. For model, to tell Sauce Labs to use the application we receive uploaded with the namemy_app.apk, and to run it on an Android ape running Android 4.4 and emulating a Samsung Galaxy S3, we use the following capabilities:

1
{
2
& quot; app & quot;:& quot; sauce-storage: my_app.apk & quot;,
3
& quot; platformName & quot;:& quot; Android & quot;,
4
& quot; platformVersion & quot;:& quot; 4.4 & quot;,
5
& quot; deviceName & quot;:& quot; Samsung Galaxy S3 Emulator & quot;,
6
& quot; appiumVersion & quot;:& quot; 1.3.4 & quot;
7
}

For an iOS trial, with the following capabilities we will be telling Sauce Labs to use the covering we have uploaded with the gensmy_app.app, and run it on the iPhone simulator running iOS 8.1:

1
{
2
& quot; app & quot;:& quot; sauce-storage: my_app.app & quot;,
3
& quot; platformName & quot;:& quot; iOS & quot;,
4
& quot; platformVersion & quot;:& quot; 8.1 & quot;,
5
& quot; deviceName & quot;:& quot; iPhone Simulator & quot;,
6
& quot; appiumVersion & quot;:& quot; 1.3.4 & quot;
7
}

The final capability in both cases pertains to Appium itself. With appiumVersion you can use a specific frame of the Appium waiter (in this case, 1.3.4, the modish as of this writing). Since the configuration of your environment can be complex and getting it right is real important, Sauce Labs provides a tool, the Platform Configurator, which allows you to visually configure the test environment you want, and give code in your desired language. Through the desired capacity you will send to Sauce Labs, you get the environment in which you would wish your examination to run. From there, you can automate your test scenarios!

Instantiating a Driver

The various Appium language bindings part the conception of providing adriverobject. When desired capableness are direct to Sauce Labs, a new environment is set up and designate asession identifier. Each driver is associated with a single session identifier and therefore each driver is associated with a individual mobile device for the duration of a test. The different language bindings experience slightly different conventions, but they all postulate to do the pursuit at the showtime of each test:

  • Store the SAUCE_USERNAME and SAUCE_ACCESS_KEY for accessing the Sauce Cloud

  • Set http: //ondemand.saucelabs.com:80/wd/hub as the endpoint to post Appium commands to

  • Specify a set of desired capabilities for this test session

  • Send the desired capabilities to Sauce Labs and begin a new session

The pursuit are samples of instantiating Appium driver in Java and Python:

Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

Java

1
import io.appium.java_client.ios.IOSDriver;
2
import io.appium.java_client.remote.MobileCapabilityType;
3
import org.openqa.selenium.remote.DesiredCapabilities;
4
5
importation java.net.MalformedURLException;
6
import java.net.URL;
7
8
public form Main {
9
10
public static void primary (String [] args) throws MalformedURLException {
11
12
DesiredCapabilities desiredCapabilities = new DesiredCapabilities ();
13
desiredCapabilities.setCapability (& quot; name & quot;, & quot; iOS examination - Java & quot;);
14
desiredCapabilities.setCapability (MobileCapabilityType.PLATFORM_VERSION, & quot; 7.1 & quot;);
15
desiredCapabilities.setCapability (MobileCapabilityType.DEVICE_NAME, & quot; iPhone Simulator & quot;);
16
desiredCapabilities.setCapability (MobileCapabilityType.APP, & quot; http: //appium.s3.amazonaws.com/TestApp6.0.app.zip & quot;);
17
desiredCapabilities.setCapability (& quot; appiumVersion & quot;, & quot; 1.3.4 & quot;);
18
19
URL sauceUrl =new URL (& quot; http: // [SAUCE USERNAME]: [SAUCE_ACCESS_KEY] @ ondemand.saucelabs.com:80/wd/hub & quot;);
20
21
IOSDriver driver = new IOSDriver (sauceUrl, desiredCapabilities);
22
23
}
24
}

Python

1
from appium import webdriver
2
desired_capabilities={
3
& # x27; name & # x27;:& # x27; iOS test - Python & # x27;,
4
& # x27; platformName & # x27;:& # x27; iOS & # x27;,
5
& # x27; platformVersion & # x27;:& # x27; 7.1 & # x27;,
6
& # x27; deviceName & # x27;:& # x27; iPhone Simulator & # x27;,
7
& # x27; app & # x27;:& # x27; http: //appium.s3.amazonaws.com/TestApp6.0.app.zip & # x27;,
8
& # x27; appiumVersion & # x27;:& # x27; 1.3.4 & # x27;
9
}
10
sauce_url =& quot; http: // % s: % s @ ondemand.saucelabs.com:80/wd/hub & quot;
11
driver = webdriver.Remote(
12
desired_capabilities=desired_capabilities,
13
command_executor=sauce_url %(SAUCE_USERNAME,SAUCE_ACCESS_KEY)
14
)

Simple Commands

There are multiple commands uncommitted for the review of the elements present on the UI of a twist, and interacting with them. So many, in fact, that it can be overwhelming to learn them all at once. (The complete list is a combination of all the API endpoints delineate in theSelenium Documentation, and the Appium Documentation.) The maiden commands to learn are the following: Finding Elements

  • bump element

  • find constituent

Inspecting Elements

  • text

  • location

  • size

Interacting with Elements

  • click

  • send_keys

1
// Finding Elements In order to do any meaningful dictation, one demand a UI element to act with. Appium allows for finding UI constituent by a number of means. The preferred method is to find elements by their Accessibility Id. These would be identifier which app developer manually attach to important elements so that different handicap accessibility interfaces can meaningfully interpret the UI. The Android and iOS platforms both get Accessibility programs (iOS, Android).
2
3
MobileElement button = (MobileElement) driver.findElementByAccessibilityId (& quot; play-button & quot;);
4
push = self.driver.find_element_by_accessibility_id (& # x27; play-button & # x27;)
5
6
// Elements can also be found by using the gens of their form. On Android devices, these name start with “ android.widget. ” eg. “ android.widget.TextView ” and “ android.widget.LinearLayout ”. On iOS, class name begin with “ UIA ”, eg. “ UIATextField ” and “ UIATableView ”.
7
8
MobileElement push = (MobileElement) driver.findElementByClassName (& quot; UIAButton ”);
9
button = self.driver.find_element_by_class_name (& # x27; UIAButton & # x27;)
10
11
// If multiple elements are found by these commands, only the first is returned. For finding multiple element a pluralized version of each command subsist. These command return arrays of constituent.
12
13
MobileElement buttons = (List) (List & lt;? & gt;) driver.findElementsByAccessibilityId (& quot; play-button & quot;);
14
MobileElement buttons = (List) (List & lt;? & gt;) driver.findElementsByClassName (& quot; UIAButton ”);
15
buttons = self.driver.find_elements_by_accessibility_id (& # x27; play-button & # x27;)
16
push = self.driver.find_elements_by_class_name (& # x27; UIAButton & # x27;)
17
18
// One can find ingredient contained within another factor:
19
20
List tableViews = (List) (List & lt;? & gt;) driver.findElementsByClassName (& quot; UIATableView & quot;);
21
MobileElement push = (MobileElement) tableViews.get (2) .findElementByAccessibilityId (& quot; play-button & quot;);
22
tableViews = self.driver.find_elements_by_class_name (“ UIATableView ”)
23
button = tableViews [2] .find_element_by_accessibility_id (& # x27; play-button & # x27;)
24
25
// The Java customer has an alternative method of finding ingredient which behaves the same but has a somewhat different syntax:
26
27
MobileElement button = (MobileElement) driver.findElement (MobileBy.AccessibilityId (& quot; play button & quot;));
28
List buttons = (List) (List & lt;? & gt;) driver.findElements (By.className (& quot; UIAButton & quot;));
29

These different approaches to find elements (by class gens or by accessibility ID) are calledlocator scheme. Appium has additional locator strategies for chance ingredient by id, xpath, and platform specific locator like iOS UIAutomation commands and Android UIAutomator selectors. These will be discourse in a later chapter. Inspecting Elements By inspecting the properties of elements seeable on the UI, we can discover whether or not the app conduct as await. We can test for the presence of a popup, look for a user ’ s name when logged in, see that lists are populate, that persona are in the right place, etc. Whenever a UI element is “ institute ” through appium, the server returns an id, not an object populate with UI belongings. Additional functions require to be called in order to get the specific properties of an element. The “ textbook ” command returns the textual content of the element.

String buttonText = button.getText ();

buttonText = button.text

The “ location ” bid return the current location of the element on the blind, mensurate in pixels.

Point location = button.getLocation ();

location = button.location

The “ sizing ” dictation return the size of the element on the screen, measured in pixels.

Dimension dimension = button.getSize ()

dimension = button.size

Since these property are estimate when the command is called, if the element is no longer visible on the UI the bidding will neglect. Interacting with Elements By interacting with factor, we assume the actions of a user, type into battlefield, press buttons, tapping the blind, and performing touch gestures. Use the “ click ” command to simulate tap on an factor:

button.click ();

button.click ()

Use the “ send key ” dictation to type into a text field.

textField.sendKeys (“ Hi, my name is ”);

textField.send_keys (‘ Hi, my gens is ’)

Touch gesture will be discussed in a later chapter. Discussed above are the basic command for finding, inspecting, and interacting with UI elements. The examples are in Java and Python. Each language binding follows conventions special to its developer civilisation, but they all encompass the same set of commands. When in doubt, check the documentation for a particular language binding.

Python Example

1
import unittest
2
import os
3
import sys
4
from appium import webdriver
5
fromsauceclientimportSauceClient
6
7
USERNAME = os.environ.get(& # x27; SAUCE_USERNAME & # x27;)
8
ACCESS_KEY= os.environ.get(& # x27; SAUCE_ACCESS_KEY & # x27;)
9
sauce =SauceClient(USERNAME,ACCESS_KEY)
10
11
classSimpleIOSSauceTests(unittest.TestCase):
12
13
defsetUp(self):
14
self.desired_capabilities={
15
& # x27; platformName & # x27;:& # x27; iOS & # x27;,
16
& # x27; platformVersion & # x27;:& # x27; 7.1 & # x27;,
17
& # x27; deviceName & # x27;:& # x27; iPhone Simulator & # x27;,
18
& # x27; app & # x27;:& # x27; http: //appium.s3.amazonaws.com/TestApp6.0.app.zip & # x27;,
19
& # x27; appiumVersion & # x27;:& # x27; 1.3.4 & # x27;,
20
& # x27; name & # x27;: self.id()
21
}
22
23
sauce_url =& quot; http: // % s: % s @ ondemand.saucelabs.com:80/wd/hub & quot;
24
self.driver = webdriver.Remote(
25
desired_capabilities=self.desired_capabilities,
26
command_executor=sauce_url %(USERNAME,ACCESS_KEY)
27
)
28
self.driver.implicitly_wait(30)
29
30
deftearDown(self):
31
print(& quot; Link to your job: https: //saucelabs.com/jobs/ % s & quot;% self.driver.session_id)
32
try:
33
if sys.exc_info()==(None,None,None):
34
sauce.jobs.update_job(self.driver.session_id, passed=True)
35
else:
36
sauce.jobs.update_job(self.driver.session_id, passed=False)
37
finally:
38
self.driver.quit()
39
40
deftest_ui_computation(self):
41
# populate text fields with values
42
field_one = self.driver.find_element_by_accessibility_id(& # x27; TextField1 & # x27;)
43
field_one.send_keys(12)
44
45
field_two = self.driver.find_elements_by_class_name(& # x27; UIATextField & # x27;)[1]
46
field_two.send_keys(8)
47
48
# they should be the like sizing, and the first should be above the second
49
self.assertLess(field_one.location[& # x27; y & # x27;], field_two.location[& # x27; y & # x27;])
50
self.assertEqual(field_one.size, field_two.size)
51
52
# trigger computation by using the button
53
self.driver.fi
Published:
Jun 1, 2015
Share this billet
Copy Share Link
LinkedIn
© 2026 Sauce Labs Inc., all rights reserved. SAUCE and SAUCE LABS are registered trademarks owned by Sauce Labs Inc. in the United States, EU, and may be registered in other jurisdictions.
robot
quote

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free