Automated E2E mobile testing involving intercommunication scenarios.
Kraken is an open source automated android E2E testing tool that supports and validates scenarios that involve the inter-communication between two or more users. It works in a Black Box manner meaning that it is not required to have access to the source code of the application but instead it can be run with the APK (Android package file format). Kraken uses signaling for coordinating the communication between the devices using a file based protocol.
Kraken uses calabash-android for running automated E2E tests in each device or emulator and cucumber for running your feature files written with Gherkin sintax.
Kraken requires Ruby 2.20 or higher but we recommend using ~2.3 version. We use calabash-android as runner, you can check their prerequisites at this link. Installing and managing a Gem is done through the gem command. To install Kraken’s gem run the following command.
$ gem install kraken-mobile
Signaling is a protocol used for the communication of two or more devices running in parallel. It is based in the idea that each emulator or real device has a communication channel where he can receive signals sent from other devices which contain information or actions that are supposed to be executed. This type of protocol is commonly used in automated mobile E2E testing tools that validate scenarios involving the inter-communication and collaboration of two or more applications.
First you need to generate the cucumber feature skeleton where your tests are going to be saved. To achieve this you should run kraken-mobile gen
. It will create the skeleton in your current folder like this:
features
|_support
| |_app_installation_hooks.rb
| |_app_life_cycle_hooks.rb
| |_env.rb
|_step_definitions
| |_kraken_steps.rb
|_my_first.feature
The features goes in the features foler and should have the “.feature” extension. You can start out by looking at features/my_first.feature
. You should also check calabash predefined steps.
In Kraken each feature is a test and each scenario within a feature is a test case that is run in a device. Each device is identified as an user and numbered from 1 to N. Ex: @user1, @user2, @user3. To check what is the number of a given device you should run kraken-mobile devices
.
List of devices attached
user1 - emulator-5554 - Android_SDK_built_for_x86
user2 - emulator-5556 - Android_SDK_built_for_x86
After identifying what number each device has, you can write your test case giving each scenario the tag of a given device like so:
Feature: Example feature
@user1
Scenario: As a first user I say hi to a second user
Given I wait
Then I send a signal to user 2 containing "hi"
@user2
Scenario: As a second user I wait for user 1 to say hi
Given I wait for a signal containing "hi"
Then I wait
Kraken offers two main steps to help synchronizing your devices.
To wait for a signal coming from another device for 10 seconds that is Kraken default timeout use the following step.
Then /^I wait for a signal containing "([^\"]*)"$/
To wait for a signal coming from another device for an specified number of seconds use the following step
Then /^I wait for a signal containing "( [^\"]*)" for (\d+) seconds$/
To send a signal to another specified device use the following step
Then /^I send a signal to user (\d+) containing "([^\"]*)"$/
Kraken internal implementation of the signaling steps use the following functions.
readSignal(channel, content, timeout)
Waits for a signal with the specified content in the channel passed by parameter. This functions waits for the specified number of seconds in the timeout parameter before throwing an exception.
Note: The channel parameter has to be the number of a device such as @user1, @user2, @userN
writeSignal(channel, content)
Writes content to a channel passed by parameter.
Note: The channel parameter has to be the number of a device such as @user1, @user2, @userN
To run your test:
$ kraken-mobile run <apk>
Kraken with the help of Calabash-Android will install an instrumentation along with your app and will start your tests in all devices connected (Check Kraken Settings section in order to learn how to specify in what devices your tests should be run).
Kraken uses kraken_mobile_settings.json to specify in what devices the tests should be run.
The following command will show you the available connected devices or emulators and let you choose which ones you want to use.
$ kraken-mobile setup
$ kraken-mobile run <apk> --configuration=<kraken_mobile_settings_path>
Kraken uses properties files to store sensitive data such as passwords or api keys that should be used in your test cases.
The properties files should be a manually created JSON file with the following structure.
{
"@user1": {
"PASSWORD": "test"
},
"@user2": {
"PASSWORD": "test2"
}
}
You can use the specified properties using the following sintax.
@user1
Scenario: As a kjkhdkjds
Given I wait
Then I see the text "<PASSWORD>"
kraken-mobile run <apk> --properties=<kraken_mobile_properties_path>
Kraken offers a Fake string generator thanks to the Ruby gem Faker, the list of supported faker types are listed as follows:
Kraken keeps a record of every Fake string generated, thats why each string will have an id associated. To generate a Faker string you need to follow the structure “$FAKERNAME_ID”.
@user1
Scenario: As a user
Given I wait
Then I enter text "$name_1" into field with id "view"
As mentioned before, Kraken keeps record of every string generated with an id given to each string, this gives you the possibility of reusing this string later in your scenario. To reuse a string you can you need to append a $ character to the fake string as follows:
@user1
Scenario: As a user
Given I wait
Then I enter text "$name_1" into field with id "view"
Then I press "add_button"
Then I should see "$$name_1"
Kraken offers the possibility of generating random GUI events by using Android ADB monkey as well as its own implementation based in the idea of sending and reading random signals.
To execute ADB monkey Kraken offers the following command specifying the number of events to be executed:
Then I start a monkey with (\d+) events
Kraken extended the ADB monkey behavior by sending and writing random signals as well as executing GUI events only in buttons and clickable views or inputs by offering the following command:
Then I start kraken monkey with (\d+) events
Kraken makes it possible to save the XML presented by the current view in a specific device, this is convenient to identify view ids, asserting the correct XML is presented after an action has being completed or running static analyzing tools.
To save the snapshot of the current view, Kraken offers the following step specifying where the file is going to be saved:
Then I save device snapshot in file with path "([^\"]*)"
Application | Video | Feature File | Steps Definition | Properties file | Settings File | Report Link |
---|---|---|---|---|---|---|
Infinite Words | video | .feature | — | — | — | report |
QuizUp | video | .feature | stepsDef | — | — | report |
Spotify/Shazam | video | .feature | stepsDef | .json | .json | report |
Spunky | video | .feature | stepsDef | — | — | report |
Picap | video | .feature | stepsDef | .json | — | report |
AskFM | video | .feature | stepsDef | — | — | report |
Stick Men Fight | video | .feature | — | — | — | report |
Tic Tac Toe | video | .feature | stepsDef | — | — | report |
Tumblr | video | .feature | stepsDef | .json | — | report |
F3 | video | .feature | stepsDef | .json | — | report |
Hosted on GitHub Pages - Theme by orderedlist