ios_appium_rspec

iOS Integration Tests With Appium

| 0 Comments

I came from the RoR web development and – as we all know – Rails community loves tests. Personally, I am a fan of acceptance testing and using mostly capybara for it. So, when I shifted to the iOS development, it was essential for me to find some decent acceptance testing tools like Apple’s UI Automation, Calabash and Appium. The last one appeared to be a test automation framework of iOS, Android and hybrid apps that supports Ruby among other languages. I’ve chosen it to be the first one to explore and started writing tests for my current real project. Let’s see now whether Appium stack is a good choice for the our purposes.

To start with, we need 3 things to run integration tests with Appium:

  • Appium server
  • application package
  • test script

Appium Installation

There are two ways to install Appium: download packaged app or install it via npm. I tried to install it via npm, but it didn’t work, so I opted for a bundled app and successfully ran couple examples. Then, however, I decided to fix my Appium npm install and managed to run it from console by completely reinstalling node and manually cleaning /usr/local/share/npm.

Make app build

Below is a simple script to create a build and place it inside the desired folder to easily access it from test whenever required.

Don’t forget to make scheme Project shared, otherwise you might get the following error:

Write spec

Here is the template, so we now need to fill in the flows.

Finding elements

Selenium operates with views similar to HTML DOM elements’ and it looks like this:

Guess how to find tableCells? Right:

To get all elements use

In the end, you will need only visible buttons

Looks good so far.

To click on a button named “Done”, you can use:

In the real world, however, there are too many buttons with custom images; so, in this case we have to use accessibilityIdentifier.
Set accessibilityIdentifier to ‘Done’ in the code, and in the tests use

More docs:


Examples:

Tips and tricks

Debugger

I use byebug for Ruby 2.0 as it allows me easily play with UI elements.

Networking

Finally, almost every real application communicates to remote server and this is also something that we want to test. So, as we test our app from outside, we mock webserver outside as well. To run server with mocked api, I use sinatra rb.

Final flow.

I’ve personally found Appium very useful, especially taking into account that it doesn’t require any code inside the application.
On the other hand, it requires a lot of prep work to run tests. So, In order to make start with Appium easier, I’ve created a simple gem : appium-rspec-bootstrap

Hope you’ll find it handy too. Any comments and suggestions are very welcome.

Share
* Railsware is a premium software development consulting company, focused on delivering great web and mobile applications. Learn more about us.

Want to get more of Railsware blog?

RSS FEED

We're always ready to help!

CONTACT US