環(huán)境搭建目錄
前提環(huán)境
python
selenium
setuptools,pip
通用環(huán)境
Homebrew
Node & NPM
Carthage
Appium
Appium Doctor
iOS 環(huán)境
Xcode
ios-deploy
ideviceinstaller & libimobiledevice
ios_webkit_debug_proxy
一、前提環(huán)境配置
安裝python
下載python進(jìn)行安裝https://www.python.org/,默認(rèn)安裝,安裝好之后,打開終端,輸入python,如提示不是內(nèi)部命令,則將python安裝目錄添加到環(huán)境變量Path中。
安裝setuptools,pip
下載setuptools,pip https://pypi.python.org/pypi/setuptools https://pypi.python.org/pypi/pip
打開cmd 進(jìn)入setuptools解壓目錄,輸入:python setup.py install 進(jìn)入pip解壓目錄,輸入:python setup.py install 安裝好后,打開終端,輸入pip,如提示不是內(nèi)部命令,則將python安裝目錄下Scripts目錄添加到環(huán)境變量Path中。
安裝selenium
終端輸入pip install Selenium安裝最新版本的selenium。
pip install Selenium 如需安裝指定的版本,則pip install Selenium==版本號(hào)。
pip install Selenium==版本號(hào)
二、通用環(huán)境配置
安裝 Homebrew
Homebrew是一個(gè)包管理軟件,它可以使我們更容易地安裝其他一些軟件,終端輸入安裝:
安裝
MacBook-Air ~ % /bin/bash -c "(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
重新安裝
MacBook-Air ~ % /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
檢查homebrew是否安裝
MacBook-Air ~ % brew -v
MacBook-Air ~ % brew list //查看已安裝列表
MacBook-Air ~ % brew update //更新Homebrew

如果安裝失?。ňW(wǎng)速不行等。。),可以打開網(wǎng)址:http://vip.ytesting.com/q.do?a&id=ff80808172521d8201726a74986f0880 將其內(nèi)容保存為homebrew.txt,然后終端輸入:
MacBook-Air ~ % /usr/bin/ruby homebrew.txt
注意:此步驟還順帶安裝了Xcode命令行工具(xcode-commaindline-tools)。
安裝 Node & NPM
Node是一個(gè)javascript運(yùn)行時(shí)環(huán)境,npm是節(jié)點(diǎn)包管理器。我們需要這些,因?yàn)锳ppium是一個(gè)節(jié)點(diǎn)應(yīng)用程序。在終端中,輸入以下命令(此命令也將安裝npm):
安裝
MacBook-Air ~ % brew install node
查看node版本
MacBook-Air ~ % node -v
重新安裝:
MacBook-Air ~ % brew reinstall node


默認(rèn)的npm源再國(guó)內(nèi)都很慢,安裝好node之后需要重新配置一個(gè)國(guó)內(nèi)源
MacBook-Air ~ % npm config set registry https://registry.npm.taobao.org/
MacBook-Air ~ % npm -v


安裝 Carthage
Carthage是一個(gè)依賴管理器,類似于java的maven,WebDriverAgent需要它,終端輸入:
安裝carthage
MacBook-Air ~ % brew install carthage
更新carthage
MacBook-Air ~ % brew upgrade carthage
重新安裝:
MacBook-Air ~ % brew reinstall carthage
安裝完成后檢查一下是否安裝成功
MacBook-Air ~ % carthage version //打印出版本號(hào)即表示安裝成功

如果安裝
carthage出現(xiàn)以下錯(cuò)誤:Error: An unexpected error occurred during the
brew link stepThe formula built, but is not symlinked into /usr/local
Permission denied @ dir_s_mkdir - /usr/local/Frameworks
Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
原因是
carthage已經(jīng)安裝,但是沒(méi)有 link 到 brew,還有就是文件夾權(quán)限問(wèn)題,在終端輸入:MacBook-Air ~ % sudo mkdir /usr/local/Frameworks
MacBook-Air ~ % sudo chown $(whoami):admin /usr/local/Frameworks
MacBook-Air ~ % brew link carthage
安裝 Appium(二選1)
Appium(Version 1.13)是一個(gè)用于本地、混合和移動(dòng)web應(yīng)用程序的開源測(cè)試自動(dòng)化框架。它使用WebDriver協(xié)議驅(qū)動(dòng)iOS、Android和Windows mobile應(yīng)用程序。
方式1:安裝桌面版 appium-server(推薦)
桌面版包含了appium-server,同時(shí)也包含一個(gè)元素定位器,建議安裝桌面版。
進(jìn)入官網(wǎng)下載

