Appium Bootcamp – Chapter 6: Run Your Tests

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

May 26, 2026 · 10 min read · Tool Comparison

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

|

x

Back to Resources

Blog

Posted August 8, 2014

Appium Bootcamp – Chapter 6: Run Your Tests

quote

[UPDATE- November 2019]You can find the newest Get Started with Appium white papers here:Get Started with Appium- Java and Get Started with Appium- Ruby

This is the sixth post in a series ring Appium Bootcamp by noted Selenium expertDave Haeffner. 

Dave recently immersed himself in the open root Appium project and collaborated with result Appium contributor Matthew Edwards to convey us this material. Appium Bootcamp is for those who are brand new to mobile test automation with Appium. No familiarity with Selenium is required, although it may be useful. This is the sixth of eight posts; two new posts will be turn each week.

Now that we hold our tests indite, refactored, and pass topically it & # x27; s clip to make them simple to launch by wrapping them with a command-line executor. After that, we & # x27; ll be able to easily add in the power to run them in the cloud.

Quick Setup

appium_libcomes pre-wired with the power to run our tryout in Sauce Labs, but we & # x27; re still depart to need two additional library to reach everything;rakefor command-line performance, andsauce_whiskfor some additional tasks not extend byappium_lib.

Let & # x27; s add these to ourGemfile and run bundle install.

1
# filename: Gemfile
2
3
source & # x27; https: //rubygems.org & # x27;
4
5
gem & # x27; rspec & # x27;,& # x27; ~ & gt; 3.0.0 & # x27;
6
gem & # x27; appium_lib & # x27;,& # x27; ~ & gt; 4.0.0 & # x27;
7
gem & # x27; appium_console & # x27;,& # x27; ~ & gt; 1.0.1 & # x27;
8
gem & # x27; rake & # x27;,& # x27; ~ & gt; 10.3.2 & # x27;
9
gem & # x27; sauce_whisk & # x27;,& # x27; ~ & gt; 0.0.13 & # x27;

Uncomplicated Rake Tasks

Now that we get our needed library let & # x27; s create a new file in the labor radical nameRakefileand add tasks to launch our tests.

1
# filename: Rakefile
2
3
desc & # x27; Run iOS tests & # x27;
4
task :ios do
5
Dir.chdir & # x27; ios & # x27;
6
exec& # x27; rspec & # x27;
7
end
8
9
desc & # x27; Run Android tests & # x27;
10
task :android do
11
Dir.chdir & # x27; android & # x27;
12
exec& # x27; rspec & # x27;
13
end

Notice that the syntax in this file reads a lot like Ruby -- that & # x27; s because it is (along with some Rake specific syntax). For a primer on Rake, saythis.

In this file we & # x27; ve created two tasks. One to run our iOS tests, and another for the Android tests. Each task vary directory into the right twist folder (e.g.,Dir.chdir) and then launches the tests (e.g.,exec & # x27; rspec & # x27;).

If we salve this file and runrake -Tfrom the command-line, we will see these tasks listed along with their description.

& gt; rake -T
rake android # Run Android trial
rake ios # Run iOS tests

If we run either of these tasks (e.g., rake android or rake ios), they will fulfill the tests topically for each of the device.

Running Your Tests In Sauce

