1. The test class must inherit activityinstrumentationtestcase2 <Test Class Name>
2. Super ("package name", test class name. Class) in the constructor );
3. In the setup method, solo = new solo (getinstrumentation (), getactivity ());
4. In the teardown Method
Try {
Solo. Finalize ();
} Catch (throwable e ){
E. printstacktrace ();
}
Getactivity (). Finish ();
Super. teardown ();
5. Click Automation
Clickonmenuitem ("menu name ")
Clickinlist (number of rows in the list) Note: Starting from 1
Clickontext ("(? I ).*? Test. * ") Click the text
Clicklongontext ("NOTE 2") Click text for a long time
Clickonbutton ("button name") click the button
6. Input Automation
Entertext (No., "input content ")
7. Screen Control
Setactivityorientation (Solo. landscape or solo. Portrait) controls horizontal or vertical display of the screen
8. Jump
Goback () imitates the Hard Return key
Gobacktoactivity ("activity name") jumps to the specified activity
9. Judgment
Determines whether the current activity is specified.
Assertcurrentactivity ("test prompt", "activity name ");
Search whether the specified text exists
Searchtext ("Search Text") or searchtext ("(? I ).*? Note 1 test ") followed by a regular expression
10. Obtain
(Edittext) Solo. getview (R. Id. edittext01 );
(Textview) Solo. getview (R. Id. textview01 );
Arraylist currenttextviews = solo. getcurrenttextviews (outputfield );
11. Pay attention to the following two points when you click the button for testing:
(1) During a real machine test, I found that I couldn't find the button after clicking the button in the screen saver test, that is, click NO. It seems that the test robot is really simulated.
(2) there is a delay after you click the button. You need to wait for a period of time for future tests. Otherwise, an error will be reported after you enter the following test. The processing example is as follows:
// Click the button to enable the Service
Solo. clickonbutton (butstartservice );
// Determine whether the specified service exists
Long start = system. currenttimemillis ();
While (! Isservicestarted (service_package_name )){
Try {
Thread. Sleep (1000 );
} Catch (interruptedexception e ){
}
If (system. currenttimemillis ()-Start)> timeout ){
Break;
}
}
Asserttrue ("no service is enabled", isservicestarted (service_package_name ));
transfer to a basic procedure for using robotium