MacBook-Air ~ % git clone https://github.com/appium/appium-desktop.git

其他版本:進(jìn)入官網(wǎng)下載1.17.1

方式2:安裝 appium-server 版
1、安裝 appium-server
終端安裝server版輸入:
MacBook-Air ~ % npm install -g appium
默認(rèn)安裝最新的版本,如果想安裝指定的版本:
MacBook-Air ~ % npm install -g appium@1.7.2
卸載 Appium:
MacBook-Air ~ % npm uninstall -g appium
MacBook-Air ~ % npm cache clean --force
安裝appium client
appium主站上給出的命令是npm install wd 這應(yīng)該是老版本的安裝方法:
MacBook-Air ~ % npm install wd # get appium client
MacBook-Air ~ % npm wd -v # 檢查是否安裝成功。
推薦下面的方法進(jìn)行安裝:
安裝python-client
MacBook-Air ~ % git clone git@github.com:appium/python-client.git # 下載python-client
MacBook-Air ~ % cd python-client # 進(jìn)入python-client目錄
MacBook-Air ~ % python setup.py install # 安裝python-client
安裝成功:
Finished processing dependencies for Appium-Python-Client==0.30 # 表示安裝成功,安裝版本0.30
安裝appium-doctor:
1、安裝appium-doctor
終端運(yùn)行appium-doctor檢查appium安裝是否成功
MacBook-Air ~ % npm install appium-doctor -g
MacBook-Air ~ % node your-appium-test.js
2、檢查appium安裝版本
appium doctor用來(lái)檢查appium的是否成功安裝。手動(dòng)下載安裝appium doctor的網(wǎng)址在:https://github.com/appium/appium-doctor
MacBook-Air ~ % appium -v # 安裝完成之后輸入appium -v,顯示版本號(hào)表示appium server安裝成功
3、啟動(dòng)appium服務(wù)
在終端輸入appium &。輸出下面的信息,則表示appium server啟動(dòng)成功了。
MacBook-Air ~ % appium &
[1] 965$ [Appium] Welcome to Appium v1.9.1
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
在終端輸入:appium-doctor --ios 檢查 iOS環(huán)境環(huán)境
其中的 WARN(警告)不用管:

iOS自動(dòng)化 必要 環(huán)境配置沒(méi)有問(wèn)題
配置jdk+Android SDK 環(huán)境配置--針對(duì)Android
查看所有 必要 配置環(huán)境是否成功


打開.bash_profile
MacBook-Air ~ % open .bash_profile
Setting PATH for SDK
export ANDROID_HOME=/Users/用戶名/Library/Android/sdk
export PATH=PATH
export PATH=PATH
Setting PATH for Jdk
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/Contents/Home
export PATH=PATH
export CLASSPATH=.:JAVA_HOME/lib/tools.jar
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
關(guān)閉保存后,更新.bash_profile
MacBook-Air ~ % source .bash_profile
在終端輸入:appium-doctor --Android 檢查 Android環(huán)境環(huán)境

安裝完成后,終端輸入appium-doctor 檢測(cè)環(huán)境是否成功(查詢結(jié)果顯示?表示沒(méi)有配置,需要配置,查看需要設(shè)置的必要環(huán)境)。
安裝appium-doctor,android方面的環(huán)境需要:
必選項(xiàng)—— ANDROID_HOME、JAVA_HOME、adb、android、emulator
其中的警告不用管
appium-doctor # 默認(rèn)安裝路徑:/usr/local/lib/node_modules/appium/node_modules/
IOS自動(dòng)化環(huán)境配置
安裝Xcode和模擬器
啟動(dòng)Mac應(yīng)用程序商店并下載/安裝Xcode(Version 13.1)。安裝之后,啟動(dòng)Xcode并選擇 Xcode > Preferences > Components 來(lái)安裝可能想要測(cè)試的模擬器。

