iOS positioned elements

Recently we are doing automated testing IOS, IOS is Appium environment configuration OK, execute really slow, slow to cynicism, then to sum up today IOS speed sorting and targeting each targeting method.


According to my observation, according to the order of the elements to find the speed, from fast to slow in the following order:

ios_predicate >> accessibility_id >> class_name >>xpath

Note ⚠️ :( more forums say that class_name >> accessibility_id, where we just assume that their speed is the same.)

1, element attributes introduction
 
image.png

type: Element type, consistent with className effects, such as: XCUIElementTypeButton
value: generally do
name: text content elements can be used as AccessibilityId positioning methods, such as: ClearEmail
label: In most cases, action is consistent with the name
enabled: the element can be clicked, the general value true or false
visible; element is visible, the general value of true or false


2、ios_predicate

In the iOS UI Automation, a native support Predicate best targeting, properties of a single support element and positioning a plurality of attributes, strongly recommended.
Use, for example as follows:

driver.find_element_by_ios_predicate("value == 'ClearEmail'")
driver.find_element_by_ios_predicate("type == 'XCUIElementTypeButton' AND value == 'ClearEmail'")

1) comparison: >、<、==、>=、<=、!=
can be used to compare strings and values:
such as: value>100or value == 'ClearEmail'orvalue != 'ClearEmail'

driver.find_element_by_ios_predicate("value>100")

2) operator range: IN、BETWEEN
it can be used to check the range of values and character strings
such as: value BETWEEN {1,6}orvalue IN {'Clear','Email'}

driver.find_element_by_ios_predicate("value BETWEEN {1,6}")

3) string Related: CONTAINS、BEGINSWITH、ENDSWITH
contains a string, such as: value CONTAINS 'Email'
beginning with a string, such as: value BEGINSWITH 'Clear'
at the end of a string, such as:value ENDSWITH '班级Email'

driver.find_element_by_ios_predicate("value CONTAINS 'Email'")

4) Wildcard: LIKE
wherein: ?represents a character *representative of a plurality of characters
such as: value of an element attribute ClearEmail:
value LIKE 'Clear?mail'
value LIKE 'Clear*'
more so many text can be recognized as the same element.

driver.find_element_by_ios_predicate("value LIKE 'Clear*'")

5) the regular expression: MATCHES
such as: value of an element attribute ClearEmail:
value MATCHES '^C.+l$'

driver.find_element_by_ios_predicate("value MATCHES '^C.+l$'")

Note ⚠️: regular expressions details, please refer to my other article " Python - Regular Expressions "
6) two and two or more attributes positioning element: AND
a single property can be positioned to connect with the symbol AND, as follows:

driver.find_element_by_ios_predicate("type == 'XCUIElementTypeButton' AND value == 'ClearEmail'")


3、accessibility_id

Replaces the previous nametargeting, On iOS, the main elements used labelor the name(value of the two properties are the same) property positioned, if the attribute is empty, they can not use this property.
driver.find_element_by_accessibility_id('ClearEmail')


4、class_name

Use the element typeattribute positioning, we pay special attention to the uniqueness of the property! class_nameThe only situation is not much, we do not have access under normal circumstances.
driver.find_element_by_class_name('XCUIElementTypeButton')


5、xpath

Since iOS 10 start XCUITest framework does not support the use of native, positioning is very slow, so we do not recommend the use of the official, there are other alternative targeting methods can be used.
1) is positioned using the absolute path:
driver.find_element_by_xpath('/XCUIElementTypeApplication/XCUIElementTypeButton')
2) positioned relative path
driver.find_element_by_xpath('//XCUIElementTypeButton')
3) is positioned by an index element
driver.find_element_by_xpath('//XCUIElementTypeButton[index]')
4. The positioning element attribute by
an attribute:
driver.find_element_by_xpath("//className[@value='ClearEmail']")
two properties:
driver.find_element_by_xpath("//className[@value='ClearEmail'][@ visible =true]")
some properties (most powerful):driver.find_element_by_xpath("//className[contains(@value,'ClearEmail')]")


 

Link: https: //www.jianshu.com/p/a6c2d72fe704

Guess you like

Origin www.cnblogs.com/kaola8023/p/12524277.html