Facebook-wda tidevice iOS自动化测试

今天在用appium进行iOS自动化测试的时候发现其获取布局文件以及截图文件时效率非常低,于是就想到调研一下有没有其他方法跳过appium的接口。

 

奔跑吧!智能Monkey之Fastbot跨平台_ 字节跳动技术团队的博客-CSDN博客 这篇文章做了一个调研,结果并没有什么卵用:

 然后iOS自动化测试驱动工具探索_ios_字节跳动终端技术_InfoQ写作社区 文章中也提到字节实现了一个工具bdc,但是奈何他不开源。

facebook-wda

之后就发现了这个工具,是uiautomator2团队开发的工具(真的太牛了这个团队),之前安卓开发的时候为了绕过appium选择了uiautomator2,结果现在做ios端为了绕过appium又是选择了这个团队的工具。

github主页:GitHub - openatx/facebook-wda: Facebook WebDriverAgent Python Client Library (not official)

国人团队写的非常详细,我列几个常见的用法:

import wda

# 连接设备
c = wda.Client('http://localhost:8100')
# 如果只有一个设备也可以简写为
c = wda.USBClient()
# 支持指定设备的udid,和WDA的端口号
c = wda.USBClient("539c5fffb18f2be0bf7f771d68f7c327fb68d2d9", port=8100)

# 基础操作
c.source() # 获取XML
c.source(accessible=True) # default false, format JSON
# Press home button
c.home()
c.locked() # true of false
c.lock() # lock screen
c.unlock() # unlock
c.app_current() # 当前app,返回格式{"pid": 1281, "bundleId": "com.netease.cloudmusic"}
c.screenshot('screen.png') # Good
# convert to PIL.Image and then save as jpg
c.screenshot().save("screen.jpg") # Good
c.appium_settings() # 获取appium的配置

# app连接
s = c.session("com.apple.Health", alert_action="accept")
c.session().app_activate("com.apple.Health") # same as app_launch
# terminate app
c.session().app_terminate("com.apple.Health")
# get app state
c.session().app_state("com.apple.Health")
# output {"value": 4, "sessionId": "xxxxxx"}
# different value means 1: die, 2: background, 4: running

# 对app的一些操作,其实和上面对设备的操作差不多
s.home() # same as c.home(), use the same API
s.screenshot().save("s.png")
# Get width and height
print(s.window_size())
# Double touch
s.double_tap(200, 200)
s.swipe_left()
s.swipe_right()
s.swipe_up()
s.swipe_down()
# tap hold for 1 seconds
s.tap_hold(x, y, 1.0)
# press home, volumeUp, volumeDown
s.press("home") # fater then s.home()
s.press("volumeUp")
s.press("volumeDown")

# 查找元素
# using id to find element and check if exists
s(id="URL").exists # return True or False
# using id or other query conditions
s(id='URL')
# using className
s(className="Button")
# using name
s(name='URL')
s(nameContains='UR')
s(nameMatches=".RL")
# using label
s(label="label")
s(labelContains="URL")
# using value
s(value="Enter")
s(valueContains="RL")
# using index, index must combined with at least on label,value, etc...
s(name='URL', index=1) # find the second element. index of founded elements, min is 0
# combines search conditions
# attributes bellow can combines
# :"className", "name", "label", "visible", "enabled"
s(className='Button', name='URL', visible=True, labelContains="Addr")
s(xpath='//Button[@name="URL"]')

# 对元素操作
s(text='Dashboard').tap()
# Accessing attrbutes, you have to use get()
s(text='Dashboard').get().value
s(text='Dashboard').click_exists() # return immediately if not found
e.tap()
e.click() # alias of tap
e.clear_text()
e.set_text("Hello world")
e.tap_hold(2.0) # tapAndHold for 2.0s
# Set text
e.set_text("Hello WDA") # normal usage
e.set_text("Hello WDA\n") # send text with enter
e.set_text("\b\b\b") # delete 3 chars
# Swipe
s(className="Image").swipe("left")

其他的去主页看,写的真的很详细

但是不支持安装和卸载,可以用os.system调用下面介绍的tidevice的终端操作来实现

tidevice

顺便找到的一个能用来替代ideviceinstaller的阿里开发的一个类似于adb的iOS交互程序,用pip安装。

gitee地址:

tidevice: tidevice 是 iOS 自动化工具,可用于 iOS 应用的性能采集和 UI 自动化

github地址:GitHub - alibaba/taobao-iphone-device: tidevice can be used to communicate with iPhone device

pip3 install -U "tidevice[openssl]"   # Recommend
pip3 install -U tidevice

能够看一些手机的信息:

$ tidevice pair
# 配对设备

$ tidevice unpair
# 取消配对设备

$ tidevice list
List of apple devices attached
00008030-001A35E40212345678 codeskyblue的iPhoneSE

$ tidevice list --json
[
    {
        "udid": "00008030-001A35E40212345678",
        "name": "codeskyblue的iPhoneSE"
    }
]

# 安装应用
$ tidevice install example.ipa

# 指定设备安装
$ tidevice --udid $UDID install https://example.org/example.ipa

# 卸载应用
$ tidevice uninstall com.example.demo

# 启动应用
$ tidevice launch com.example.demo

# 停止应用
$ tidevice kill com.example.demo

# 查看已安装应用
$ tidevice applist

# 查看运行中的应用
$ tidevice ps
$ tidevice ps --json output as json

同时还能够替代xcode运行WebDriveragent,也就是能支持Windows和Linux平台进行iOS测试,但是我没有弄成功就不写了,在github首页有写。

然后其实他还是支持python的,可以直接在python中调用API接口,看这个文章:

​​​​​​​阿里最新、最强开源iOS自动化测试神器 - 知乎

理论上应该有很多用facebook-wda进行开发的,毕竟没人想用appium,但是在网上找了好久都没有找到相关文章,只能自己踩坑然后写下来了。

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值