基于windows的iOS自动化测试

发布于:2022-12-26 ⋅ 阅读:(538) ⋅ 点赞:(0)
  1. 准备工作

    1. 技术原理

       

  1. 手机端的WDA Runner(WebDriverAgent)类似于appium测试框架中的 UIAutomator Server,将从客户端接收到的控制命令转换为XCUITest 相关API操作,实现对应用界面的控制。WebDriverAgent应用需要通过xcode编译安装。

    1. usbmuxd是苹果提供的一个服务,用于USB和TCP协议之间的转换,实现在没有网络的情况下也可以连接设备,iTunes和Xcode就使用到了这个服务,所以在环境安装中需要在windows上安装一个iTunes。

    2. WDA的启动使用阿里开源的tidevice工具。

    3. Language Bindings为不同语言的测试脚本,比如基于python语言的facebook-wda,基于go语言的gwda等。

  2. 环境抢建

    1. iOS 设备安装 wda

      1. 安装Xcode

      2. 下载WebDriverAgent

github下载地址

  1. 安装iTunes

    1. 下载安装Windows 版 iTunes方法:下载地址

    2. iTunes安装成功后,连接上你的iPhone:

                

  1. 安装python,windows10安装python详细过程

  2. 安装pip

    1. 官网下载pip安装包,官网地址:https://pypi.org/project/pip/

    2. 下载pip的tar包,如图:

    3. 解压后,通过cmd进入解压目录,执行命令:python setup.py install

  3. 安装tidevice

    1. 打开cmd,输入命令: pip3 install -U "tidevice[openssl]",如图表示安装成功

    2. 查看tidevice版本号验证是否安装成功,打开cmd,输入命令:tidevice version或tidevice -v,如图

  4. 安装git,下载地址

  5. 安装weditor(本人n次安装失败,找到了源码安装方法)

    1. 先用git下载源码,git clone https://github.com/openatx/weditor

    2. 基于源码安装pip3 install -e weditor

  1. 连接测试

    1. 手机安装WebDriverAgent

    2. 启动驱动器

 tidevice  wdaproxy -B com.facebook.WebDriverAgentRunner.xctrunner --port 8100

  1. 启动weditor 

    1. python -m weditor,会自动打开一个浏览器,选择iOS

    2. 输入http://localhost:8100,连接

  2. python命令测试

import wda
wda.DEBUG = True
c = wda.Client('http://localhost:8100')
c = wda.Client() # 读取环境变量DEVICE_URL,如果没有使用默认地址:http://localhost:810
c.home() #点击home键
s = c.session("com.Litta.LittaCoach") # 打开app
  1. 用例编写

    1. 元素定位

      1. s(name='我的',className='Button')

                       

  1. s(nameContains='账号设置',index=0)

                       

  1. s.xpath('//Table/Cell[2]/Button[1]/StaticText[1]')

    1. s(className='XCUIElementTypeTextField')

    2. s(predicate='name BEGINSWITH "账号设置"')

  2. 元素事件

    1. s(name='我的',className='Button').tap

    2. s(nameContains='账号设置',index=0).click()

    3. s(name="我的").tap_hold(2.0) 

  3. text操作

    1. s.xpath('//ScrollView/Other[1]/Other[1]').set_text('1')

    2. s(className='XCUIElementTypeTextField').set_text('18651660882')

    3. s(className='XCUIElementTypeTextField').clear_text()

  4. 异常

    1. assert s(nameContains='账号设置',index=0).wait(1.0)

  5. 打印元素信息

    1. ele = s(predicate='name BEGINSWITH "账号设置"')   print(ele.name)

    2. ele = s(predicate='name BEGINSWITH "账号设置"')   print(ele.text)

  6. 屏幕截图

    1. s.screenshot().save("test.png")

  7. 手势滑动swipe

    1. s.swipe(fx, fy, tx, ty, duration=0.5) # 从(fx, fy)滑到(tx, ty),坐标值可以是绝对值或者百分比,duration单位秒

    2. s.swipe_left()

    3. s.swipe_right()

  8. WDA教程

https://github.com/openatx/facebook-wda

https://blog.51cto.com/u_15649298/5479308

https://blog.csdn.net/QQqun810119819/article/details/120939806

      

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到