python+airtest+unittest来做IOS自动化

环境搭建

1)github下载WebDriveragent, ,百度搜这个然后找到github地址然后去下载

2)安装AirtestIDE 下载地址。我下载的AirtestIDE_2019-09-10_py3_Mac10-12.dmg。下载完成之后,直接安装即可。

设备连接-部署iOS-Tagent

iOS-Tagent下载地 址  下载完成之后 需要在WebDriverAgent/Scripts 中执行build.sh脚本  sh执行就行 或者./bulid.sh  

(1)需要在signing& Capbailities中 设置Team(就是苹果id或者开发者账号) 需要选择debug模式 设置完成之后下面不能显示 黄色提示报错信息

2)在Bulid Settings中设置 唯一的Packing Product Bundle Identifler 修改就行

3)设置 product -> Scheme -> WebDriverAgentRunner

4)点击product 点击test  手机会安装WEBdriverapp  通用里面设置信任

5)在终端里面 安装 iproxy   执行brew install iproxy 进行安装 在终端输入iproxy 8100 8100 不能关闭,在xcode里面,点击product点击test,然后在airtest中进行连接手机

6)网页中输入 http://172.20.10.7:8100/status ,如果访问成功并且可以看到一些json格式的手机信息,即表示启动成功若还是不行,查看 这个链接或者 搜虫师 ios环境搭建。https://www.jianshu.com/p/cd61f4dcd307

 

举个例子

(1)先导包,ios自动化用的是airtest这个工具来进行定位和实现一些基本操作的。需要用到它的api

 

(2) 设置截图存放位置和日志路径,命名规则

 

 

 

 

(3) 用例编写-初始化操作和结束操作

 

 

 

 

 

以上完成,就可以进行用例编写了

 

常用操作

(1)通过文本定位

导包导iosPoco,实例化函数 例如 poco=iosPoco() 后面具体文本定位就可以

poco(‘商城’).click()   或者 poco(‘商城’).wait(2).click()

 

(2) 通过截图定位,使用airtest来进行截图 然后进行定位

点击工具左上角中的 开始录制 按钮,然后鼠标进行操作。操作完成之后,工具页面会出现当前操作的代码和图片名称

 

(2)滑动操作

先获取屏幕尺寸 screenWidth,screenHeigth=poco.get_screen_size()

Swipe((screenWidth*0.5,screenHeigth*0.9),vector=[0,-0.8],duration=2.5)

vector的值是 [0,-0.8] 趋势越来越小  那么他就是 页面往下滑

vector的值是[0,0.8] 趋势越来越大(不能大于1),那么他就是 页面往上滑

 

 

 

(3)截图

Snapshot(filename=’test.png’)

 

(4)循环点击某个list元素合集

for item in range(len(freeze_poco("List").child())):

     item = str(item)

     poco("NestStarReward").offspring(item).offspring("T").click()

 

(5)判断元素不存在则点击

if not poco("TeamDlg(Clone)").offspring("Categories").offspring("item1").offspring("Text").exists():

poco("CurrentCategory").click()

 

(6)滑动

# swipe from A to B

point_a = [0.1, 0.1]

center = [0.5, 0.5]

poco.swipe(point_a, center)

 

# swipe from A by given direction

direction = [0.1, 0]

poco.swipe(point_a, direction=direction)

 

 

 

 

(6)控件出现超时

from poco.exceptions import PocoTargetTimeout

 

try:

    poco('guide_panel', type='ImageView').wait_for_appearance()

except PocoTargetTimeout:

    # bugs here as the panel not shown

    raise

 

posted @ 2021-08-06 16:17  以泪为证  阅读(543)  评论(0)    收藏  举报