As I mentioned before,appium_libcomes with the ability to run Appium tests in Sauce Labs. We just necessitate to condition a Sauce account username and access key. To obtain an admittance key, you first need to have an account (if you don & # x27; t get one you can create a free test onehere). After that, log into the account and go to the bottom left of your dashboard; your admittance key will be listed thither.

We & # x27; ll too necessitate to get our apps available to Sauce. This can be accomplish by either uploading the app to Sauce, or, do the app available from a publicly available URL. The anterior approach is easy enough to achieve with the help ofsauce_whisk.

Let & # x27; s go ahead and update ourspec_helper.rbto add in this new upload capability (along with a twosome of other bits).

1
# filename: common/spec_helper.rb
2
3
require & # x27; rspec & # x27;
4
require & # x27; appium_lib & # x27;
5
require & # x27; sauce_whisk & # x27;
6
7
defusing_sauce
8
user = ENV[& # x27; SAUCE_USERNAME & # x27;]
9
key = ENV[& # x27; SAUCE_ACCESS_KEY & # x27;]
10
user && !user.empty? && key && !key.empty?
11
end
12
13
defupload_app
14
storage =SauceWhisk::Storage.new
15
app = @caps[:caps][:app]
16
storage.upload app
17
18
@caps[:caps][:app]=& quot; sauce-storage: # {File.basename (app)} & quot;
19
end
20
21
defsetup_driver
22
returnif $driver
23
@caps= Appium.load_appium_txtfile: File.join(Dir.pwd,& # x27; appium.txt & # x27;)
24
ifusing_sauce
25
upload_app
26
@caps[:caps].delete :avd # re: https: //github.com/appium/ruby\_lib/issues/241
27
end
28
Appium::Driver.new @caps
29
end
30
31
defpromote_methods
32
Appium.promote_singleton_appium_methods Pages
33
Appium.promote_appium_methods RSpec::Core::ExampleGroup
34
end
35
36
setup_driver
37
promote_methods
38
39
RSpec.configure do|config|
40
41
config.before(:each) do
42
$driver.start_driver
43
end
44
45
config.after(:each) do
46
driver_quit
47
end
48
49
end

Near the top of the file we pull insauce_whisk. We then add in a couple of helper method (using_sauce and upload_app). using_saucechecks to see if Sauce credentials have been set properly.upload_appuploads the application from local disk and so updates the capabilities to reference the route to the app on Sauce & # x27; s storage.

We put these to use insetup_driverby wrapping them in a conditional to see if we are using Sauce. If so, we upload the app. We & # x27; re also removing theavdcapability since it will have topic with our Sauce run if we keep it in.

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

Next we & # x27; ll need to update ourappium.txtfiles so they & # x27; ll play nice with Sauce.

1
# filename: android/appium.txt
2
3
[caps]
4
appium-version =& quot; 1.2.0 & quot;
5
deviceName=& quot; Android & quot;
6
platformName=& quot; Android & quot;
7
platformVersion=& quot; 4.3 & quot;
8
app =& quot; .. / .. / .. /apps/api.apk & quot;
9
avd =& quot; training & quot;
10
11
[appium_lib]
12
require =[& quot; ./spec/requires.rb & quot;]
13
# filename: ios/appium.txt
14
15
[caps]
16
appium-version =& quot; 1.2.0 & quot;
17
deviceName=& quot; iPhone Simulator & quot;
18
platformName=& quot; ios & quot;
19
platformVersion=& quot; 7.1 & quot;
20
app =& quot; .. / .. / .. /apps/UICatalog.app.zip & quot;
21
22
[appium_lib]
23
require =[& quot; ./spec/requires.rb & quot;]

In order to act with Sauce we take to specify theappium-version and the platformVersion. Everything else stays the same. You can see a full list of Sauce & # x27; s endorse platforms and shape optionshere.

Now let & # x27; s update our Rake tasks to be cloud aware. That way we can specify at run time whether to run things topically or in Sauce.

1
desc & # x27; Run iOS tests & # x27;
2
task :ios,:location do|t, args|
3
location_helper args[:location]
4
Dir.chdir & # x27; ios & # x27;
5
exec& # x27; rspec & # x27;
6
end
7
8
desc & # x27; Run Android quiz & # x27;
9
task :android,:fix do|t, args|
10
location_helper args[:location]
11
Dir.chdir & # x27; android & # x27;
12
exec& # x27; rspec & # x27;
13
end
14
15
deflocation_helper(location)
16
if location !=& # x27; sauce & # x27;
17
ENV[& # x27; SAUCE_USERNAME & # x27;], ENV[& # x27; SAUCE_ACCESS_KEY & # x27;]= nil, nil
18
end
19
end

We & # x27; ve update our Rake tasks so they can take an argument for the location. We so use this argument value and pass it tolocation_helper. The location_helperexpression at the location value -- if it is not set to& # x27; sauce & # x27;then the Sauce credentials get set tonil. This helps us ensure that we really do want to run our tests on Sauce (e.g., we have to specify both the Sauce credentials AND the location).

Now we can launch our tests locally just like before (e.g.,rake ios) or in Sauce by delimit it as a location (e.g.,rake ios [& # x27; sauce & # x27;])

But in order for the tests to discharge in Sauce Labs, we involve to set our certificate someway. We & # x27; ve opted to maintain them out of ourRakefile(and our exam codification) so that we can maintain succeeding tractableness by not having them hard-coded; which is also more secure since we won & # x27; t be committing them to our repository.

Specifying Sauce Credentials

There are a few means we can go about specifying our credentials.

Specify them at run-time

SAUCE_USERNAME=your-username SAUCE_ACCESS_KEY=your-access-key profligate ios [& # x27; sauce & # x27;]

Export the value into the current command-line session

exportation SAUCE_USERNAME=your-username
exportation SAUCE_ACCESS_KEY=your-access-key

Set the values in your belt profile (recommended)

# filename: ~/ * .bash_profile

...
export SAUCE_USERNAME=your-username
exportation SAUCE_ACCESS_KEY=your-access-key

After choosing a method for specifying your credentials, run your tests with one of the Rake project and specify & # x27; sauce & # x27; for the locating. Then log into your Sauce Account to see the exam results and a picture of the execution.

Making Your Sauce Runs Descriptive

It & # x27; s outstanding that our tests are now running in Sauce. But it & # x27; s tough to sift through the test resolution since the name and test status are nondescript and all the same. Let & # x27; s fix that.

Fortunately, we can dynamically set the Sauce Labs job name and test status in our test code. We just need to provide this information before and after our tryout escape. To do that we & # x27; ll need to update the RSpec configuration incommon/spec_helper.rb.

1
# filename: common/spec_helper.rb
2
3
...
4
RSpec.configure do|config|
5
6
config.before(:each) do |example|
7
$driver.caps[:name]= example.metadata[:full_description]ifusing_sauce
8
$driver.start_driver
9
end
10
11
config.after(:each) do |example|
12
ifusing_sauce
13
SauceWhisk::Jobs.change_status $ driver.driver.session_id, example.exception.nil?
14
end
15
driver_quit
16
end
17
18
end

In before (: each)we update thenamedimension of our capabilities (e.g.,cap [: gens]) with the name of the test. We get this gens by tapping into the test & # x27; s metadata (e.g.,example.metadata [: full_description]). And since we solely need this to run if we & # x27; re using Sauce we wrap it in a conditional.

In after (: each)we leveragesauce_whiskto set the job status base on the test effect, which we get by checking to see if any exceptions were raised. Again, we only want this to run if we & # x27; re using Sauce, so we wrap it in a conditional too.

Now if we run our tests in Sauce we will see them fulfil with the correct name and job status.

Outro

Now that we have local and cloud performance covered, it & # x27; s time to automate our trial footrace by plugging them into a Uninterrupted Integration (CI) server.

Follow Dave on Twitter -@ tourdedave

Continue the indication the former chapters:

Published:
Aug 8, 2014
Topics
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