
环境:(对于具体版本没有必要完全一致)
xcode:Version 12.2 (12B45b)
appium版本:1.19.0
appium desktop版本:1.18.3(本次不涉及desktop)
node版本:v14.15.1
iOS真机测试的坑实在太多,需要多一些耐心
Android的UI自动化搭建太简单了,感兴趣的可以自己百度或者谷歌
备注:以下环境安装过程中,如果出现某文件无权限,可以使用以下命令,修改文件权限
sudo chmod -R 777
1、安装homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2、安装libimobiledevice(真机测试必备)
brew install libimobiledevice --HEAD
3、安装carthage
brew install carthage
4、安装node
去官方的地址https://nodejs.org/en/download/,下载文件进行安装
5、安装cnpm(由于某种原因,直接用npm下载安装会有好多网络问题,安装淘宝的cnpm要比npm好用)npm install -g cnpm --registry=https://registry.npm.taobao.org
6、安装ios-deploy(真机测试必备)
cnpm install -g ios-deploy
7、安装xcpretty 如果安装出错,切换个目录再试试
gem install xcpretty
8、安装appium
cnpm install -g appium
PS:如果安装失败,可以尝试使用 npm install -g appium
10、通过xcode编译 WebDriverAgent 第一步 首先修改 WebDriverAgentLib文件的 general第一步: cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/ 第二步:ls命令 查看文件夹中是否存在WebDriverAgent文件夹 第三步:若不存在WebDriverAgent文件夹,则在当前文件夹下,使用以下命令,若存在,则跳过第三步 git clone https://github.com/facebookarchive/WebDriverAgent.git 第四步:cd WebDriverAgent/ 第五步:mkdir -p Resources/WebDriverAgent.bundle 第六步:sh ./Scripts/bootstrap.sh 第七步:第六步安装成功后,再次执行该命令,若出现以下提示,则证明安装成功 -e Fetching dependenciesDependencies up-to-date
第二步 修改 WebDriverAgentLib文件的 Signing&Capabilities
在 *** 作team这个步骤时
如果没有账号,需要添加好账号,并申请权限
通过 manage Certificates添加开发者证书
本环节要确保添加好team后,确保页面上没有任何错误:如果有错误,则无法编译成功,下图则是出现问题的场景
第三步 修改 WebDriverAgentLib文件的 Build Settings 设置支持的最低iOS版本,以及修改 Bundle identifier第四步 修改WebDriverAgentRunner文件的 Signing&Capabilities
第五步 修改WebDriverAgentRunner文件的 Build Settings
第六步 点击左上角的执行按钮,出现 Build Succeeded提示,则部署完成
11、建立服务WebDriverAgent 第一步 可以先关掉xcode了。确保手机和MAC都在同一个wifi下,且都能连接外网 第二步:
获取udid:
可以通过itools获取到udid后,使用如下命令,其中xxxx需要替换为你手机的udid
cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=xxxxxxxxxxxxxx' test
执行后,必定会报错,但会在你的手机上安装一个WebDriverAgent的软件,这个软件没有图标
在通用->描述文件与设备管理->信任刚才安装的软件,再次执行
cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=xxxxxxxxxxxxxx' test
如出现如下信息,则证明执行成功
12、确认设备监听成功1.在手机设置->Developer 中,打开Enable UI Automation
2.从上图中,可以看到 ServerURLHere->http://169.254.48.135:8100<-ServerURLHere
3.打开浏览器,输入上面的连接http://169.254.48.135:8100/status,看到返回一个json串,则证明监听成功
4.如果无法打开页面
使用iproxy 8100 8100,强行把设备端口号绑定在8100端口,此时,你需要使用http://127.0.0.1:8100/status 网址打开网站,看看能否抓到设备信息
需要注意的是:
如果使用了iproxy进行端口强绑,后续在设置desired_caps时,需要额外增加一个参数
13、启动appium第11步执行的命令行不要关闭!!!
重新打开一个命令行输入appium,进行启动
14、demo(简单写了一个,用于演示)备注:
若之前,你必须要用iproxy 8100 8100强制进行端口监听,则需要在desired_caps中加入webDriverAgentUrl:"http://localhost:8100"(第23行),因为我不需要进行强制端口监听,所以我注释掉了这段代码bundleId 此处我使用的是今日头条的bundleId 不要问我为什么用今日头条不用tiktok,手动狗头🐶如何查询app的bundleId,网上一大堆方法xcodeOrgId:使用自己的开发者id可以通过xcode查看
4.确保命令行中正在正确执行
wda命令正在执行
cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=xxxxxxxxxxxxxx' test
appium正在执行
appium
8100/status端口能正常监听
demo代码:进行自动滑动 *** 作
# -*- coding:UTF-8 -*-
import unittest
import time
from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
class ContactsAndroidTests(unittest.TestCase):
name = 'ContactsAndroidTests'
def setUp(self):
desired_caps = {}
# 真机参数
desired_caps['deviceName'] = 'iPhoneXS'
desired_caps['platformName'] = 'iOS' # 系统版本
desired_caps['platformVersion'] = '13.6' # 设备名称
# desired_caps["bundleId"] = "com.zhiliaoapp.musically.ep"
desired_caps["bundleId"] = "com.ss.iphone.article.NewsSocial"
desired_caps['noReset'] = True
desired_caps['udid'] = '00008020-000A486814E1002E'
desired_caps['xcodeOrgId'] = 'MNLY4SEVLJ'
desired_caps['xcodeSigningId'] = 'iPhone Developer'
# desired_caps['webDriverAgentUrl'] = "http://localhost:8100"
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
self.action = TouchAction(self.driver)
def tearDown(self):
self.driver.close_app()
self.driver.quit()
def testcase_noreset_false(self):
print "开始~~~"
self.driver.implicitly_wait(8) # 动态休眠时间
time.sleep(5)
try:
for i in range(0, 1000):
self.action.press(x=173, y=613).wait(500).move_to(x=174, y=192).release().perform()
print "第" + str(i) + "次"
time.sleep(2)
except Exception, e:
print e
print " *** 作完成"
if __name__ == '__main__':
unittest.main()
pass
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)