由于下拉菜单中元素name值相同,采用列表循环
def check_waterFlowLevel():
waterLevel_list = []
position_dic = {}
elements = poco("android.widget.RelativeLayout").offspring("com.eco.global.app:id/tv_left")
print(elements)
for i in elements:
waterLevel_list.append(i.get_text())
waterLevel_list = set(waterLevel_list)
print("当前拖地水量的值有:" + str(waterLevel_list))
# 获取水量的纵坐标位置
for j in waterLevel_list:
position_dic[j] = poco(text=j).get_position()[1]
# print("当前水量和其对应的纵坐标位置为:",end="")
# print(position_dic)
# 判断水量的排序
if position_dic['低'] < position_dic['中'] < position_dic['高']:
print("当前排位正确")
else:
print("水量排位错误!")
return position_dic
# 为进入系统,上滑
poco(name='com.android.settings:id/category').swipe('up')
x,y=poco.get_position()
dir=[0,-0.5]
poco.swipe([x,y],dir)
i = 0
while True:
if timezone_element.exists():
timezone_element.click()
break
# 设定最多滑动次数(因为系统中只有4个category元素)
elif i < 5:
# 按category坐标来滑动
x,y=poco.get_position()
dir=[0,-0.5]
poco.swipe([x,y],dir)
i+=1
else:
raise PocoNoSuchNodeException
# android:id/numberpicker_input[0]为小时,[1]为分钟
poco(name='android.widget.NumberPicker').\
child(name='android:id/numberpicker_input')[1].swipe([0,-0.2])
引用poco中的异常
# 引用python包中poco模块的中的异常
import sys
sys.path.append("D:\python\Lib\site-packages\poco")
import exceptions
# 应用在poco的操作中
while True:
if timezone_element.exists():
timezone_element.click()
break
# 设定最多滑动次数(因为系统中只有4个category元素)
elif i < 5:
# 按category坐标来滑动
x,y=poco.get_position()
dir=[0,-0.5]
poco.swipe([x,y],dir)
i+=1
else:
raise PocoNoSuchNodeException
引用airtest中的异常
# 引用airtest中的异常
from airtest.core.error import *
# 应用在图像定位
try:
wait(Template(r"tpl1585821764025.png", record_pos=(0.003, 0.747), resolution=(720, 1440)),180)
except TargetNotFoundError:
deboot_flag = 1
# 如果测试报告文件夹TestReport不存在,就创建
report_path = os.getcwd()+'\\TestReport'
if not os.path.exists(report_path):
os.mkdir(report_path)
判断文件存在,就写入
if os.path.exists(report_timezone_not_found):
with open(report_timezone_not_found, 'a+') as f:
localtime = time.asctime(time.localtime(time.time()))
# 写入本轮测试结束图标
f.write('-'*20 + localtime + '-'*20 + '\n')
To be continued..