IOS UI自动化环境搭建--真机
1.需要准备的设备
IOS手机+MAC 电脑+USB连接线
2.通用环境:
1.homebrew
作用:
- Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。简单的一条指令,就可以实现包管理,而不用你关心各种依赖和文件路径的情况,十分方便快捷。
安装:
先检查一下你的mac是什么版本:
终端输入:which $SHELL
/bin/bash
mac电脑点击右上角的搜索按钮,输入终端,打开终端后输入下方命令:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
环境配置:
输入:vim ~/.bash_profile
export HOMEBREW_NO_INSTALL_CLEANUP= true
export HOMEBREW_PIP_INDEX_URL=http://mirrors.aliyun.com/pypi/simple #ckbrew
export HOMEBREW_API_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles/api #ckbrew
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles #ckbrew
eval $(/usr/local/Homebrew/bin/brew shellenv) #ckbrew
使用:安装,卸载,重装软件
$ brew install <package-name> # 安装
$ brew uninstall <package-name> # 卸载
$ brew reinstall <package-name> # 重装
$ brew help #帮助查看命令
$ brew list #查看安装的软件应用
$ brew search "*关键词*" #搜索要安装的软件
$ brew cask install #安装应用程序名称
检查是否安装成功:
终端输入:brew -v
Homebrew 4.3.14
Homebrew/homebrew-core (git revision edc77cd4d07; last commit 2024-08-01)
Homebrew/homebrew-cask (git revision 5fce54697b; last commit 2024-08-01)
遇到的问题:
安装下载比较慢:科学----->上网
获取对应的ip :https://whatismyipaddress.com/hostname-ip
输入命令:vim /etc/hosts
140.82.116.3 github.com #配置
151.101.129.194 github.global.ssl.fastly.net #配置
2.python
作用:python环境跑脚本
安装:
brew search python
安装python
brew install python
配置环境变量:
#进入文件
vim ~/.bash_profile
#点击i编辑文件,添加如下内容
alias python="/usr/local/bin/python3"
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
export PATH=${PATH}:/Users/weisun/Downloads/allure-2.30.0/bin
#保存文件 :wq!
#使文件生效
source ~/.bash_profile
安装检查:
输入命令:python -V
Python 3.12.4
3.selenium
安装命令:
pip3 install selenium
检查是否安装:
pip3 show selenium
Name: selenium
Version: 4.23.1
Summary: Official Python bindings for Selenium WebDriver
Home-page: https://www.selenium.dev
Author:
Author-email:
License: Apache 2.0
Location: /Users/weisun/Library/Python/3.9/lib/python/site-packages
Requires: certifi, trio, trio-websocket, typing_extensions, urllib3, websocket-client
Required-by:
4.setuptools
5.pip
6.xcode
输入命令查看是否:
$ xcodebuild -version
Xcode 15.4
Build version 15F31d
command_line
$ xcode-select --print-path
/Applications/Xcode.app/Contents/Developer
2.Node&NPM
有些软件安装卸载等需要权限才可以操作:
sudo npm uninstall -g appium
3.Carthage
4.Appium
安装:
sudo npm i -g appium
卸载:
sudo npm uninstall -g appium
Password: 《----输入你电脑的密码
验证是否安装:
appium --version
输入命令,启动:appium
[Appium] Available drivers:
[Appium] - uiautomator2@3.7.6 (automationName 'UiAutomator2')
[Appium] - xcuitest@7.24.12 (automationName 'XCUITest')
安装 Appium Drivers
sudo appium driver install xcuitest
查看是否安装好:
appium driver list --installed
查看webdriverAgent安装目录
指令:appium driver run xcuitest open-wda
显示对应的WebDriverAgent.xcodeproj路径并用xcode打开WebDriverAgent.xcodeproj
安装完之后要配置WebDriverAgent.xcodeproj
1.进入WebDriverAgent.xcodeproj目录文件夹,需要变更文件夹的权限
右键打开“显示简介”
解锁,点击+添加当前用户读和写的权限,点击……选择目录下面的文件相同权限
2.终端输入这个指令,用xcode打开编辑:appium driver run xcuitest open-wda
下图圈起来的地方要配置 和勾选
add Account点击完之后添加账户,点击+添加Apple ID,选择一个Team,点击下载download manual profiles,点击Manage Certificates添加证书
这一步骤忽略-------》这是之前执行失败,下载过好多证书,把之前的证书都删除掉的操作
这步忽略---〉先进入钥匙串里面的选择对应的证书删除
这步忽略-----》然后进入苹果账号里面--》证书,revoke,这个我把我相关的都删除
安装Appium-Python-Client
pip install Appium-Python-Client
安装包错,使用如下指令:
pip3 install Appium-Python-Client --break-system-packages
xcode构建运行,test,还是报错:重启电脑和手机
5.pycharm
6.Appium-Doctor
ios-deploy
安装ios-deploy,这是支持使用命令行管理 iOS 设备 app 的工具
npm install -g ios-deploy
查看IOS的安装环境:
appium-doctor --ios
遇到的问题:
idb一直安装失败:
卸载掉重新安装:
pip3.x uninstall fb-idb
brew uninstall idb-companion
brew untap facebook/fb
重新安装:
brew tap facebook/fb
brew install idb-companion
sudo pip3.12 install fb-idb --break-system-packages
检查是否安装好:idb list-targets
查看安装目录:which idb
7.ideviceinstaller&libimobiledevice
1、安装libimobiledevice,这是用于连接 iOS 设备的开源工具,类似于 Android 的 ADB
brew install libimobiledevice --HEAD
8.ios_webkit_debug_proxy
配置:https://www.cnblogs.com/dreamhighqiu/p/11023363.html
# 运行命令后会显示如下:
$ iproxy 8100 8100
waiting for connection
浏览器打开地址:http://localhost:8100/status
9.authroize_ios
遇到的问题:
问题1:
Failed to create session. An unknown server-side error occurred while processing the command. Original error: Unable to launch WebDriverAgent. Original error: xcodebuild failed with code 74. This usually indicates an issue with the local Xcode setup or WebDriverAgent project configuration or the driver-to-platform version mismatch. Consider checking the WebDriverAgent configuration guide for real iOS devices at https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md.. Make sure you follow the tutorial at https://appium.github.io/appium-xcuitest-driver/latest/preparation/real-device-config/
)))重新插拔一下设备
问题2
Failed to create session. An unknown server-side error occurred while processing the command. Original error: Could not find a driver for automationName 'XCUITest' and platformName 'iOS'. Have you installed a driver that supports those capabilities? Run 'appium driver list --installed' to see. (Lower-level error: Cannot find module '/Users/weisun/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent/build/index.js'. Please verify that the package.json has a valid "main" entry)
)))重新安装:sudo npm install appium-xcuitest-driver
问题3:
Error: Cannot find module '/Users/weisun/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent/build/index.js'. Please verify that the package.json has a valid "main" entry
))))解决:卸载appium 下面的xcuitest,重新安装
问题4:
Failed to create session. An unknown server-side error occurred while processing the command. Original error: Unknown device or simulator UDID: '0000……
或者
解决:
)))插拔一下设备or重启电脑
问题5:
Failed to create session. An unknown server-side error occurred while processing the command. Original error: Unable to launch WebDriverAgent. Original error: xcodebuild failed with code 70. This usually indicates an issue with the local Xcode setup or WebDriverAgent project configuration or the driver-to-platform version mismatch. Consider checking the WebDriverAgent configuration guide for real iOS devices at https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md.. Make sure you follow the tutorial at https://appium.github.io/appium-xcuitest-driver/latest/preparation/real-device-config/
)))
1.按照网上的教程下载:webdriverAgent ,然后用xcode打开WebDriverAgent.xcodeproj,配置
选择webdriverrunner,真机,运行build,test,然后打开链接,链接打不开参考这个:https://www.cnblogs.com/dreamhighqiu/p/11023363.html
2.然后把/Users/weisun/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent这个目录下面的文件都替换掉,上面下载的
圈起来的目录都替换掉,然后刚刚的teamid生成的证书记得导出
3.终端进入下面目录:
/Users/weisun/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent
执行一下指令:
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=00008101-001318122189001E' test
4.https://github.com/appium/appium/issues/19706
5.脚本命令运行:
cd /Users/weisun/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=00008101-001318122189001E' test
6.配置项错误,值写错
问题6:
Failed to create session. An unknown server-side error occurred while processing the command. Original error: Unable to launch WebDriverAgent. Original error: xcodebuild failed with code 65. This usually indicates an issue with the local Xcode setup or WebDriverAgent project configuration or the driver-to-platform version mismatch. Consider checking the WebDriverAgent configuration guide for real iOS devices at https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md.. Make sure you follow the tutorial at https://appium.github.io/appium-xcuitest-driver/latest/preparation/real-device-config/
)))
解决:用目录打开安装的webdriverAgent.xcodeproj
appium driver run xcuitest open-wda
1. inspector里面的配置:appium:xcodeOrgId是否填写正确是TeamId
2.https://appium.github.io/appium-xcuitest-driver/latest/preparation/real-device-config/
3.配置重复了,webdriverAgent配置过之后,Appium inspector里面的配置项就不要添加 teamid等信息
问题3: 执行后包错Command Analyze failed with a nonzero exit code
1)清理xcode缓存,重启mac电脑
2)执行Intergration app runner
问题4:手机要安装对应的app bundleid的app
问题5:
esting failed:
Test target WebDriverAgentRunner encountered an error (The bundle identifier for WebDriverAgentRunner-Runner.app couldn’t be read. The application may be damaged or incomplete: “/Users/weisun/Library/Developer/Xcode/DerivedData/WebDriverAgent-cjzswfqawlndrcdbvvaqkpcctujg/Build/Products/Debug-iphoneos/WebDriverAgentRunner-Runner.app”.)
)))编译一下IntegrationApp就OK了
最后问题解决看这边:https://github.com/appium/appium/issues/20450