安裝Command Line Tools
默認(rèn)是不會(huì)安裝Command Line Tools的,Command Line Tools是在Xcode中的一款工具,可以在命令行中運(yùn)行C程序。為了配置appium環(huán)境,我們需要安裝Xcode Command Line Tools。
官網(wǎng)下載

下載完成后,雙擊已下載的 .dmg 進(jìn)行安裝
檢驗(yàn) Command Line Tools 是否安裝成功
方法一:
MacBook-Air ~ % xcode-select --install # 查看是否安裝
xcode-select: error: command line tools are already installed, use "Software Update" to install updates(錯(cuò)誤:命令行工具已經(jīng)安裝,請(qǐng)使用“軟件更新”安裝更新)
方法二:打開Xcode,創(chuàng)建一個(gè)新的項(xiàng)目,在OSX下面選擇Application,如果右側(cè)出現(xiàn)Command line tool圖標(biāo),表示已經(jīng)安裝成功。

方法三:打開XCode 新建工程,如果安裝了,在新建窗口可以看到

安裝完成后,在終端中輸入以下命令來(lái)查看安裝版本:
MacBook-Air ~ % xcodebuild -version
Xcode 11.6
如果已經(jīng)安裝過(guò)xcode,appium-doctor提示未安裝,則運(yùn)行命令即可:
MacBook-Air ~ % sudo xcode-select -r
Tips:
查看已啟動(dòng)的模擬器udid
xcrun simctl list | grep '(Booted)'
列出所有設(shè)備,包括真機(jī)、模擬器、mac
instruments -s devices
錄像功能
xrecord --quicktime --list
xrecord --quicktime --name="iPhone" --out="/Users/blah/video/iphone.mp4" --force
安裝 libimobiledevice & ideviceinstaller
libimobiledevice 是一個(gè)跨平臺(tái)的軟件庫(kù),支持 iPhone?, iPod Touch?, iPad? and Apple TV? 等設(shè)備的通訊協(xié)議。不依賴任何已有的私有庫(kù),不需要越獄。應(yīng)用軟件可以通過(guò)這個(gè)開發(fā)包輕松訪問(wèn)設(shè)備的文件系統(tǒng)、獲取設(shè)備信息,備份和恢復(fù)設(shè)備,管理 SpringBoard 圖標(biāo),管理已安裝應(yīng)用,獲取通訊錄、日程、備注和書簽等信息,使用 libgpod 同步音樂(lè)和視頻。 ideviceinstaller 是一個(gè)與iOS設(shè)備的installation_proxy交互的工具,允許安裝、升級(jí)、卸載、存檔、還原和列舉已安裝或存檔的app。此工具用于在真機(jī)上運(yùn)行測(cè)試,默認(rèn)是都安裝的。
MacBook-Air ~ % brew install libimobiledevice --HEAD # 安裝最新的更新
MacBook-Air ~ % brew reinstall libimobiledevice # 重新安裝
MacBook-Air ~ % brew install ideviceinstaller # 用于查看bundleid
MacBook-Air ~ % brew reinstall ideviceinstaller # 重新安裝
如果安裝時(shí)遇到: “invalid active developer path” 則運(yùn)行:
MacBook-Air ~ % xcode-select --install
MacBook-Air ~ % sudo xcode-select -r
可能出現(xiàn)的問(wèn)題
dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib Referenced from:
/usr/local/opt/libimobiledevice/lib/libimobiledevice.6.dylib Reason: image not found
如果遇到如上錯(cuò)誤,則先卸載ideviceinstaller 和 libimobiledevice
MacBook-Air ~ % brew uninstall ideviceinstaller
MacBook-Air ~ % brew uninstall libimobiledevice
然后再重安裝即可
安裝 ios-deploy
ios-deploy 同樣是一個(gè)不需要用Xcode安裝和調(diào)試應(yīng)用的命令行工具。需要一個(gè)有效的開發(fā)者證書,需要 Xcode 7以上的版本。終端輸入命令進(jìn)行安裝:
MacBook-Air ~ % brew install ios-deploy # 安裝命令
MacBook-Air ~ % brew reinstall ios-deploy # 重新安裝
MacBook-Air ~ % brew upgrade ios-deploy # 更新命令

