appium環境搭建可參考以下兩個鏈接:
https://www.jianshu.com/p/a2b79cd8bf38
https://www.jianshu.com/p/3c04e029c3ea
環境配置:
carthage: stable 0.31.2 (bottled), HEAD
usbmuxd: stable 1.0.10 (bottled), HEAD
libimobiledevice: stable 1.2.0 (bottled), HEAD
npm 6.4.1
ios-deploy 1.9.4
xcpretty 0.3.0
appium-doctor 1.6.0
Appium v1.9.1
Python 3.7
WebDriverAgent 用GitHub的[https://github.com/facebook/WebDriverAgent ]
Xcode10.1
每次真機開發啓動順序:
1.先在終端啓動WDA(或者直接用XCode直接【WebDriverAgentRunner】-【testing】也行)
xcodebuild build-for-testing test-without-building -project /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination id=設備ID test
進行端口轉發
iproxy 8100 8100 設備ID
-
啓動Appium Server
配置信息:
"deviceName": "iPhone 6s",
"platformName": "ios",
"udid": "601861ce25a7dae4dc3d12e6f43cd42936XXXXXX",
"automationName": "XCUITest",
"xcodeOrgId": " 7GTPKLXXXX",
"xcodeSigningId": "iPhone Developer",
"no-reset": true,
"startIWDP": true,
"bundleId": "com.XXXXXX"
- 通過元素定位器進行定位
- python通過appium進行腳本編寫
遇到的坑:
- 運行安裝WebDriverAgent驗證是否安裝成功:
export DEVICE_URL='http://localhost:8100'
export JSON_HEADER='-H "Content-Type: application/json;charset=UTF-8, accept: application/json"'
curl -X GET $JSON_HEADER $DEVICE_URL/status
或
http://localhost:8100/status
如果單純WebDriverAgent運行成功,然後appuim沒有反應,可能因爲有些國產的iPhone設備通過手機的IP和端口還不能訪問,此時需要將手機的端口轉發到Mac上 :
終端輸入:iproxy 8100 8100 <DeviceUDID>
- 如果存在多個版本Xcode,在安裝brew包的時候,會出現兼容性問題,可以通過切換來處理
sudo xcode-select --switch /Applications/Xcode9.4.1.app
sudo xcode-select --switch /Applications/Xcode.app
- 兩個wda模塊地址
1、在命令行安裝appium的時候已經集成了wda模塊
/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/WebDriverAgent.xcodeproj
2、使用appium desktop的wda模塊
/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent
出現報錯:A new session could not be created. Details: Appium's IosDriver does not support Xcode version 9.4.1. Apple has deprecated UIAutomation. Use the "XCUITest" automationName capability instead.
解決辦法:添加 automationName = XCUITest出現報錯:An unknown server-side error occurred while processing the command. Original error: Unknown device or simulator UDID
解決辦法:安裝libimobiledevice
brew install --HEAD libimobiledevice
- 出現報錯:Requested 'libusbmuxd >= 1.1.0' but version of libusbmuxd is 1.0.10
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables libusbmuxd_CFLAGS
and libusbmuxd_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
解決辦法:
brew update
brew uninstall --ignore-dependencies libimobiledevice
brew uninstall --ignore-dependencies usbmuxd
brew install --HEAD usbmuxd
brew unlink usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
- 出現報錯urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=4723): Max retries exceeded with url: /wd/hub/session (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x109c28908>: Failed to establish a new connection: [Errno 61] Connection refused'))
解決辦法:打開appium-desktop