Appium Mac 命令行安裝


試過很多方法都失敗,打算用命令行方式安裝。

准備工作:

 從 https://github.com/appium/appium下載appium版本的源碼(.tar)

 詳見github_Appium1.6.5

0. 安裝brew(如果已經安裝可以跳過這步)

ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"

https://brew.sh/index_zh-cn.html: 按照官網提示在命令行執行ruby腳本(mac自帶ruby)

1. 命令行安裝node:

brew install node

 2. cd 到 appium.tar的解壓后的路徑

 3.  安裝appium

npm install -g ./appium

 安裝后界面:

nalideMacBook-Pro:appium-1.6.5 nali$ npm install -g appium
npm WARN deprecated babel-core@5.8.24: Babel 5 is no longer being maintained. Upgrade to Babel 6.
npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated line-numbers@0.2.0: Copy its ~20 LOC directly into your code instead.
/usr/local/bin/appium -> /usr/local/lib/node_modules/appium/build/lib/main.js

> appium-chromedriver@2.11.2 install /usr/local/lib/node_modules/appium/node_modules/appium-chromedriver
> node install-npm.js

info Chromedriver Install Installing Chromedriver version '2.28' for platform 'mac' and architecture '64'
info Chromedriver Install Opening temp file to write chromedriver_mac64 to...
info Chromedriver Install Downloading https://chromedriver.storage.googleapis.com/2.28/chromedriver_mac64.zip...
info Chromedriver Install Writing binary content to /var/folders/gs/1rvd4dj94gn10btdfzmq50680000gn/T/201787-9541-1hmuws9.6gxs/chromedriver_mac64.zip...
info Chromedriver Install Extracting /var/folders/gs/1rvd4dj94gn10btdfzmq50680000gn/T/201787-9541-1hmuws9.6gxs/chromedriver_mac64.zip to /var/folders/gs/1rvd4dj94gn10btdfzmq50680000gn/T/201787-9541-1hmuws9.6gxs/chromedriver_mac64
info Chromedriver Install Creating /usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac...
info Chromedriver Install Copying unzipped binary, reading from /var/folders/gs/1rvd4dj94gn10btdfzmq50680000gn/T/201787-9541-1hmuws9.6gxs/chromedriver_mac64/chromedriver...
info Chromedriver Install Writing to /usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac/chromedriver...
info Chromedriver Install /usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac/chromedriver successfully put in place

> appium-selendroid-driver@1.6.2 install /usr/local/lib/node_modules/appium/node_modules/appium-selendroid-driver
> node ./bin/install.js

dbug AndroidDriver Getting Java version
info AndroidDriver Java version is: 1.8.0_144
info Selendroid Ensuring /usr/local/lib/node_modules/appium/node_modules/appium-selendroid-driver/selendroid/download exists

……

4.  命令行運行appium 檢查是否能夠啟動

nalideMacBook-Pro:appium-1.6.5 nali$ appium
[Appium] Welcome to Appium v1.6.5
[Appium] Appium REST http interface listener started on 0.0.0.0:4723

5. 驗證的第二種方式,安裝appium-doctor.

   詳見github_appium_doctor

  Appium 安裝過程中也會遇到下面的error問題,但是不影響。后續解決

切換到appium-doctor的目錄

npm install -g appium-doctor
 
# 裝好之后 檢測一下iOS的環境有沒有配置好 如果不加--ios 則檢測Android和iOS
appium-doctor --ios
 
# 它提示我缺少Xcode Command Line Tools和Carthage,那就補上
xcode-select --install
brew install carthage

 

7. 其他庫:

brew install libimobiledevice --HEAD
npm install -g ios-deploy   # for iOS 10+
gem install xcpretty #對真機需要xcpretty
gem 安裝速度慢可以更換鏡像源
gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/

第一次運行配置

不配置會出現xcodebuild exited with code '65' and signal 'null'錯誤

