Android automated testing experience sharing UiObejct. getFromParent () Usage

Source: Internet
Author: User

1.UiObejct. getFromParent () usage: Find the desired sub-object from the parent object of the current object. The sub-object and the current object should be at the same level.

As shown in: Max inactivity before lock is a known condition, and 4 minutes is what I want to obtain dynamically. What should we do?

Let's take a look at the structure: TableLayout (curent index is 2)-TableRow (has several indexes)-TextView (has 2 indexes ).

1.First, obtain the object whose TableLayout index is 2.
2.Traverse the TableRow in TableLayout and obtain the text of TextView (0) in TableRow (I ).
3.When the text content of TextView (1) is "Max inactivity before lock", you can determine the TableRow we want. (In fact, it is to find the corresponding index)
4.Then we use the getFromParent () method of the current object to find the text of TextView (1), so that we can get the desired value.

Copy codeThe Code is as follows: // The following two steps are used to obtain the number of TableRow under TableLayout.
UiObject allPasswordPolicies = new UiObject (new UiSelector (). className ("android. widget. TableLayout"). index (2 ));
Int pwdcount = allPasswordPolicies. getChildCount ();
// Traverse each TableRow
For (int I = 0; I <pwdcount; I ++ ){
UiObject passcodePolicyName = allPasswordPolicies. getChild (new UiSelector (). className ("android. widget. tableRow "). index (I ). childSelector (new UiSelector (). className ("android. widget. textView "). index (0 )));

// Find the object whose TextView value is 0 in TableRow is equal to "Max inactivity before lock"
If (passcodePolicyName. getText (). contains ("Max inactivity before lock ")){

// Use the getFromParent () and getText () methods to obtain the text value of the object whose index is 1 at the same level as the current object. PasscodePolicyName. getFromParent is equivalent to TableRow (1) object.
String actualValue = passcodePolicyName. getFromParent (new UiSelector (). className ("android. widget. TextView"). index (1). getText ();
If (actualValue. equals (expectedValue )){
System. out. println (policyName + "check: Pass .");
} Else {
System. out. println (policyName + "check: Failed .");
}
}
}

Related Article

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.