Python + uiaotumator2之Android—APP自动化简易例子
Posted Owen_ET
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python + uiaotumator2之Android—APP自动化简易例子相关的知识,希望对你有一定的参考价值。
上代码:
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/08/31 09:43 # @Author : zc # @File : test.py import uiautomator2 as u2 from time import sleep d = u2.connect_usb(‘608ad0fe‘) #打开小卖 # d(text=u"小卖安全").click() d.app_start("cn.sqm.citymine_safety") sleep(0.2) #输入用户名 d(resourceId="cn.sqm.citymine_safety:id/et_login_id").send_keys("ceshi06") d.click(0.924, 0.607) #输入密码 d(resourceId="cn.sqm.citymine_safety:id/et_login_password").set_text("123456") d.click(0.924, 0.607) #点击登录按钮 d(resourceId="cn.sqm.citymine_safety:id/btn_login").click() #点击发起任务 d(className="android.widget.ImageView", instance=25).click() #选择任务类型:日常检查 d(resourceId="cn.sqm.citymine_safety:id/tv_select_task_type").click() sleep(0.5) d(className="android.view.View").drag_to(0.506, 0.759, duration=0.5) d(resourceId="cn.sqm.citymine_safety:id/btn_confirm").click() #检查单位:IOS开发 d(resourceId="cn.sqm.citymine_safety:id/tv_select_inspection_area").click() d(resourceId="cn.sqm.citymine_safety:id/item_tv_next_level").click() d(resourceId="cn.sqm.citymine_safety:id/item_tv_department").click() #隐患类型:其他 d(resourceId="cn.sqm.citymine_safety:id/tv_select_hidden_danger_type").click() d(className="android.view.View").drag_to(0.506, 0.759, duration=0.5) d(text=‘确定‘).click() #隐患描述 d(resourceId="cn.sqm.citymine_safety:id/et_hidden_danger_description").set_text("其他问题") d.click(0.924, 0.607) #照片:1 d(resourceId="cn.sqm.citymine_safety:id/iv_choose_photos").click() d(text=u"手机相册").click() d(resourceId="cn.sqm.citymine_safety:id/v_selected", className="android.widget.ImageView", instance=10).click() d(resourceId="cn.sqm.citymine_safety:id/done").click() #违反制度:违反员工行为规范 d(resourceId="cn.sqm.citymine_safety:id/iv_add_violation").click() d(resourceId="cn.sqm.citymine_safety:id/item_tv_content_violation", text=u"违反员工行为规范").click() d(resourceId="cn.sqm.citymine_safety:id/tv_complete").click() #向上滑动拖拽 d(className="android.widget.LinearLayout").drag_to(0.498, 0.00, duration=0.5) #整改期限:选择9月1号 d(resourceId="cn.sqm.citymine_safety:id/tv_please_the_rectification_date").click() for i in range(2): d(resourceId="cn.sqm.citymine_safety:id/day").drag_to(0.82, 0.8, duration=0.5) d(text=‘确定‘).click() #协同人员 list = ["开发02"] d(resourceId="cn.sqm.citymine_safety:id/item_tv_personnel_name").click() d(resourceId="cn.sqm.citymine_safety:id/item_tv_personnel_name", text=list[0]).click() d(resourceId="cn.sqm.citymine_safety:id/tv_complete").click() #单位负责人 d(resourceId="cn.sqm.citymine_safety:id/item_tv_personnel_name", className="android.widget.TextView", instance=len(list)+1).click() for i in range(2): d(resourceId="cn.sqm.citymine_safety:id/lv_area_manager").click() d(resourceId="cn.sqm.citymine_safety:id/item_tv_department", text=u"区域06").click() d(resourceId="cn.sqm.citymine_safety:id/tv_complete").click() #返回首页 sleep(0.5) d.click(0.063, 0.068) #点击我的 d(resourceId="cn.sqm.citymine_safety:id/rb_single_center").click() #退出账号 d(text="安全退出账号").click() #返回首页home d.press("home") #測試完成關閉軟件 d.service("uiautomator").stop()
以上是关于Python + uiaotumator2之Android—APP自动化简易例子的主要内容,如果未能解决你的问题,请参考以下文章