What is Calabash?
Calabash is an automated testing framework that can test Android and IOS native and hybrid apps.
It has:
Calabash-android
Calabash-ios
Home:? http://calabash.sh
Calabash-android Introduction
Calabash-android is an android-enabled UI Automation testing framework that uses the cucumber framework, which communicates with the emulator and the test apk installed on the real machine via HTTP and JSON, and tests the APK call Robotium method to enter Line UI Automation test, support WebView operation.
Calabash-android Frame composition
features--here feature is cucumber feature, used to describe the user stories.
Step Definitions--calabash Android has already defined some common step in advance. You can define more complex steps according to your needs.
Before Your app--test, you do not have to modify your app. (There's actually a problem here, we'll talk about it later.) )
Instrumentation Test server--This is an application that will be installed on the device when the test is run. This app is based on the ActivityInstrumentationTestCase2 in the Android SDK. It is part of the Calabash Android framework. Robotium is integrated in this application.
Calabash-android Environment Construction
Ruby Environment
Rvm
Rbenv
rubyinstaller.org for Windows
Android Development environment
Java
Android SDK
Ant
Specify the JAVA environment variable, the Android SDK environment variable (android_home), and Ant to join the PATH.
Installing Calabash-android
Gem Install Calabash-android
sudo gem install calabash-android # If permissions are not enough for this.
If you have any questions, please refer to:? Https://github.com/calabash/calabash-android/blob/master/documentation/installation.md
Create a calabash-android skeleton
Calabash-android Gen
The following directory structure is generated:
?? Calabash? Tree
.
Features
|_support
| |_app_installation_hooks.rb
| |_app_life_cycle_hooks.rb
| |_env.rb
|_step_definitions
| |_calabash_steps.rb
|_my_first.feature
Write Test Cases
Like the general cucumber test, we just add test cases to the feature file. For example, we test contactmanager.apk (Android SDK sample inside, Appium also use this apk).
We want to achieve,
Open this app
Click the ADD contact button
Add Contact Name for Hello
Add Contact Phone for 13817861875
Add Contact Email for? [Email protected]
Save
So our feature should be like this:
Feature:login Feature? Scenario:as a valid user I can log into my app??? When I Press "ADD Contact"
Then I see "Target account"
Then I enter the "Hello" into input field number 1??? Then I enter ' 13817861875 ' into input field number 2??? Then I enter "[e-mail protected]" into input field number 3??? When I Press "Save"
Then I wait for 1 second??? Then I toggle CheckBox Number 1??? Then I see "Hello"
Here input field number is for the Contactadder Activity in the Enter box. I'm actually not very friendly now, but the better way is to wrap it up again, transparent to the DSL writer. Like what:
When I enter "Hello" as "contact Name"
Step_definition
When (/^i enter "([^"]*) "as" ([^ "]*)" $/) does | Text, Target |
index = case Target
When "Contact Name": 1
...
End
Steps%{
Then I enter #{text} into input field number #{index}
}end
This makes feature readability a bit stronger.
Run feature
Before running, we have to deal with the APK, or we will encounter some problems.
App did not start (RuntimeError)
Because Calabash-android's client and test server need to communicate, add permissions in Androidmanifest.xml:
<uses-permission android:name= "Android.permission.INTERNET"/>
Contactermanager the problem with the code itself
Since Contacermanager run time, you need to have an account, if there is no account Save the time will be wrong. For ease of operation, we want to modify the next.
Source code address in the $ANDROID _home/samples/android-19/legacy/contactmanager, everyone to find their own.
Need to modify the Com.example.android.contactmanager.ContactAdder class inside the Createcontactentry method, we need to judge the Mselectedaccount, modify the place as follows:
Prepare Contact Creation Request
//
Note:we use rawcontacts Because this data must is associated with a particular account.
//?????? The system would aggregate this with any other data for this contact and create a
//?????? Coresponding entry in the Contactscontract.contacts provider for us.
arraylist<contentprovideroperation> Ops = new arraylist<contentprovideroperation> ();
if (mselectedaccount! = null) {
Ops.add (Contentprovideroperation.newinsert (ContactsContract.RawContacts.CONTENT_URI)
. Withvalue (ContactsContract.RawContacts.ACCOUNT_TYPE, Mselectedaccount.gettype ())
. Withvalue (ContactsContract.RawContacts.ACCOUNT_NAME, Mselectedaccount.getname ())
. build ());
} else {
Ops.add (Contentprovideroperation.newinsert (ContactsContract.RawContacts.CONTENT_URI)
. Withvalue (ContactsContract.RawContacts.ACCOUNT_TYPE, NULL)
. Withvalue (ContactsContract.RawContacts.ACCOUNT_NAME, NULL)
. build ());
}....
if (mselectedaccount! = null) {
Ask the contact provider to create a new contact
LOG.I (TAG, "Selected account:" + mselectedaccount.getname () + "(" +
Mselectedaccount.gettype () + ")");
} else {
LOG.I (TAG, "No selected account");
}
After the code has been modified, export the APK file.
Running is simple:
Calabash-android Run <apk>
If you encounter signature problems, use: Calabash-android resign apk.
You can see what I'm running:
?? Calabash? Calabash-android Run contactmanager.apk
Feature:login Feature
Scenario:as a valid user I can log into my app # features/my_first.feature:33135 kb/s (556639 b Ytes in 0.173s) 3315 kb/s (26234 bytes in 0.007s)
When I Press "ADD Contact" # Calabash-android-0.4.21/lib/calabash-andr Oid/steps/press_button_steps.rb:17
Then I see "Target account" # Calabash-android-0.4.21/lib/calabash-and Roid/steps/assert_steps.rb:5
Then I enter the "Hello" into input field number 1?????????????? # Calabash-android-0.4.21/lib/calabash-android/steps/enter_text_steps.rb:5
Then I enter ' 13817861875 ' into input field number 2 # calabash-android-0.4.21/lib/calabash-android/steps/ Enter_text_steps.rb:5
Then I enter "[e-mail protected]" into input field number 3 # calabash-android-0.4.21/lib/calabash-android/steps/enter_t Ext_steps.rb:5
When I Press "Save" # calabash-android-0.4.21/lib/calabash- Android/steps/press_button_steps.rb:17
Then I wait for 1 second # calabash-android-0.4.21/lib/calabash- Android/steps/progress_steps.rb:18
Then I toggle CheckBox Number 1 # Calabash-android-0.4.21/lib/calabash-androi D/steps/check_box_steps.rb:1
Then I see "Hello" # Calabash-android-0.4.21/lib/calab Ash-android/steps/assert_steps.rb:51 Scenario (1 passed) 9 Steps (9 passed) 0m28.304s
All pass!
You see that GIF is failed because it runs on the emulator. And the above all through I run on the Hisense mobile phone. Environment is different, slightly different.
Summarize
This article is a brief introduction to Calabash-android, to do is to initiate the work. The mobile testing framework is not a Appium, and Testerhome hopes that the topics of other frameworks will also heat up. Watch and learn!
This article was selected from: http://www.spasvo.com/news/html/20141218171136.html
Mobile app test Framework-calabash Android Introduction