Mobile Software Test Automation: Sample Android Project

Sample Project

In order to move through the tutorial as quickly as possible so you can get coding, I am first going to walk through android, and then go back and discuss iPhone.  This is because there is a lot more we have to do in order to set up testing on iOS devices, which is not needed with android.

For those of you learning for the first time, you can follow along with me using this calculator app that I downloaded from the Play Store.  The app creator is Code Monkey, who developed this app to help others learn to develop android apps.  The source code for this project is here if you are interested, but it is not needed for this tutorial. You are welcome to use your own app, I am only using this in hopes that you can then apply what you are learning to your project.  You will need to download this app if you want to follow along with the sample project.

So we then need to pull this apk off the device.  To do this, first connect an android device to your machine, or launch an emulator.  Then, launch the terminal and type:

$ adb devices

You should see a list of devices attached, with an alpha-numeric code if its a physical device, or the named emulator device.  If not, you will have to add a path to your .bash_profile that points to the platform_tools folder that should be found at ~/Library/Android/sdk/platform-tools.  This folder contains the adb shell command you need.  If you need more help adding this to your .bash_profile, I did a write up on this here.

Next, in the terminal, type:

$ adb shell pm list packages

This will return a list of all the packages on your device.  Find the package for the downloaded calculator.  The package name is listed in the play store URL for the app, which is faster, and knowing it will definitely help you sort through the list of packages on your phone.  But for this app, the package is com.dalviksoft.calculator.  The next step is to find the location of this package.  To do this, in the terminal, type:

$ adb shell pm path com.dalviksoft.calculator

This will return the package location.  For mine, it returned as:  /data/app/com.dalviksoft.calculator-1/base.apk.  Now, we are going to pull this package off the device.  To do so, in the terminal, type:

$ adb pull /data/app/com.dalviksoft.calculator-1/base.apk

Now, the Calculator apk should be on your machine, in whatever folder your terminal was pointing to when you did the previous command.  It will be named "base.apk", and I simply renamed it "Calculator.apk".  If you were not in your project folder, you should now move this apk into your project folder, outside of the features folder.  For organization purposes, I have a project folder in which the features folder lives, as well as the Gemfile and Gemfile.lock documents.  In that same project folder, lives a folder named: "android-apks", and that is where the apk lives.

That should be everything you need to get started.  So at this point, your project folder should look like this:

Screen Shot 2015-11-25 at 4.21.11 PM.png

I have the ios folder created, but nothing is in it right now, since we are starting with android.  Next we will start writing the acceptance tests which are our .feature files, and we will also have a more in-depth discussion on Gherkin.