Appium Tip #5: Ready to Rumble with Ruby?

  October 12, 2015

We’re back with a new blog in our Things You Should Know About Appium and this time we will focus on using Ruby to write robust Appium tests. Ruby has become popular in past years as a similar scripting language to Python and Ruby is a dynamic, reflective, object-oriented general-purpose programming language using in a variety of different purposes.

In a nutshell, Ruby is a language comparable to Python in its simplicity and clearness, although it does require a bit more investment of time to learn. Once you get used to it though, Ruby can become a very powerful tool due to its well defined and robust design. You can download our complete Appium beginner’s guide to set up a proper Ruby environment for Appium mobile testing.

You’ll find here all the steps you need to start your tests – using Ruby – against real mobile devices on Bitbar Testing.

Getting Started

First and the foremost, you should install Bundler to ensure all necessary gems and dependencies gets installed properly. Then, update your test script (testdroid_*.rb) with necessary information. Always do remember to modify your desired capabilities before you start a test. This will always save you time and effort as you don’t have to run a test to realize there was something wrong with desired capabilities.

Ok, here is how to install:

$ gem install bundler
$ bundle install

Launch a test:

$ rspec testdroid_android.rb

NOTE! There are some common settings that you need to set in all scripts regardless of the app type that you are testing. Each testdroid_*.rb file needs to be updated with the following values.

Here are all the values that you need to configure:

  • screen_shot_dir – where should screenshots be stored on your local drive
  • testdroid_username – the email that you use to sign up for Bitbar Testing
  • testdroid_password – your password
  • testdroid_project – has a default value, but you might want to add your own name to this. The project name is visible in your project view in the cloud. Each project must have a unique name
  • testdroid_testrun – name or number of this test run. Test run names can be modified even at every test run
  • testdroid_app – should be the name of the app you uploaded to the cloud. Eg. if you uploaded your app using a script this would look something like this: ‘f4660af0-10f3-46e9-932b-0622f497b0d2/Testdroid.apk’ If you uploaded your app through the web UI, you can use here the value ‘latest’ that refers to the latest uploaded app file.
Native iOS Specific Settings

Example script: testdroid_appiumdriver_ios.rb

To run your Appium tests against your native iOS application with real devices you need to edit the testdroid_appiumdriver_ios.rb script.

In addition to the above mentioned Appium capabilities for iOS testing you need set:

  • bundleId – this is your application’s unique name

Two Tips for Ruby on Appium

(1) You can launch your Appium test to use the latest app file you uploaded through the Bitbar Testing portal by setting the testdroid_app desired capability value to ‘latest’.

(2) To automate device finding, you could check this Ruby tool contributed by bootstrap online. The tool is actually a port from our Python script based on the Bitbar API. The API can be utilized to do basically all the things our Portal allows you to do, and then a bit more! Documentation for the API can be found here.

See you again next week!