Android Automation test: Robotium (a) test demo

Source: Internet
Author: User

1. Download Robotium
Open: http://code.google.com/p/robotium/
Download: Robotium-solo-3.4.1.jar (need to rely on this package when writing test cases)
2, need to re-sign the APK, because robotium required to be tested application and test code to have a consistent signature, so we need to download to the APK, through Re-sign.jar to generate the Debug key apk, this re-generated APK will be consistent with the test project signature. After downloading, you need to configure Android_home, which is the location of the Android SDK, and then pull the apk to the icon, it will automatically generate a debug key apk, If you cannot run directly by clicking Re-sign.jar, you need to switch to the directory where the jar file is placed, and CMD executes Java-jar Re-sign.jar generates a new apk in the process will pop up a message box, remember to intercept, because there are two of information we will be in the code to use the installation of the resulting apk. Then connect the test machine (or open the emulator, the emulator must be open to install successfully), and then open the command line adb install xx_debug.apk (the name of the new APK), or double-click the apk file can also be installed
2. Create test Project
1) File-"new-" other-"Android test project, as this is based on the APK testing, select this Project
2) Add Android-junit-report-1.5.8.jar and Robotium-solo-5.6.3.jar these two packages to the project
3) manifest.xml Modification
<?xml version= "1.0" encoding= "Utf-8"?>
<manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
Package= "COM.KAMOCTEST.LOGIN.HWJ"//Package Name
Android:versioncode= "1"
Android:versionname= "1.0" >

<uses-sdk android:minsdkversion= "/>"

<instrumentation
Android:name= "Com.zutubi.android.junitreport.JUnitReportTestRunner"//Import Unit Test report jar
Android:targetpackage= "Com.coolwi.km.user"/>//Tested application package name
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>//Give writable permission

<application
android:icon= "@drawable/ic_launcher"
Android:label= "@string/app_name" >
<uses-library android:name= "Android.test.runner"/>
</application>
</manifest>
4) New test class shsclistactivity inherit ActivityInstrumentationTestCase2, write test code, run test Case Select Run As->androidjunittest
5) Write a test demo
/*
@ Test module: Test Account Management
@ Test Content: The Account Management module in each of the Small module link click Normal No error

*/
Package com.coolwi.km.test;

Import com.robotium.solo.*;
Import Android.test.ActivityInstrumentationTestCase2;


