To use robotium, follow these steps:

Source: Internet
Author: User

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

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.