For basic install and use, please refer to official doc. I'll start from finding elements.
A. Find elements using poco
pip install pocoui
(hint: not pip install poco
, that's a different framework).
You can get elements UI tree by Airtest IDE.
1.using name
use element's name from UI tree directly
button = poco('ConfirmButton')
2.using other attributes
You can find other attibutes like type, visible or text by clicking the element from UI tree, and you can locate the elements with these attributes.
button = poco('ConfirmButton', text='OK')
button = poco('ConfirmButton', type='Button')
3.using relative relation to locate elements
You can use relative location to find the elements, for example:
poco("plays").child("playBasic").offspring("star_single")
more relative location method
child() direct child(ren), if more than one child is matched, poco('xxx').child('yyy').click()
will operate on the first 'yyy' child element
children() direct children(all children)
offspring select the offsprings including the direct child(ren)
parent() select the direct parent
sibling() select the sibling(s)
4.using index to locate elements
If .child() finds more than one elements, you can use the index to locate them one by one
btn0 = poco('xxx').child('Btn')[0]
btn1 = poco('xxx').child('Btn')[1]
btn2 = poco('xxx').child('Btn')[2]
5.using regular expression
select the UI element whose text attribute matches the pattern '^close.*$'
close_btn = poco(textMatches='^close.*$')
and name can also be matched by nameMatches
poco(nameMateches='.*Title$')
B. Find elements using Airtest
1.snapshot
get the snapshot of the target element, named as 'target.png', and you can click(touch in Android or iOS) it like:
touch(Template(r"target.png", record_pos=(-0.021, 0.121), resolution=(900.0, 1600.0)))
2.set the threshold
there's a threshold value to help filter the image finding results. When it's lower, it means it's easy to find incorrect image and when it's higher, it means it will only find highly matched images.
We can set the global threshold like this(the default value is):
from airtest.core.setting import Settings as ST
ST.THRESHOLD = 0.7 # used in finding elements
ST.THRESHOLD_STRICT = 0.7 # used in assert
if we want to set dedicated threshold for one element, we can set like this:
touch(Template(r"target.png", threshold=0.8, record_pos=(-0.021, 0.121), resolution=(900.0, 1600.0)
网友评论