APK-based Robotium login Renren and hair status

Source: Internet
Author: User
Tags testng

Building a Robotium environment is basically downloading and installing the JDK and configuring environment variables, downloading and opening eclipse, downloading and installing the Android SDK tools and configuring environment variables, downloading and installing the ADT plugin, creating and opening Android Virtual Device, Download, apk re-sign and install to the device, manually open Renren app no problem after the environment is ready. (I study robotium when bought Zhiwei yang "mobile phone test Robotium actual combat course", I also summed up a study notes, considering the author is not easy I do not upload, this book is very good. )

Some common CMD commands to view the status of the device and the path to the JDK:

When everyone is well, it's like this in device:

Write two Tests, respectively, to achieve login Renren and hair Status:

 Packagecom.renren.test;ImportOrg.testng.annotations.AfterMethod;ImportOrg.testng.annotations.BeforeMethod;ImportCom.robotium.solo.Solo;ImportAndroid.test.ActivityInstrumentationTestCase2;ImportAndroid.util.Log;ImportAndroid.view.View;ImportAndroid.widget.EditText; @SuppressWarnings ("Rawtypes") Public classRenrentestextendsActivityInstrumentationTestCase2 {//The activity name after re-signed.    Private Static FinalString launcher_activity_full_classname = "Com.renren.mobile.android.ui.WelcomeScreen"; Private StaticClass Launcheractivityclass; PrivateSolo solo; Private Static FinalString TAG = "Myresult"; //Initiate.    Static {        Try{Launcheractivityclass=Class.forName (launcher_activity_full_classname); } Catch(Exception ex) {Throw NewRuntimeException (ex); }} @SuppressWarnings ("Unchecked")     PublicRenrentest ()throwsClassNotFoundException {Super(Launcheractivityclass); } @BeforeMethodprotected voidSetUp ()throwsException {solo=NewSolo (Getinstrumentation (), getactivity ()); }     Public voidTestcanlogin ()throwsinterruptedexception {Booleanresult = waitfortextunless ("Login", "Photo"); if(Result = =true) {            if(Solo.searchtext ("Login") {Solo.clickonview (Solo.getview ("Com.renren.mobile.android:id/welcome_hot_spot_login")); } waitfortext ("Please enter user name"); if(Solo.searchtext ("Please enter user name") {EditText Usrnametext=(EditText) solo. GetView ("Com.renren.mobile.android:id/welcome_hot_spot_account_layout"); String UserName= "User Name";                Solo.entertext (Usrnametext, userName); EditText Pwdtext=(EditText) solo. GetView ("Com.renren.mobile.android:id/welcome_hot_spot_password_edit"); String pwd= "Password";                Solo.entertext (Pwdtext, PWD); //Click the login button.Solo.clickonview (Solo.getview ("Com.renren.mobile.android:id/welcome_hot_spot_login_button")); } waitfortext (Photos); Thread.Sleep (3000); LOG.I (TAG,"Logged in"); } Else{log.i (TAG,"No login Required"); }    }     Public voidTestsendinfo ()throwsinterruptedexception {waitfortext (Photos); String Sendbuttonid= "Com.renren.mobile.android:id/tab_item_publisher"; View Sendbutton=Solo.getview (Sendbuttonid);        Solo.clicklongonview (Sendbutton); Waitfortext ("Hair Status"); Try{String Inputeditorid= "Com.renren.mobile.android:id/input_editor"; EditText EditText=(EditText) Solo.getview (Inputeditorid); String message= "Android test!";            Solo.entertext (editText, message); Solo.clickonbutton (Published);            Waitfortext (message); Thread.Sleep (3000); } Catch(Exception ex) {System.out.println (ex); }    }    Private BooleanWaitfortextunless (String string, String string2)throwsinterruptedexception {BooleanSignal =true;  while(!solo.searchtext (String) &&signal) {            if(Solo.searchtext (string2)) {signal=false; returnsignal; } Else{Thread.Sleep (1000); }        }        returnsignal; }        Private voidWaitfortext (String text)throwsinterruptedexception { while(!solo.searchtext (text)) {Thread.Sleep (1000); }} @AfterMethod Public voidTearDown ()throwsException {solo.finishopenedactivities (); }}

1, suppresswarnings means to suppress the warning, in detail there are several ways to use the Internet to search;

2. Create a solo class to interact with the elements on the device's current app page;

3, declare a tag, let the log class in the Logcat output some of the specified information, convenient for us in the logcat to find and judge some of the status of the Test experience;

4, Robotium test method name to start with test, testxxx form, run to select the Android JUnit test run;

5. Setup and teardown are the methods required to load and destroy applications for fixed test classes;

5. Write two wait methods to wait for elements on the page, and not to wait for the target element if an exception element occurs.

APK-based Robotium login Renren and hair status

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.