安裝 ios_webkit_debug_proxy
Appium使用ios_webkit_debug_proxy這個(gè)工具在真機(jī)上訪問(wèn)web view。在終端中,運(yùn)行以下命令:
MacBook-Air ~ % brew install ios-webkit-debug-proxy # 安裝命令
MacBook-Air ~ % brew reinstall ios-webkit-debug-proxy # 重新安裝
至此iOS環(huán)境搭建完畢?。?!只適用于模擬器,真機(jī)的話還需要配置。
iOS真機(jī)調(diào)試環(huán)境配置
編譯webagentrunner項(xiàng)目,安裝到被測(cè)真實(shí)設(shè)備上
查看appium的安裝位置,正常npm安裝的位置應(yīng)該在/usr/local/bin/appium下
MacBook-Air ~ % which appium
/usr/local/bin/appium (命令版安裝)
命令行安裝的appium一般安裝在/usr/local/bin/appium下,WebDriverAgent將會(huì)在路徑:/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/ 下;如果是桌面版的,WebDriverAgent的路徑是:ls /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent
命令行版
MacBook-Air ~ % cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/
桌面版
MacBook-Air ~ % cd /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent

首先查看路徑(/usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent)下有沒(méi)有WebDriverAgent.xcodeproj(有的話跳過(guò)下邊,直接用Xcode打開即可)

2)如果/usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent 沒(méi)有WebDriverAgent.xcodeproj存在,則打開終端運(yùn)行如下命令搭建項(xiàng)目:
MacBook-Air ~ % cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/
MacBook-Air ~ % mkdir -p Resources/WebDriverAgent.bundle
MacBook-Air ~ % ./Scripts/bootstrap.sh -d
然后用Xcode 打開
WebDriverAgent.xcodeproj,在 “Signing&Capabilities” 下將 WebDriverAgentLib 和 WebDriverAgentRunner設(shè)置成 “Automatically manage signing” 并在 “Team” 中選擇你的開發(fā)團(tuán)隊(duì) ;

新用戶第一次需要?jiǎng)?chuàng)建Team團(tuán)隊(duì)





個(gè)人證書調(diào)試失敗
Failed to register bundle identifier.
The app identifier "com.facebook.WebDriverAgentRunner" cannot be registered to your development team because it is not available. Change your bundle identifier to a unique string to try again.
需要手動(dòng)更改目標(biāo)的bundle id,方法是進(jìn)入“Build Settings”選項(xiàng),更改“Product bundle Identifier”的值使Xcode將接受,默認(rèn)為com.facebook.WebDriverAgentRunner,你需要改成不一樣的,如:io.automation.WebDriverAgentRunner

返回 “Signing&Capabilities” 選項(xiàng),看到對(duì)于文件WebDriverAgentRunner的配置文件已經(jīng)創(chuàng)建成功了


解決??問(wèn)題

真機(jī)測(cè)試
最后,build項(xiàng)目: 通過(guò)Xcode獲取udid:
利用ios-deploy獲取,其他參考上邊的介紹
MacBook-Air ~ % ios-deploy -c

命令行進(jìn)入到WDA項(xiàng)目目錄
MacBook-Air ~ % cd /usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent
將WDA安裝到被測(cè)手機(jī)上,并測(cè)試該應(yīng)用
MacBook-Air ~ % xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=<測(cè)試機(jī)的udid>' test

