uiautomator2自动化测试工具详解

发布时间 2023-09-06 10:57:31作者: 彭哈哈
  • 前言
    • 个人观点觉得uiautomator2的运行方式比appium要简单许多,因为appium依赖性方较多,尤其是在做iOS连接appium时需要xcode中编译的webdriveragent工具来协助运行自动化环境,特别容易在运行中自动中断自己就删除了?,因此会带来很多麻烦
  • 环境部署
    • 电脑上需要有已配置好的adb的环境(网上教程很多,这里就不细讲了)
    • 安装python的uiautomator2库

      pip install -U uiautomator2       出现Successfully installed的标识就说明安装成功   

    • 在手机上安装atx-agent

      1)使用adb命令连接手机并查出序列号    adb devices

      2)在python中编写启动脚本,就可以直接在手机上直接安装atx(安装好后会出现一个小汽车的图标)

      import uiautomator2 as u2
      d = u2.connect_usb('9YS0220813028584')# 按序列号连接手机
      print(d.info)
      d.app_start('包名')# 启动app(包名)   如何获取app的包名可以参考我的其他文章

       3)安装weditor

      pip3 install weditor==0.6.4

       4)启动weditor

      python -m weditor

 

到这里关于uiautomator2的自动化环境就搭建好了! 大家有疑问或好的想法可以在评论区一起讨论~

        ?