@SuppressWarnings ("Rawtypes")
public class Shsclistactivity extends ActivityInstrumentationTestCase2 {
Private solo solo;

private static final String Launcher_activity_full_classname = "com.coolwi.km.activity.StartActivity";

private static class<?> Launcheractivityclass;
static{
try {
Launcheractivityclass = Class.forName (launcher_activity_full_classname);
} catch (ClassNotFoundException e) {
throw new RuntimeException (e);
}
}

@SuppressWarnings ("Unchecked")
Public shsclistactivity () throws ClassNotFoundException {
Super (Launcheractivityclass);
}

public void SetUp () throws Exception {
Super.setup ();
Solo = new solo (getinstrumentation ());
Getactivity ();
}

@Override
public void TearDown () throws Exception {
Solo.finishopenedactivities ();
Super.teardown ();
}

public void TestRun () {
Take screenshot
Solo.takescreenshot ();
Wait for activity: ' Com.coolwi.km.activity.StartActivity '
Solo.waitforactivity ("StartActivity", 2000);

Wait for activity: ' Com.coolwi.km.activity.LoginActivity '
Asserttrue ("Loginactivity is not found!", solo.waitforactivity ("loginactivity"));
Enter the text: ' 15088132075 '
Solo.clearedittext ((Android.widget.EditText) Solo.getview ("Et_phone"));
Solo.entertext ((Android.widget.EditText) Solo.getview ("Et_phone"), "15088132075");
Click on Empty Text View
Solo.clickonview (Solo.getview ("et_pwd"));
Enter the text: ' 123456ab '
Solo.clearedittext ((Android.widget.EditText) Solo.getview ("Et_pwd"));
Solo.entertext ((Android.widget.EditText) Solo.getview ("Et_pwd"), "123456ab");
Click on Login
Solo.clickonview (Solo.getview ("BT_OK"));
Wait for activity: ' Com.coolwi.km.main.MainActivity '
Asserttrue ("Mainactivity is not found!", solo.waitforactivity ("mainactivity"));
Wait for Dialog
Solo.waitfordialogtoopen (5000);
Set default small timeout to 10377 milliseconds
Timeout.setsmalltimeout (10377);
Click on account Management
Solo.clickonview (Solo.getview ("Radio4"));
Shop Shop Purchase Test
Click on Merchant Mall
Solo.clickonview (Solo.getview ("TV_SHSC"));
Wait for activity: ' Com.coolwi.km.main.account.shopping.SHSCListActivity '
Asserttrue ("Shsclistactivity is not found!", solo.waitforactivity ("shsclistactivity"));
Click on ImageView
Solo.clickonview (Solo.getview ("IV_DDJL"));
Wait for activity: ' Com.coolwi.km.main.account.shopping.SHSCMyOrderActivity '
Asserttrue ("Shscmyorderactivity is not found!", solo.waitforactivity ("shscmyorderactivity"));
Scroll to ImageView
Android.widget.ListView listView0 = (android.widget.ListView) solo.getview (android.widget.ListView.class, 0);
Solo.scrolllisttoline (listView0, 0);
Click on ImageView
Solo.clickonview (Solo.getview ("Iv_back"));
Click on Empty Text View
Solo.clickonview (Solo.getview ("Et_search"));
Enter the text: ' Card mo '
Solo.clearedittext ((Android.widget.EditText) Solo.getview ("Et_search"));
Solo.entertext ((Android.widget.EditText) Solo.getview ("Et_search"), "card Mo");
Take screenshot
Solo.takescreenshot ();
Click on the card mo
Solo.clickonview (Solo.getview ("Et_search"));
Press Search button
Solo.presssoftkeyboardsearchbutton ();
Set default small timeout to 12368 milliseconds
Timeout.setsmalltimeout (12368);
Click on Buy Now
Solo.clickonview (Solo.getview ("Bt_pay"));
Wait for activity: ' Com.coolwi.km.main.account.shopping.SHSCWebActivity '
Asserttrue ("Shscwebactivity is not found!", solo.waitforactivity ("shscwebactivity"));
Click on ImageView
Solo.clickonview (Solo.getview ("Iv_back"));
Take screenshot
Solo.takescreenshot ();
Take screenshot
Solo.takescreenshot ();
Click on ImageView
Solo.clickonview (Solo.getview ("Iv_back"));
/*
Wait for activity: ' Com.coolwi.km.activity.WebAppActivity '
Asserttrue ("Webappactivity is not found!", solo.waitforactivity ("webappactivity")); */
Click on merchant Agreement
Solo.clickonview (Solo.getview ("TV_MDXY"));
Take screenshot
Solo.takescreenshot ();
Wait for activity: ' Com.coolwi.km.activity.WebAppActivity '
Asserttrue ("Webappactivity is not found!", solo.waitforactivity ("webappactivity"));
Click on ImageView
Solo.clickonview (Solo.getview ("Iv_back"));
/*//Click on authentication information
Solo.clickonview (Solo.getview ("tv_rzxx"));
Wait for activity: ' Com.coolwi.km.main.account.ZZRZActivity '
Asserttrue ("Zzrzactivity is not found!", solo.waitforactivity ("zzrzactivity")); */
Click on authentication information
Solo.clickonview (Solo.getview ("tv_rzxx"));
Wait for activity: ' Com.coolwi.km.main.account.ZZRZActivity '
Asserttrue ("Zzrzactivity is not found!", solo.waitforactivity ("zzrzactivity"));
Take screenshot
Solo.takescreenshot ();
Click on ImageView
Solo.clickonview (Solo.getview ("Iv_back"));
Click on system settings
Solo.clickonview (Solo.getview ("Tv_xtsz"));

Take screenshot
Solo.takescreenshot ();
Wait for activity: ' Com.coolwi.km.main.account.XTSZActivity '
Asserttrue ("Xtszactivity is not found!", solo.waitforactivity ("xtszactivity"));
Click on Change Password
Solo.clickonview (Solo.getview ("rela_xgmm"));
Wait for activity: ' Com.coolwi.km.main.account.UpdatePwdActivity '
Asserttrue ("Updatepwdactivity is not found!", solo.waitforactivity ("updatepwdactivity"));
Click on Empty Text View
Solo.clickonview (Solo.getview ("Et_yzm"));
Enter the text: ' 159753 '
Solo.clearedittext ((Android.widget.EditText) Solo.getview ("Et_yzm"));
Solo.entertext ((Android.widget.EditText) Solo.getview ("Et_yzm"), "159753");
Click on Empty Text View
Solo.clickonview (Solo.getview ("et_pwd"));
Enter the text: ' 123456ab '
Solo.clearedittext ((Android.widget.EditText) Solo.getview ("Et_pwd"));
Solo.entertext ((Android.widget.EditText) Solo.getview ("Et_pwd"), "123456ab");
Click on Empty Text View
Solo.clickonview (Solo.getview ("et_confirm_pwd"));
Enter the text: ' 123456ab '
Solo.clearedittext ((Android.widget.EditText) Solo.getview ("Et_confirm_pwd"));
Solo.entertext ((Android.widget.EditText) Solo.getview ("Et_confirm_pwd"), "123456ab");
Click on confirm
Solo.clickonview (Solo.getview ("BT_OK"));
Click on Comment Feedback
Solo.clickonview (Solo.getview ("RELA_YJFK"));
Wait for activity: ' Com.coolwi.km.main.account.FeedBackActivity '
Asserttrue ("Feedbackactivity is not found!", solo.waitforactivity ("feedbackactivity"));
Take screenshot
Solo.takescreenshot ();
/*//Click on Empty Text View
Solo.clickonview (Solo.getview ("et_content")); * *
Click on Empty Text View
Solo.clickonview (Solo.getview ("et_content"));
Enter the text: ' Gyg '
Solo.clearedittext ((Android.widget.EditText) Solo.getview ("Et_content"));
Solo.entertext ((Android.widget.EditText) Solo.getview ("Et_content"), "Gyg");
Click on Submit
Solo.clickonview (Solo.getview ("Bt_submit"));
Click on ImageView
Solo.clickonview (Solo.getview ("Iv_back"));
Click on Use Help
Solo.clickonview (Solo.getview ("Tv_help"));
Wait for activity: ' Com.coolwi.km.activity.WebAppActivity '
Asserttrue ("Webappactivity is not found!", solo.waitforactivity ("webappactivity"));
/*//Wait for activity: ' Com.coolwi.km.activity.WebAppActivity '
Asserttrue ("Webappactivity is not found!", solo.waitforactivity ("webappactivity")); */
Click on ImageView
Solo.clickonview (Solo.getview ("Iv_back"));
Click on account Recharge
Solo.clickonview (Solo.getview ("Tv_zhcz"));
Wait for activity: ' Com.coolwi.km.main.account.ZHCZActivity '
Asserttrue ("Zhczactivity is not found!", solo.waitforactivity ("zhczactivity"));
Click on 100 USD
Solo.clickonview (Solo.getview ("bt1"));
Enter the text: ' 100 '
Solo.clearedittext ((Android.widget.EditText) Solo.getview ("Et_amount"));
Solo.entertext ((Android.widget.EditText) Solo.getview ("Et_amount"), "100");
Click on ImageView
Solo.clickonview (Solo.getview ("IB_CZJL"));
Wait for activity: ' Com.coolwi.km.activity.WebAppActivity '
Asserttrue ("Webappactivity is not found!", solo.waitforactivity ("webappactivity"));
Click on ImageView
Solo.clickonview (Solo.getview ("Iv_back"));
Click on ImageView
Solo.clickonview (Solo.getview ("Iv_back"));
Click on the monthly statement
Solo.clickonview (Solo.getview ("Tv_yjzd"));
Take screenshot
Solo.takescreenshot ();
Wait for activity: ' Com.coolwi.km.main.account.YJZDActivity '
Asserttrue ("Yjzdactivity is not found!", solo.waitforactivity ("yjzdactivity"));

Scroll to ImageView
Android.widget.ListView listView1 = (android.widget.ListView) solo.getview (android.widget.ListView.class, 0);
Solo.scrolllisttoline (listView1, 0);
Click on ImageView
Solo.clickonview (Solo.getview ("Iv_back"));
Click on about card mo
Solo.clickonview (Solo.getview ("tv_about"));
Wait for activity: ' Com.coolwi.km.main.account.AboutActivity '
Asserttrue ("Aboutactivity is not found!", solo.waitforactivity ("aboutactivity"));
Click on new version detect current version number: 2.5.16-T is the latest edition
Solo.clickonview (Solo.getview ("Re_check"));
Click on Contact Us
Solo.clickonview (Solo.getview ("RE_LXWM"));
Wait for activity: ' Com.coolwi.km.main.account.RZTSActivity '
Asserttrue ("Rztsactivity is not found!", solo.waitforactivity ("rztsactivity"));
Click on ImageView
Solo.clickonview (Solo.getview ("Iv_back"));
Click on share QR code to friends tap QR code to share to friends
Solo.clickonview (Solo.getview ("Re_code"));
Wait for activity: ' Com.mob.tools.MobUIShell '
Asserttrue ("Mobuishell is not found!", solo.waitforactivity ("Mobuishell"));
Click on Empty Text View
Solo.clickonview (Solo.getview (android.widget.TextView.class, 0));
Click on ImageView
Solo.clickonview (Solo.getview ("Iv_back"));
Click on system settings
Solo.clickonview (Solo.getview ("Tv_xtsz"));
Wait for activity: ' Com.coolwi.km.main.account.XTSZActivity '
Asserttrue ("Xtszactivity is not found!", solo.waitforactivity ("xtszactivity"));
Click on to log out
Solo.clickonview (Solo.getview ("rela_tcdl"));
Wait for Dialog
Solo.waitfordialogtoopen (5000);
Click on OK
Solo.clickonview (Solo.getview ("bt_confirm"));
Wait for activity: ' Com.coolwi.km.activity.LoginActivity '
Asserttrue ("Loginactivity is not found!", solo.waitforactivity ("loginactivity"));
}
}

Android Automation test: Robotium (a) test demo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.