報(bào)錯(cuò):
error: No profiles for 'io.uitest.WebDriverAgentRunner.xctrunner' were found: Xcode couldn't find any iOS App Development provisioning profiles matching 'io.uitest.WebDriverAgentRunner.xctrunner'. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass -allowProvisioningUpdates to xcodebuild. (in target 'WebDriverAgentRunner' from project 'WebDriverAgent')報(bào)這個(gè)錯(cuò)是因?yàn)闆](méi)有接入相關(guān)的設(shè)備到MAC上,只要設(shè)備接入,并通過(guò)XCode菜單:Product->Destnation->"Select Devices"選中要連接的設(shè)備就行。
XCode:
Product->Destination->"Select your iphone"

Product->Scheme->"Select WebDriverAgentRunner"

Product -> Test

注意:運(yùn)行Test之前,手機(jī)先解鎖再通過(guò)USB線連接到電腦。
運(yùn)行完"Test",如果遇到這個(gè)報(bào)錯(cuò):
運(yùn)行報(bào)錯(cuò):

/usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj User-supplied CFBundleIdentifier value 'com.facebook.wda.lib' in the Info.plist must be the same as the PRODUCT_BUNDLE_IDENTIFIER build setting value 'com.facebook.WebDriverAgentLib'.
解決方案:

運(yùn)行報(bào)錯(cuò):

/usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent/WebDriverAgentLib/Vendor/RoutingHTTPServer/RoutingHTTPServer.h:16:9: 'CocoaAsyncSocket/GCDAsyncSocket.h' file not found
解決:進(jìn)入appium-webdriveragent目錄,重新執(zhí)行:
MacBook-Air % cd /usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent
MacBook-Air appium-webdriveragent % sh ./Scripts/bootstrap.sh

再次執(zhí)行Product -> Test,彈出密鑰授權(quán)彈窗,輸入密鑰(多次輸入密鑰,直到彈窗消失)


最后報(bào)錯(cuò):Command CodeSign failed with a nonzero exit code
解決方案---通過(guò)終端命令:MacBook-Air appium-webdriveragent % xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=000-000080E' test
執(zhí)行中會(huì)彈出密鑰彈窗,多次輸入密鑰,直到彈窗消失

最后機(jī)上可以看到一個(gè)沒(méi)有圖標(biāo)的 WebDriverAgentRunner.app 應(yīng)用,進(jìn)入設(shè)置 -》通用 -》設(shè)備管理 -》點(diǎn)擊 開發(fā)者app下面的證書 -》點(diǎn)擊“第一個(gè)藍(lán)色字體信任按鈕” -》點(diǎn)擊信任,再重新執(zhí)行項(xiàng)目即可正常連接
xcode點(diǎn)擊??直接運(yùn)行:

再次報(bào)錯(cuò):
/usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj User-supplied CFBundleIdentifier value 'com.facebook.wda.runner' in the Info.plist must be the same as the PRODUCT_BUNDLE_IDENTIFIER build setting value 'io.uitest.WebDriverAgentRunner'.
解決方案:

最終看到這樣輸出就是成功了:
Test Suite ‘All tests’ started at 2017-01-23 15:49:12.585
Test Suite ‘WebDriverAgentRunner.xctest’ started at 2017-01-23 15:49:12.586
Test Suite ‘UITestingUITests’ started at 2017-01-23 15:49:12.587
Test Case ‘-[UITestingUITests testRunner]’ started.
t = 0.00s Start Test at 2017-01-23 15:49:12.588
t = 0.00s Set Up
驗(yàn)證是否安裝成功,確保手機(jī)和電腦連接同一個(gè)WiFi(同一局域網(wǎng)內(nèi)),可以不設(shè)置這些內(nèi)容:
export DEVICE_URL='http://<device IP>:8100'
export JSON_HEADER='-H "Content-Type: application/json;charset=UTF-8, accept: application/json"'
curl -X GET DEVICE_URL/status
直接在手機(jī)瀏覽器中輸入這個(gè)地址http://127.0.0.1:8100/status返回一個(gè)json串即表明連接成功

