Appium Concise Tutorial (10)--Control positioning basics

Source: Internet
Author: User
Tags xpath appium

In a narrow sense, automated testing at the UI level is the process of letting machines take the place of people to point to.

But the machine goes to something (point above or to the left), how to point (the long press or the touch), these things must be written by the code is clearly indicated by the author.

Control positioning is what solves the problem of machine points.

Generally speaking, we can tell the machine: go to the login button .

The machine is stupid, it doesn't know what the Landing button is. Because the login button is a natural language description.

If you let a person go to the landing button, then he actually has to go through a series of brain repair in order to do this thing.

The process of this brain repair is restored as follows:

This must be a button.

This button must be on the application under test.

This button probably has a text message on the landing .

Well, there really is one, then point it.

This is a simple process of human exploratory testing. In general, if the information you give is not sufficient, humans can still understand your description through a series of exploratory thinking. This is a question of psychology that does not begin to explain.

But the machine is not human, if you give the description is not accurate, the machine will not be spontaneous exploration and brain repair.

So control positioning is precisely the process of describing the characteristics of a control and telling the machine.

The copyright of this article is owned by ethanol, welcome reprint, but please specify the author and source, strictly prohibited for any commercial use

The feature of a control is the property of the control, which can be obtained through the uiautomatorviewer in the previous lecture.

In Appium's positioning world, the following methods can be used for us. In other words, we describe and locate the control features according to Webdriver and Appium's DSL (self-searching and understanding) in a few agreed-upon ways.

A method that inherits from the Webdriver, which means that the control can be positioned by these 3 features

    • Find by "class" (i.e, UI component Type,andorid can be Android.widget.TextView)
    • Find by "XPath" (i.e), an abstract representation of a path to an element, with certain constraints, due to the incomplete XPath library of Appium, This is not very recommended)
    • Find by "id" (The resource ID of the control on Android)

The method defined in the mobile JSON Wire Protocol protocol, which is more suitable for the positioning of the control on a moving device

    • -ios uiautomation: A string corresponding to a recursive element search using the UIAutomation library (ios-only)
    • -android uiautomator: A string corresponding to a recursive element search using the Uiautomator Api (android-only)
    • accessibility id: A string corresponding to a recursive element search using the Id/name, the native accessibility options utilize.

The Appium client has encapsulated the methods defined in the mobile JSON wire protocol to make it easier to call.

Ruby article
' Animation '  'Animation' new Uiselector (). Clickable (true)  '  'new Uiselector (). Clickable (true)'

Of course, you can also use the native Webdriver method

' resource_id '

In addition, Ruby Lib offers some very handy ways to navigate the controls, write them, and read them well.

    • Text (value_or_index): Find The first TextView that contains value or by index. If int then the TextView at that index is returned.
    • Button (Value_or_index): Find The first button that contains value or by index. If int then the button at that index is returned

See here for more details

Python article
El = Self.driver.find_element_by_android_uiautomator ('new Uiselector (). Description ("Animation")') Self.assertisnotnone (EL) Els= Self.driver.find_elements_by_android_uiautomator ('new Uiselector (). Clickable (True)') self.assertisinstance (Els, list) El= self.driver.find_element_by_accessibility_id ('Animation') Self.assertisnotnone (EL) Els= self.driver.find_elements_by_accessibility_id ('Animation') self.assertisinstance (Els, list)

In general, it's increased in the driver.

    • find_element_by_accessibility_id
    • find_elements_by_accessibility_id
    • Find_element_by_android_uiautomator
    • Find_element_by_android_uiautomator

and other methods

Java Chapter

I've talked about it before, and I've added these methods.

Findelementbyaccessibilityid () Findelementsbyaccessibilityid () findelementbyiosuiautomation () Findelementsbyiosuiautomation () Findelementbyandroiduiautomator () Findelementsbyandroiduiautomator ()

Discussion: As can be seen from the above, Python and Java Client encapsulation of mobile control positioning is relatively elementary. Ruby Lib encapsulates a number of handy and concise methods, so you can see that using Ruby Lib is a better choice than Python and Java. Of course, if performance is ignored.

In the next section we start to look at how to use the resource ID to locate the control.

The copyright of this article is owned by ethanol, welcome reprint, but please specify the author and source, strictly prohibited for any commercial use

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.