appium+python+ios真机在mac中环境搭建及使用

桌面appium环境搭建

(先吐槽一下,appium搭建环境遇到的坑是真的多)
我下载的appium版本是1.71.1,下载完就可以开始使用啦

第一步:开始服务,点击放大镜

在这里插入图片描述
在这里插入图片描述

第二步:配置json字符串,先保存,再Start Session

iOS的配置如下
{
“platformName”: “iOS”,
“platformVersion”: “12.4”,
“deviceName”: “iPhone”,
“udid”: “ec07393e72e823f4f7e73f9709cd2c9104”,
“bundleId”: “com.medialab.XXX”,
“app”: “/Users/admin/rtcengine-test/AgoraRTCEngine-test/AutoBuild/Results/XXXX.ipa”
}
成功连接手机
在这里插入图片描述

终端appium环境搭建

先安装npm和node,再通过npm安装cnpm,安装过程不详述,用npm install appium一直不能成功,用了镜像也不行,干脆用的cnpm,虽然cnpm也遇到了一些问题,卡在了安装appium-chromedriver上面,用了–ignore-scripts就好了

cnpm install -g --ignore-scripts

安装appium-doctor

cnpm install appium-doctor

但不知道为什么appium和appium-doctor没有打包好的可执行文件,只有js文件,js文件加入环境变量也可以用,在bash_profile中添加如下语句,并source

alias appium='/usr/local/Cellar/node/15.2.1/lib/lib/node_modules/appium/build/lib/main.js'
alias appium-doctor='/usr/local/Cellar/node/15.2.1/lib/lib/node_modules/appium-doctor/appium-doctor.js'

然后在终端输入appium或者appium-doctor都是可以执行的,necessary的部分都是绿勾,问题不大
在这里插入图片描述
appium开启成功
在这里插入图片描述
要想操纵手机,无论是终端还是桌面,都得在手机上安装WebDriverAgent,
具体安装方法参见https://testerhome.com/topics/6962
我在安装的过程中,遇到了Xcode可以编译成功,但是无法直接装到手机上,执行如下命令才装包成功,但是appium启动一次,WebDriverAgent就要被删一次,不知道为啥,网上说可能需要企业签名

xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=真机的udid' test

python端

pip3 install Appium-Python-Client

import time
from appium import webdriver

desired_caps = dict()
desired_caps['platformName'] = 'iOS'
desired_caps['platformVersion'] = '14.2'
desired_caps['deviceName'] = 'iPhone 8 Plus'
desired_caps['app'] = 'com.medialab.XXX'
desired_caps['udid'] = 'ec07393e72e823f4f7e73f9709cd2c91'


driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)

driver.find_element_by_xpath('//XCUIElementTypeStaticText[@name="XXX"]').click()
time.sleep(1)
driver.find_element_by_xpath('//XCUIElementTypeApplication[@name="JP"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTextField[1]').send_keys("111111")
driver.find_element_by_xpath('//XCUIElementTypeApplication[@name="JP"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTextField[2]').send_keys('222222')



执行以上代码可以实现模拟点击,一定要确保WebDriverAgent是被装到手机上的

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值