安裝成功后運(yùn)行如果遇到這樣的錯(cuò)誤:
2017-01-24 09:02:18.358 xcodebuild[30385:339674] Error Domain=com.apple.platform.iphoneos Code=-12 "Unable to launch com.apple.test.WebDriverAgentRunner-Runner" UserInfo={NSLocalizedDescription=Unable to launch com.apple.test.WebDriverAgentRunner-Runner, NSUnderlyingError=0x7fa839cadc60 {Error Domain=DTXMessage Code=1 "(null)" UserInfo={DTXExceptionKey=The operation couldn’t be completed. Unable to launch com.apple.test.WebDriverAgentRunner-Runner because it has an invalid code signature, inadequate entitlements or its profile has not been explicitly trusted by the user. : Failed to launch process with bundle identifier 'com.apple.test.WebDriverAgentRunner-Runner'}}}
2017-01-24 09:02:18.358 xcodebuild[30385:339674] Error Domain=IDETestOperationsObserverErrorDomain Code=5 "Early unexpected exit, operation never finished bootstrapping - no restart will be attempted" UserInfo={NSLocalizedDescription=Early unexpected exit, operation never finished bootstrapping - no restart will be attempted}
Testing failed:
Test target WebDriverAgentRunner encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted)
至此iOS真機(jī)運(yùn)行環(huán)境mac端配置完畢
手機(jī)端設(shè)置
進(jìn)入設(shè)置,開發(fā)者選項(xiàng),允許UIautomator
Tips: 真機(jī)運(yùn)行務(wù)必添加這兩個(gè)參數(shù)到capabilities:
{
#xcodeOrgId 類似:TEST INTERNATIONAL
"xcodeOrgId": "<Team ID>",
#xcodeSigningId 是一個(gè)由Apple生成的唯一的10個(gè)字符的字符串,類似 6387P24J3L
"xcodeSigningId": "iPhone Developer"
}
這兩個(gè)字段獲取方式:
xcodeOrgId: 開發(fā)者組織代碼,是一串唯一的10位隨機(jī)字符串。查找方式:打開keychain,找到蘋果開發(fā)者對(duì)應(yīng)的證書,點(diǎn)進(jìn)去,找到Organizational Unit這項(xiàng),對(duì)應(yīng)的字符串就是了
xcodeSigningId:直接填 iPhone Developer
真機(jī)手動(dòng)配置補(bǔ)充
udid就是設(shè)備唯一識(shí)別碼了,查看方式參考上文,如果只連接了一臺(tái)設(shè)備可以設(shè)置為auto
理想情況下,appium會(huì)自動(dòng)注冊(cè)并編譯,但是如果有出現(xiàn)編譯失敗報(bào)錯(cuò)誤碼65的現(xiàn)象一般是由于找不到指定的開發(fā)者證書,需要我們手動(dòng)配置一下,配置之后再手動(dòng)編譯一次,下次再運(yùn)行的時(shí)候基本就可以了
第一次在手機(jī)構(gòu)建webdriveragent應(yīng)用時(shí),xcode需要訪問(wèn)keychain以獲取證書,輸入當(dāng)前mac用戶的登錄密碼,然后點(diǎn)擊 allow all 即可,如果連續(xù)彈出多次對(duì)話框就多次點(diǎn)擊 allow all
附錄
ios-deploy使用命令參考
安裝應(yīng)用
ios-deploy -c # 查看當(dāng)前鏈接的設(shè)備,獲取udid
xxx.app為 Xcode 編譯后的應(yīng)用安裝包路徑
ios-deploy --id [udid] --bundle [xxx.app] # 給指定設(shè)備安裝應(yīng)用,udid是蘋果設(shè)備唯一識(shí)別碼
卸載應(yīng)用
ios-deploy --id [udid] --uninstall_only --bundle_id [bundleId] # 給指定連接的設(shè)備卸載應(yīng)用
查看設(shè)備已安裝的應(yīng)用
ios-deploy --id [udid] --list_bundle_id # 查看設(shè)備安裝的所有應(yīng)用,包括系統(tǒng)應(yīng)用和第三方應(yīng)用
ios-deploy --id [udid] --exists --bundle_id # 指定設(shè)備檢查指定應(yīng)用是否已經(jīng)安裝
idevice命令用法參考
獲取設(shè)備的udid的幾種方法
idevice_id --list # 略寫為 -l 顯示當(dāng)前所連接設(shè)備的 udid
idevice_id -l # 顯示當(dāng)前所連接的設(shè)備[udid],包括 usb、WiFi 連接
instruments -s devices # 列出設(shè)備包括模擬器、真機(jī)及 mac 電腦本身
ideviceinfo # 可以在返回的數(shù)據(jù)中找到 udid
另外蘋果手機(jī) safari打開網(wǎng)址http://fir.im/udid 就看到了
安裝應(yīng)用
xxx.ipa為應(yīng)用在本地的路徑
ideviceinstaller -i apppath # 安裝apppath下的app
ideviceinstaller -u [udid] -i [xxx.ipa] # 給指定連接的設(shè)備安裝應(yīng)用
卸載應(yīng)用
bundleId為應(yīng)用的包名
ideviceinstaller -u [udid] -U [bundleId] # 給指定連接的設(shè)備卸載應(yīng)用
查看設(shè)備已安裝的應(yīng)用
ideviceinstaller -l #列出手機(jī)上所有用戶安裝的app
運(yùn)行某個(gè)app
idevicedebug run 'APP_BUNDLE_ID' # 可以直接launch某個(gè)app,當(dāng)然,這個(gè)app必須是你通過(guò)development證書build到手機(jī)上的才行
ideviceinstaller -u [udid] -l # 指定設(shè)備,查看安裝的第三方應(yīng)用
ideviceinstaller -u [udid] -l -o list_user # 指定設(shè)備,查看安裝的第三方應(yīng)用
ideviceinstaller -u [udid] -l -o list_system # 指定設(shè)備,查看安裝的系統(tǒng)應(yīng)用
ideviceinstaller -u [udid] -l -o list_all # 指定設(shè)備,查看安裝的系統(tǒng)應(yīng)用和第三方應(yīng)用
獲取設(shè)備信息
ideviceinfo -u [udid] # 指定設(shè)備,獲取設(shè)備信息
ideviceinfo -u [udid] -k DeviceName # 指定設(shè)備,獲取設(shè)備名稱:iPhone6s
idevicename -u [udid] # 指定設(shè)備,獲取設(shè)備名稱:iPhone6s
ideviceinfo -u [udid] -k ProductVersion # 指定設(shè)備,獲取設(shè)備版本:10.3.1
ideviceinfo -u [udid] -k ProductType # 指定設(shè)備,獲取設(shè)備類型:iPhone8,1
ideviceinfo -u [udid] -k ProductName # 指定設(shè)備,獲取設(shè)備系統(tǒng)名稱:iPhone OS
其他系統(tǒng)文件信息
idevicescreenshot # 截圖
ideviceinfo # 獲取設(shè)備所有信息
idevicesyslog # 獲取設(shè)備日志
idevicecrashreport -e test # 獲取設(shè)備 crashlog,test 是文件夾需新建
idevicediagnostics restart # (shutdown、sleep)管理設(shè)備狀態(tài) - 重啟、關(guān)機(jī)、睡眠等
安裝 JDK(android自動(dòng)化)
下載 Java jdk ,按步驟安裝,安裝完成后需要在.bash_profile設(shè)置 JAVA_HOME ,設(shè)置之前你可以通過(guò)下邊的命令查看Java的安裝路徑,terminal輸入:
/usr/libexec/java_home --v
輸出路徑:
/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home
通過(guò)vim 編輯.bash_profile文件,終端輸入:
vim ~/.bash_profile
按 i鍵進(jìn)入編輯模式,移動(dòng)到最下邊加入如下兩行(路徑為之前查看的):
[改為你自己的java_home路徑]
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home
export PATH=PATH
添加后按 Esc按鍵,輸入:wq保存并退出編輯。輸入使其生效(或重啟終端):
添加后按 Esc按鍵,輸入:wq保存并退出編輯。輸入使其生效(或重啟終端):
source ~/.bash_profile