appium location based on common elements

First, the elements of positioning tool

  App application elements using the positioning control, unlike web pages, web page positioning elements commonly used tool is the F12, then the app which we will have to help other tools to assist in positioning.

1.uiautomatorviewer.bat

  After ADT tool is installed, the installation is located in the path ADT android-sdk-windows \ tools \ bin directory tool uiautomatorviewer.bat

  

  Double-click to start, after starting in the initial screen, click the button can be shown in position screenshots

  

  To see the various elements of the screenshot, the effect of the screenshot:

  

 2.appium Checker

  In the log window interface after appium start, click on the "start checking session," the inspector will jump start parameter configuration interface, configuration parameters directly to our code inside the boot parameters move over it.

  

   

   Click Start, based on the information we use to configure automatically jump to the main page of the application, we can begin positioning the elements:

  

 Second, the conventional method of positioning elements

  appium inherited from selenium in all the elements of positioning methods, and added some of their own way, let's take a look at appium source:

  

   But the method inherited from the positioning of selenium, in general, only use id, class_name, xpath these three methods, sum up, appium commonly used positioning methods generally have the following five categories:

  1. By positioning id: resource-id
  2. By positioning class_name: class
  3. By accessibility_id Location: content-desc
  4. By android_uiautomator Positioning: uiautomator automation framework SDK comes with java development
  5. By positioning xpath

  UIAutomator description:     

  UI Automation framework UIAutomator Andrews mobile terminal, the requirements: Android4.3 above

  • It provides a series of API: UI test execution system or a third-party app above
  • Allowed to perform operations on a device under test, such as open system settings menu
  • Black box for writing automated tests

  The main features of UIAutomator framework:

  1. Positioning elements: UI Automator Viewer. Scanning, image analysis tool application UI components tested
  2. Operating elements: Accessing device state. App on the target device, and various operations
  3. Element identification: UI Automator APIs. Capturing a plurality of components and operation of the UI application

1.id positioning

driver.find_element_by_id () or MobileBy.ID

 Note that the use of resource-id, rather than id

instead = (MobileBy.ID, ' com.taobao.taobao:id/iv_image ' )

2.class_name positioning

driver.find_element_by_class_name() 或者 MobileBy.CLASS_NAME

 It can directly use class

loc = (MobileBy.CLASS_NAME, 'android.widget.ImageView')

3.accessibility_id positioning

driver.find_element_by_accessibility_id() 或者 MobileBy.ACCESSIBILITY_ID

 Here you can use the content-desc

loc = (MobileBy.ACCESSIBILITY_ID, '管理')

4.android_uiautomator positioning

driver.find_element_by_android_uiautomator() 或者 MobileBy.ANDROID_UIAUTOMATOR

The parameters of the method is positioning element UiSelector class expressions:

new UiSelector (). The function name ( 'targeting expression')

Examples of a UiSelector object, then calling the interface by way of example, be described with reference to some methods used in the official website of the specific URL: https://developer.android.com/training/testing/ui-automator.html#ui-automator-viewer the website needs over the wall

Call here UiSelector object text () method can be more please refer to the above address

# Note that the string must use double quotes
= LOC (MobileBy.ANDROID_UIAUTOMATOR, ' new new UiSelector (). text ( "go around") ' )

5.xpath positioning

driver.find_element_by_xpath() 或者 MobileBy.XPATH

 Note tag name here must be to use class name as a label xpath, where different from selenium, and met when text positioning of text, use the text rather than text ()

= LOC (MobileBy.XPATH, ' //android.widget.TextView[text= "Home"] ' )

Third, the combination of positioning

Using the method in a UIAumtomator, because the method in the class UiSelector backout the object itself, various methods can be invoked continuously, i.e., the use of such compositions positioning method

 We can call the three methods are combined in a row

loc = (MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().className("android.widget.TextView").text("家装").index(2)')

Fourth, the father and son positioning

childSelector call UiSelector class () method, passing the offspring of the elements in the process of targeting expressions inside

For example, just "Home" parent node properties as follows

 So our position expression can be achieved by positioning his son

loc = (MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().className("android.widget.TextView").childSelector(text("家装"))')

Five brothers positioning

Similarly, we call fromParent () method, expressed the same level of positioning siblings

 Known to the "Home" button-oriented elements, text attributes as "Home", then to locate the "department store elements" by the element

= LOC (MobileBy.ANDROID_UIAUTOMATOR, ' new new UiSelector (). text ( "Home") .fromParent (text ( "department store")) ' )

 

Guess you like

Origin www.cnblogs.com/xiaogongjin/p/11768981.html