8. WebDriverAgent相關(大坑)【dmg 模式適用】

iOS 10+使用的是XCUITest,Appium使用的模塊是appium-xcuitest-driver,其中引用了Facebook提供的WDA方案來驅動iOS的測試。
裝Appium Desktop的時候,它里面帶了一個WebDriverAgent,但是這個自帶的是有問題的!會造成不能使用Inspector,卡了很久!從Facebook那里自己clone一份才是王道:

cd ~
git clone https://github.com/facebook/WebDriverAgent.git
cd WebDriverAgent
mkdir -p Resources/WebDriverAgent.bundle
./Scripts/bootstrap.sh    # 開始下載並編譯 編譯不應該報錯
 
 
cd /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/
rm -rf WebDriverAgent   # 把自帶的刪掉
ln -s ~/WebDriverAgent WebDriverAgent  # 用facebook的原版替換回去

經過了baidu和google,用以上方法解決了不能Inspect的問題。

在使用Appium時,需要把WDA裝到真機上,然后又會遇到證書的問題,我也不是很明白,總之跟provisioning profile有關。

用Xcode打開目錄下的WebDriverAgent.xcodeproj,對於WebDriverAgentLib 和 WebDriverAgentRunner,勾選“Automatically manage signing”,把Team改成公司的,Bundle Identifier改成公司的證書可以接受的名字,具體可以參考官方文檔操作,不懂的找開發同學協助。

然后就可以把WebDriverAgentLib和WebDriverAgentRunner都編譯到真機運行一下了。正常來說,會在桌面生成一個沒圖標的WebDriverAgentRunner,點開之后不會有什么反應,這就對了。

終於把環境搭好了,感動啊。

 

寫測試腳本

1. Appium server capabilities

要讓App跑起來,還需要了解Appium server capabilities,它告訴Appium服務器很多信息,例如開哪個App、手機的系統/版本、在哪台設備上跑(真機還是模擬器等)等。

給出我用到的一些參數(in Python),其他capabilities請參考官方文檔

如果能跑起來,就是正常的,不然看一下報什么錯。

2. Inspector

能跑起來只是第一步,更重要的是如何定位元素。

Inspector的使用方法很簡單,之前運行driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub’, desired_caps)之后,連接就已經建立好了,只需在瀏覽器進入http://localhost:8100/inspector即可,之后就可以使用熟悉的driver.find_element_by_xxx方法來定位元素啦。

 

后記

Selenium的坑

后來又遇到了一點坑,例如使用send_keys方法時,報

Message: Parameters were incorrect. We wanted {“required”:[“value”]} and you sent [“text”,”sessionId”,”id”,”value”]

錯誤,google了一下發現是selenium新版導致的問題,降級后解決:

 

手勢操作

由於XCUI的原因,之前的一些手勢操作如swipe、pinch、TouchAction等都不能用了,可以參考這篇官方文檔,使用driver.execute_script方法代替。如

對於直接用坐標的,還要注意邏輯分辨率的問題,如iPhone 7 Plus的邏輯分辨率是414×736。

 

最后

剛接觸iOS的Appium,之后肯定還會遇到問題,會繼續更新本文。

更新,最近更新到了Appium Desktop 1.1,里面帶了1.6.5的Appium,使用起來暫時未發現明顯區別。

附上一些參考:
1. http://www.cocoachina.com/ios/20170112/18518.html
2. http://blog.sina.com.cn/s/blog_b5a76ebd0102wuce.html
3. https://github.com/appium/appium/blob/master/docs/en/appium-setup/real-devices-ios.md
4. http://blog.csdn.net/achang21/article/details/70877583
5. https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md
6. https://github.com/appium/python-client
7. https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/appium-bindings.md
8. https://github.com/facebook/WebDriverAgent/issues/537
9. https://github.com/facebook/WebDriverAgent/wiki/Using-the-Inspector

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM