appium-rspec-setup-gem-logo (1)

TL; DR: If you want to add testing to your mobile projects, you should consider our Appium Rspec Setup gem. It includes both Rspec and an Appium-compatible library to allow RSpec to reach through and drive the virtual device of your choice.

 appium-logo-sauce-black

WHAT IT IS

Before we talk about why you need our gem, let’s talk about why you might need Appium.

Appium is a test framework designed for automated testing of mobile apps. It can be used for testing any development project that will run in an iOS device simulator or an Android device emulator, including native apps targeting those platforms or websites being developed against a mobile browser. It does this by actually driving the emulator/simulator based on test specs and then testing their assertions about what’s supposed to happen.

The trade-off for all this power and flexibility is that it takes quite a bit of time and setup to configure Appium to work with your project. Not only do you have to setup Appium itself, but you need to pick a test suite as a basis to build and run the tests. You also have to configure it to work with Appium so that the tests can drive the device emulator/simulator. Lastly, you need to pick and configure a testing framework to actually use as the bed for your test suite.

If you’re interested in doing Appium testing and you’re comfortable with Ruby, or just willing to learn, our gem helps you to avoid the work we spent getting everything setup and working so you can do behavioral testing of your mobile-targeted code.

Your choices are plentiful and include many frameworks in languages ranging from JavaScript to PHP to Java; but they can be narrowed by using a language that you find familiar, and then your preference for a particular approach to testing. This is where our humble gem comes into the picture.

If you use our professionally-curated choice of a testing framework and install our gem library, you can run a quick setup dialog from your project directory; we’ll take it from there to get you up and running so that you can concentrate on writing your tests. Which leads us to…

 

WHY YOU’D WANT IT

At Agape Red, we’ve done quite a few of our greenfield projects in Ruby on Rails, so we’ve had a lot of time to get comfortable with Rspec, and have grown to love the readable test setup and expectation syntax. In addition to being well documented, there are quite a few resources available for getting comfortable with Rspec, our favorite being Relish Apps’ online guide.

Our gem, Appium Rspec Setup, provides help by providing a way to include both Rspec, as a test framework to define your tests against, and an Appium-compatible library, the appropriately-named Appium Lib gem, to let it reach through and drive the virtual device of your choice.

 

HOW IT WORKS

By using a Gemfile to load our gem, you can let it install the testing dependencies in a centrally manageable place in your project to get up and running quickly. The Gemfile.lock ensures that you get the same versions of everything that worked in the initial setup, and Bundler let’s you individually update the Rspec and Appium Lib gems as new features and fixes are rolled out in the future.

 

HOW TO USE IT

How to include it in a project:

https://github.com/agapered/Appium-Rspec-Setup

 

Using In Android

Once the gem is installed you can start creating your tests! The first thing you need to do is start adding your test files to the spec folder. The test files need to follow the typical rspec format which follows the (insert name here)_spec.rb format. For example, if I wanted to create a new test file it could look something like login_spec.rb. Once the file is created then each one of these files looks very similar to what you’d see in rspec. However, there is some basic setup before you can start writing your tests. The setup looks something like…

All these before and after methods are doing is starting and shutting down the Appium driver which makes these tests possible. Once this is setup you can start writing your tests. Your tests will look extremely similar to what you’d see in rspec. You group similar tests by using the describe – do syntax then your individual tests using the it – do syntax. Your tests might look something like this.

 

Adding actual Android tests

To find the full range of functionality you can visit the docs at http://www.rubydoc.info/github/appium/ruby_lib/Appium/Android. In this blog post we will run through some basic examples. You have a couple of options when trying to find a specific view.

If you want to find a view by its id you can use the id method.

We are not limited to using ids to find views, we can also use the text.

Both the id and text methods will grab references of the views. Once you have a reference of the view you can perform actions on it or check the contents of it. For example, if you have an EditText you can send characters to the view.

Once you are done manipulating the views you can start checking if the results are correct. The way you do this is through the RSpec expects syntax.

As seen above, you test the view for a certain state. In this case we are testing if the view is there or not. You finish the expect statement with a check to the expected result. If the result isn’t what you expected the test will fail. From here you can write the tests you desire.

 

Differences for iOS

Testing iOS is similar to Android, except iOS controls aren’t referenced by ID so it’s important to check controls based on their content instead of assigned handles. To see a list of the control types that are unique to iOS, be sure to reference: http://www.rubydoc.info/github/appium/ruby_lib/Appium/Ios

 

Give It a Try

Our Appium Rspec Setup gem provides a quick way to add Rspec as a framework to define your tests against, and an Appium-compatible library to drive the virtual device of your choice. Use it to test your next project and tell us what you think.

No Comments