Android app automation using Calabash
Tools required:
1.
Android SDK
2.
Ruby 1.9.3 +
3.
Apache ant
http://www.gtlib.gatech.edu/pub/apache//ant/binaries/apache-ant-1.9.4-bin.zip
4.
JDK
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
5.
USB Driver of mobile connectivity
After installing above all tools follow the steps
below.
Steps:
1.
Add following paths to environment variable
JAVA_HOME: C:\Program Files\Java\jdk1.7.0_51\bin
ANDROID_HOME (till sdk): E:\Automation\adt-bundle-windows-x86_64-20140321\sdk
Path variables:
E:\Automation\adt-bundle-windows-x86_64-20140321\sdk\tools;
C:\ProgramFiles\Java\jdk1.7.0_51\bin;
E:\Automation\adt-bundle-windows-x86_64-20140321\sdk\platform-tools;
E:\Automation\adt-bundle-windows-x86_64-20140321\sdk\tools;
C:\Ruby200\bin;
C:\Program Files\Java\jre7\bin;
E:\Automation\apache-ant-1.9.4-bin\apache-ant-1.9.4\bin
2.
Open command prompt after setting all these
variables
3.
Run command:
gem
calabash-android : this will install calabash
4.
Create a workspace for the project:
E:\Automation\Calabash
5.
Navigate to above path in CMD: ‘cd
E:\Automation\Calabash’
6.
Run command
calabash-android
gen
It will create a Cucumber skeleton in the
current folder like this:
features
|_support
| |_app_installation_hooks.rb
| |_app_life_cycle_hooks.rb
| |_env.rb
| |_hooks.rb
|_step_definitions
| |_calabash_steps.rb
|_my_first.feature
In this skeleton you find all the
predefined steps that comes with calabash. Try to take a look my_first.feature
and change it to fit your app.
7.
Paste apk file for your app, keystore file at
location workspace location in parallel to feature folder i.e ‘E:\Automation\Calabash’
8.
Resign your apk using command: ‘calabash-android resign <apk_name>’
9.
Connect mobile device to the laptop
10.
Run apk file using command: ‘calabash-android run <apk_name>’
and verify that app is running on mobile device
11.
Terminate Running app using Ctrl+C
12.
To find elements in your app Run command: “calabash-android console <apk name>”
13.
If App is closed in device then launch it
manually.
Fire following command to find elements.
query(“*”) : Will give list of all elements
available in current screen of app.
e.g.
query(“Button”): Find all Buttons
query(“button text: ‘User name’”)
query(“button index: 4”)
[ 1] {
"id" =>
nil,
"enabled" =>
true,
"contentDescription" =>
nil,
"text" =>
"Localization (L10n) locator test",
"tag" =>
nil,
"description" =>
"android.widget.TextView@417cf028",
"class" =>
"android.widget.TextView",
"rect" => {
"center_y" => 137,
"center_x" => 139,
"height" => 29,
"y" => 123,
"width" => 278,
"x" => 0
}
},
[ 2] {
"id" =>
"buttonTest",
"enabled" =>
true,
"contentDescription" =>
"buttonTestCD",
"text" =>
"EN Button",
"tag" =>
nil,
"description" =>
"android.widget.Button@417cf868",
"class" =>
"android.widget.Button",
"rect" => {
"center_y" => 141,
"center_x" => 341,
"height" => 72,
"y" => 105,
"width" => 127,
"x" => 278
}
},
[3] {
"id" =>
"imageView",
"enabled" =>
true,
"contentDescription" =>
"imageViewCD",
"class" =>
"android.widget.LinearLayout",
"rect" => {
"center_y" => 222,
"center_x" => 240,
"height" => 91,
"y" => 177,
"width" => 480,
"x" => 0
},
"tag" => nil,
"description" =>
"android.widget.LinearLayout@417d04e8"
},
[4] {
"id" =>
"buttonStartWebview",
"enabled" =>
true,
"contentDescription" =>
"buttonStartWebviewCD",
"class" =>
"android.widget.ImageButton",
"rect" => {
"center_y" => 222,
"center_x" => 120,
"height" => 91,
"y" => 177,
"width" => 240,
"x" => 0
},
"tag" =>
nil,
"description" =>
"android.widget.ImageButton@417d09c0"
},
[5] {
"id" =>
"startUserRegistration",
"enabled" =>
true,
"contentDescription" =>
"startUserRegistrationCD",
"class" =>
"android.widget.ImageButton",
"rect" => {
"center_y" => 222,
"center_x" => 360,
"height" => 91,
"y" => 177,
"width" => 240,
"x" => 240
},
"tag" =>
nil,
"description" =>
"android.widget.ImageButton@417d5510"
},
[6] {
"id" =>
"my_text_field",
"enabled" =>
true,
"contentDescription" =>
"my_text_fieldCD",
"text" =>
"",
"tag" =>
nil,
"description" =>
"android.widget.EditText@417da1e8",
"class" =>
"android.widget.EditText",
"rect" => {
"center_y" => 304,
"center_x" => 240,
"height" => 72,
"y" => 268,
"width" => 480,
"x" => 0
}
},
[7] {
"id" =>
"lastElementRow",
"enabled" =>
true,
"contentDescription" =>
"imageViewCD",
"class" =>
"android.widget.LinearLayout",
"rect" => {
"center_y" => 376,
"center_x" => 240,
"height" => 72,
"y" => 340,
"width" => 480,
"x" => 0
},
"tag" =>
nil,
"description" =>
"android.widget.LinearLayout@417db428"
},
[8] {
"id" =>
"waitingButtonTest",
"enabled" =>
true,
"contentDescription" =>
"waitingButtonTestCD",
"text" =>
"Show Progress Bar for a while",
"tag" =>
nil,
"description" =>
"android.widget.Button@417db738",
"class" =>
"android.widget.Button",
"rect" => {
"center_y" => 376,
"center_x" => 151,
"height" => 72,
"y" => 340,
"width" => 302,
"x" => 0
}
},
[9] {
"id" =>
"input_adds_check_box",
"enabled" =>
true,
"contentDescription" =>
nil,
"text" =>
"I accept adds",
"tag" =>
nil,
"description" => "android.widget.CheckBox@417dc530",
"class" =>
"android.widget.CheckBox",
"rect" => {
"center_y" => 385,
"center_x" => 391,
"height" => 72,
"y" => 349,
"width" =>
178,
"x" => 302
},
"checked" =>
true
},
[10] {
"id" =>
"visibleTestArea",
"enabled" =>
true,
"contentDescription" =>
"visibleTestAreaCD",
"class" =>
"android.widget.LinearLayout",
"rect" => {
"center_y" => 448,
"center_x" => 240,
"height" => 72,
"y" => 412,
"width" => 480,
"x" => 0
},
"tag" =>
nil,
"description" =>
"android.widget.LinearLayout@417dd678"
},
For More help please refer following links:
14.
Start creating feature file in the path
Workspace\features folder ,i.e ‘E:\Automation\Calabash\features’
References:
Comments
Post a Comment