Get View by ID in Robotium and do the corresponding action

Source: Internet
Author: User

Several representations of ID in Robotium 1) string form: For example Id/btn_example, the source of the layout in some of the hierachy see is this. 2) Digital form: For example 0x7f0700d, open R.java inside reflects the string form and int form correspondence relation. White box test, directly use the form of r.id to call the View View =solo.getview (r.id.btn_example);//Get Viewsolo.clickonview (view);//Click on the Black box test, r.id Invisible Activity Act =solo.getcurrentactivity ();//Get Activityint ID =act.getresources (). Getidentifier ("Btn_example", "id" , Act.getpackagename ());//Get int's Idview View =act.findviewbyid (ID) by string ID;//Get Viewsolo.clickonview (view);// Click on the method can be encapsulated, the method is as follows: Private Boolean Clickbyid (String id) throws exception{     if (id== "") {          return false;     }  try{        Activity Act =solo.ge Tcurrentactivity ();//Gets the current activity        int id = Act.getresource (). Getidentifier (ID, "id", Solo.getcurrentactivity (). Getpackagename ());//Get id       view view = Solo.getview (ID);//Get View       Solo.clickonview (view);//click view    }catch (exception ex) {         LOG.E ();   }  return true;}

Get View by ID in Robotium and do the appropriate action

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.