一、前置安装
1.JDK 安装教程传送门
1.1安装前先执行如下命令看是否已经安装
java -version
如果已经安装会显示对应的版本号(各个版本信息不一样)
openjdk version "11.0.16.1" 2022-08-12
OpenJDK Runtime Environment Homebrew (build 11.0.16.1+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.16.1+0, mixed mode)
2.Homebrew 安装教程传送门
2.1安装前先执行如下命令看是否已经安装
brew -v
如果已经安装会显示对应的版本号
Homebrew 3.6.15
Homebrew/homebrew-core (git revision c749c5d4681; last commit 2022-12-13)
3.Node 安装教程传送门
3.1安装前先执行如下命令看是否已经安装
node -v
如果已经安装会显示对应的版本号
v19.2.0
4.Xcode 下载地址
下载并安装
5.Appium-Server-GUI
5.1Appium-Server-GUI 下载地址
下载并安装
6.Appium-Inspector 下载地址
下载并安装
7.安装相关依赖
brew install --HEAD ideviceinstaller
brew install --HEAD libimobiledevice
brew install ios-deploy
brew install carthage
执行前两条命令时可能会出现“常见问题 - 2”
8.安装appium-doctor并检查环境是否安装成功
安装命令:
nmp install -g appium-doctor
检查命令:
appium-doctor --ios
成功如下:
WARN AppiumDoctor [Deprecated] Please use appium-doctor installed with "npm install @appium/doctor --location=global"
info AppiumDoctor Appium Doctor v.1.16.2
info AppiumDoctor ### Diagnostic for necessary dependencies starting ###
info AppiumDoctor ✔ The Node.js binary was found at: /usr/local/bin/node
info AppiumDoctor ✔ Node version is 19.2.0
info AppiumDoctor ✔ Xcode is installed at: /Applications/Xcode.app/Contents/Developer
info AppiumDoctor ✔ Xcode Command Line Tools are installed in: /Applications/Xcode.app/Contents/Developer
info AppiumDoctor ✔ DevToolsSecurity is enabled.
info AppiumDoctor ✔ The Authorization DB is set up properly.
info AppiumDoctor ✔ Carthage was found at: /usr/local/bin/carthage. Installed version is: 0.38.0
info AppiumDoctor ✔ HOME is set to: /Users/geenju
info AppiumDoctor ### Diagnostic for necessary dependencies completed, no fix needed. ###
info AppiumDoctor
info AppiumDoctor ### Diagnostic for optional dependencies starting ###
WARN AppiumDoctor ✖ opencv4nodejs cannot be found.
WARN AppiumDoctor ✖ ffmpeg cannot be found
WARN AppiumDoctor ✖ mjpeg-consumer cannot be found.
WARN AppiumDoctor ✖ set-simulator-location is not installed
WARN AppiumDoctor ✖ idb and idb_companion are not installed
WARN AppiumDoctor ✖ applesimutils cannot be found
info AppiumDoctor ✔ ios-deploy is installed at: /usr/local/bin/ios-deploy. Installed version is: 1.12.1
info AppiumDoctor ### Diagnostic for optional dependencies completed, 6 fixes possible. ###
info AppiumDoctor
info AppiumDoctor ### Optional Manual Fixes ###
info AppiumDoctor The configuration can install optionally. Please do the following manually:
WARN AppiumDoctor ➜ Why opencv4nodejs is needed and how to install it: http://appium.io/docs/en/writing-running-appium/image-comparison/
WARN AppiumDoctor ➜ ffmpeg is needed to record screen features. Please read https://www.ffmpeg.org/ to install it
WARN AppiumDoctor ➜ mjpeg-consumer module is required to use MJPEG-over-HTTP features. Please install it with 'npm i -g mjpeg-consumer'.
WARN AppiumDoctor ➜ set-simulator-location is needed to set location for Simulator. Please read https://github.com/lyft/set-simulator-location to install it
WARN AppiumDoctor ➜ Why idb is needed and how to install it: https://github.com/appium/appium-idb
WARN AppiumDoctor ➜ Why applesimutils is needed and how to install it: http://appium.io/docs/en/drivers/ios-xcuitest/
info AppiumDoctor
info AppiumDoctor ###
info AppiumDoctor
info AppiumDoctor Bye! Run appium-doctor again when all manual fixes have been applied!
info AppiumDoctor
9.配置WebDriverAgent
9.1切换到Appium Server GUI.app的内部
cd /Applications/Appium\ Server\ GUI.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent/Scripts
9.2初始化
执行
node ./Scripts/build-webdriveragent.js
9.配置WebDriverAgent
9.1下载WebDriverAgent下载链接
ps:不使用桌面版App内部的WebDriverAgent是因为App自带的WebDriverAgent版本过低,在高版本的xcode中存在私有库的问题
切换到对应目录:
cd /Users/geenju/Downloads/WebDriverAgent-4.10.12
install
npm install
运行结果如下:
geenju@192 WebDriverAgent-4.10.12 % npm install
> appium-webdriveragent@4.10.12 prepare
> npm run build
> appium-webdriveragent@4.10.12 build
> rm -rf build && babel --out-dir=build/lib lib && babel --out-dir=build index.js
Successfully compiled 7 files with Babel (910ms).
Successfully compiled 1 file with Babel (316ms).
up to date in 5s
4 packages are looking for funding
run `npm fund` for details
build
node ./Scripts/build-webdriveragent.js
运行结果如下:
geenju@192 WebDriverAgent-4.10.12 % node ./Scripts/build-webdriveragent.js
info WDABuild Building bundle for Xcode version '14.1'
info WDABuild Clearing contents of '/Users/geenju/Library/Developer/Xcode/DerivedData/WebDriverAgent-*'
info WDABuild Deleting existing WDA: '/Users/geenju/Library/Developer/Xcode/DerivedData/WebDriverAgent-aghlrsejdreqngftgvcqwnjgrbou'
info WDABuild Deleting existing WDA: '/Users/geenju/Library/Developer/Xcode/DerivedData/WebDriverAgent-cqfondjuinztahbtdxmcopqafpmt'
info WDABuild Running ./Scripts/build.sh
info WDABuild Creating zip
info WDABuild Zip bundled at "/Users/geenju/Downloads/WebDriverAgent-4.10.12/bundles/webdriveragent-xcode_14.1.zip"
info WDABuild Created './WebDriverAgentRunner-Runner.app.zip'
info WDABuild Zip bundled at "/Users/geenju/Downloads/WebDriverAgent-4.10.12/WebDriverAgentRunner-Runner.app.zip"
打开xcode工程
open ./WebDriverAgent.xcodeproj
修改TARGETS下WebDriverAgentRunner、WebDriverAgentRunner_tvOS、UnitTests、UnitTests_tvOS、IntegrationTests_1、IntegrationTests_2、IntegrationTests_3、IntegrationApp对应的包名及其证书
完成后编译并在真机上运行
631670939864_.pic.jpg
打开手机“设置”-“开发者” 启用Enable UI Automation
641670940238_.pic.jpg651670940238_.pic.jpg
至此已完成准备工作
二、使用Appium
1确保PC和iphone在同一个网络下且均能访问外网
2通过如下命令获取iphone的udid等信息:
ios-deploy -c
运行如下:
[....] Waiting up to 5 seconds for iOS device to be connected
[....] Found 00008101-000941643E03001E (D53gAP, iPhone 12, iphoneos, arm64e, 16.1.1, 20B101) a.k.a. 'android' connected through USB.
3.通过如下命令获取设备上所有app的bundleId信息
ios-deploy --id 替换成你的udid --list_bundle_id
运行结果如下:
[....] Waiting for iOS device to be connected
[....] Using 00008101-000941643E03001E (D53gAP, iPhone 12, iphoneos, arm64e, 16.1.1, 20B101) a.k.a. 'android'.
com.apple.FCAuthenticationUI
com.apple.Health
com.cmbchina.MPBBank
com.apple.Magnifier
...
4启动iPhone 上的WebDriverAgentRunner
5启动Appium Server GUI
image.png启动成功后如下图所示:
image.png
6启动Appium Inspector
image.png以上参数即为ios-deploy获得的,
打开代测试App即可
image.png
常见问题:
1.Could not determine Xcode version
org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: Could not determine Xcode version: Could not get Xcode version. /Library/Developer/Info.plist does not exist on disk.
解决方案:
sudo xcode-select --reset
sudo xcode-select --switch /Applications/Xcode.app
2.macOS brew install 404:Bottle missing, falling back to the default domain
解决方案:
针对zsh用户:
#更新镜像源
echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"' >> ~/.zshrc
#更新bottle源
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles
#更换为默认的镜像源
unset HOMEBREW_BREW_GIT_REMOTE
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew
#立即生效
source ~/.zshrc
针对bash用户:
#更新镜像源
echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"' >> ~/.bashrc
#更新bottle源
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles
#更换为默认的镜像源
unset HOMEBREW_BREW_GIT_REMOTE
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew
#立即生效
source ~/.bashrc
网友评论