当前位置:网站首页>APP automation testing with Uiautomator2
APP automation testing with Uiautomator2
2022-08-10 15:06:00 【zljun8210】
1. Install Uiautomator2
My environment is Python, which can be installed with the pip command:
pip install uiautomator2
Note: The source code of Uiautomator2: GitHub - openatx/uiautomator2: Android Uiautomator2Python Wrapper
2. Configure the device
First the device is connected to the PC and can be discovered by adb devices.Execute the following command to automatically install the device-side programs required by this library: uiautomator-server, atx-agent
# init is to install uiautomator2 on all mobile phones connected to the computer via USBpython -m uiautomator2 init# Specify the phone to install uiautomator2, use --mirrorpython -m uiautomator2 init --mirror --serial $SERIAL# If you dislike being slow, you can use a domestic mirrorpython -m uiautomator2 init --mirror
Note: It is said that the latest version of uiautomator2 does not require manual configuration. When the code runs uiautomator2.connect(), the device side will be configured first.
3. Before writing code: identify elements
There is monitor.bat in the Andorid SDK. Running it will start uiautomatorviewer, which is a tool that comes with the SDK.
You can also use third-party tools, here we recommend weditor, installed as follows:
pip install editor
Start the Editor:
python -m editor
The browser will automatically launch a web page http://atx.open.netease.com,See the following interface
Set the device seen by adb device to connect.
4. Officially write code
import unittestimport uiautomator2 as u2import timeclass AppTest(unittest.TestCase):def EditWO(self):d = u2.connect()d.app_start('com.xxxxxx.xxxxxx')time.sleep(5)d(text='Work Order').click() # Click on the Work order menutime.sleep(3)d(text='Completed').click() # Click Completedtime.sleep(2)d(text='Open').click()time.sleep(2)d(text='300').click()time.sleep(1)d(text='Save').click()d.press('back')def Mapview(self):d = u2.connect()d.app_start('com.xxxxxx.xxxxxx')time.sleep(5)d.xpath('//android.widget.RelativeLayout/android.view.ViewGroup[1]/android.view.ViewGroup[2]/android.view.ViewGroup[1]/android.view.ViewGroup[2]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]').set_text('char')d.press('enter')d(text='CHARIOTOFFIRE').click()d(text='Cancel').click()d.xpath('//android.widget.RelativeLayout/android.view.ViewGroup[1]/android.view.ViewGroup[2]/android.view.ViewGroup[1]/android.view.ViewGroup[2]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[2]/android.view.ViewGroup[5]/android.widget.ImageView[1]').click()d(text='+ ADD LOCATIONS').click()d.xpath('//androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.widget.Button[3]').click()d.click(0.503, 0.498)d.xpath('//androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup[2]/android.view.ViewGroup[1]/android.widget.Button[3]').click()d.click(0.081, 0.801)d.xpath('//androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup[3]/android.view.ViewGroup[1]/android.widget.Button[3]').click()d.click(0.914, 0.273)d(text='GET DIRECTIONS').click()d.press("back")def test_something(self):self.EditWO()if __name__ == '__main__':unittest.main()
边栏推荐
- 易观分析联合中小银行联盟发布海南数字经济指数,敬请期待!
- Redis -- Nosql
- Classifying irises using decision trees
- 640. Solving Equations: Simple Simulation Problems
- How to code like a pro in 2022 and avoid If-Else
- [Semantic Segmentation] DeepLab Series
- 波士顿房价预测
- BFT机器人带你走进智慧生活 ——探索遨博机器人i系列的多种应用
- Azure IoT 合作伙伴技术赋能工作坊:IoT Dev Hack
- pm2 static file service
猜你喜欢
等保2.0一个中心三重防护指的是什么?如何理解?
Analysys and the Alliance of Small and Medium Banks jointly released the Hainan Digital Economy Index, so stay tuned!
紫金示例
Classifying irises using decision trees
12海里、24海里、200海里的意义及名称
强意识 压责任 安全培训筑牢生产屏障
List集合
Alibaba的秒杀系统—千亿级并发设计手册上线了
It is reported that the original Meitu executive joined Weilai mobile phone, the top product may exceed 7,000 yuan
PyTorch 多机多卡训练:DDP 实战与技巧
随机推荐
[Semantic Segmentation] DeepLab Series
Analysys and the Alliance of Small and Medium Banks jointly released the Hainan Digital Economy Index, so stay tuned!
阿里五位MySQL封神大佬耗17个月总结出53章性能优化法则
Rich Dad Poor Dad Reading Notes
奢侈品鉴定机构小程序开发制作功能介绍
QOS function introduction
兆骑科创创业赛事活动发布平台,创业赛事,项目路演
Summary of tensorflow installation stepping on the pit
数学建模学习视频及资料集(2022.08.10)
基于 Azuki 系列:NFT估值分析框架“DRIC”
PAT甲级 1014 排队等候(队列大模拟+格式化时间)
Go Context基本使用
websocket实现实时变化图表内容
Do not access Object.prototype method ‘hasOwnProperty‘ from target object....
systemui shield notification bar
High-paid programmers & interview questions series 135 How do you understand distributed?Do you know CAP theory?
统信 UOS V20 专业版(1050update2)发布:文件共享、全局搜索等优化
易观分析联合中小银行联盟发布海南数字经济指数,敬请期待!
【MindSpore易点通机器人-02】设计与技术选型
从洞察到决策,一文解读标签画像体系建设方法论