安裝 Appium

yang152412發表於2018-12-27

Appium 官網:appium.io/docs/en/abo…

下載 Appium: github.com/appium/appi…

iOS 配置

appium.io/docs/en/dri…

1、需要安裝 brew node 和 npm,

brew mac 自帶, node 官網下載:nodejs.org/en/download…

2、安裝 Carthage

bash brew install carthage
複製程式碼

如果只是模擬器的話,到此結束。

iOS 真機配置

真機配置:appium.io/docs/en/dri…

一、安裝 libimobiledevice

brew install libimobiledevice
複製程式碼

但是這個命令報錯不斷

1、沒許可權

 brew install libimobiledevice --HEAD
 
Updating Homebrew...
Error: The following directories are not writable by your user:
/usr/local/share/man/man3
/usr/local/share/man/man5
/usr/local/share/man/man7

You should change the ownership of these directories to your user.
  sudo chown -R $(whoami) /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7
ddxqdeMac-mini:~ ddxq$ sudo brew update
複製程式碼

改完之後

Error: The following directories are not writable by your user:
/usr/local/include
/usr/local/lib

You should change the ownership of these directories to your user.
  sudo chown -R $(whoami) /usr/local/include /usr/local/lib
複製程式碼

2、xcode commandlinetool

Error: Xcode alone is not sufficient on High Sierra.
Install the Command Line Tools:
  xcode-select --install
複製程式碼

按照提示改

3、/usr/local/Cellar許可權

Error: An exception occurred within a child process:
  Errno::EPERM: Operation not permitted @ dir_s_mkdir - /usr/local/Cellar
複製程式碼

這個目錄壓根就不存在,只能自己建立,並改許可權

 sudo mkdir /usr/local/Cellar
 sudo chown -R $(whoami) /usr/local/Cellar/
複製程式碼

4、/usr/local/opt

Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink .
/usr/local/opt is not writable.

You can try again using:
  brew link autoconf
複製程式碼

/usr/local/opt 目錄也是不存在,再建立一下:

sudo mkdir /usr/local/opt
sudo chown -R $(whoami) /usr/local/opt/
複製程式碼

5、沒有 autoconf

Error: An exception occurred within a child process:
  RuntimeError: /usr/local/opt/autoconf not present or broken
Please reinstall autoconf. Sorry :(
複製程式碼

解決辦法:

autoconf下載原始碼包

./configure 

make && make install
複製程式碼

重新安裝之後,仍然報這個錯,沒辦法,把前面報錯的 brew link 全部重新執行一遍,然後依然報錯,最後用

brew install libimobiledevice
複製程式碼

安裝成功。

累計的 brew link 有:

  534  brew link autoconf
  535  brew link --overwrite autoconf
  536  brew install libimobiledevice --HEAD
  537  brew link --overwrite autoconfbrew link automake
  538  brew link automake
  539  brew link libtool
  540  brew link gdbm
  541  brew link python@2
  542  sudo mkdir /usr/local/Frameworks
  543  sudo chown -R $(whoami) /usr/local/Frameworks
  544  brew link python@2
  545  brew link pkg-config
  546  brew link libplist
  547  brew link libtasn1
  548  brew link libusb
  549  brew link usbmuxd
複製程式碼

中間執行 brew link python@2 還報了 /usr/local/Frameworks 不存在,又建立這個目錄。

之後啟動 Appium desktop 的時候,開啟 session,發現報錯

Command 'idevice_id -l' exited with code null
複製程式碼

想到或許是 libimobiledevice 沒有安裝好的原因。於是重新安裝 libimobiledevice,這次又報錯:

brew install libimobiledevice --HEAD

Error: An exception occurred within a child process:
  RuntimeError: /usr/local/opt/openssl not present or broken
Please reinstall openssl. Sorry :(
複製程式碼

重新安裝 openssl,報:

brew install openssl 
Warning: openssl 1.0.2q is already installed, it's just not linked
You can use `brew link openssl` to link this version.
複製程式碼

執行 brew link openssl 報:

Warning: Refusing to link macOS-provided software: openssl
If you need to have openssl first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile

For compilers to find openssl you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl/include"

For pkg-config to find openssl you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"
複製程式碼

網上說法大部分都是 要連結 openssl,如:

ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/    
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
複製程式碼

這個執行完畢後,發現依然報錯,後來發現/usr/local/opt目錄下面壓根就沒有openssl。 沒辦法執行 brew reinstall openssl,重新安裝。安裝完成後繼續執行 brew install libimobiledevice --HEAD,依然報

Error: An exception occurred within a child process:
  RuntimeError: /usr/local/opt/readline not present or broken
Please reinstall readline. Sorry :(
複製程式碼

不過好得 /usr/local/opt目錄下面有了openssl了,終於是個好訊息。於是重新執行 連結:

ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/    
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
複製程式碼

結果卻是:

ln: /usr/local/lib//libcrypto.1.0.0.dylib: File exists
複製程式碼

執行:brew link --force openssl,還是報錯:

Warning: Refusing to link macOS-provided software: openssl
If you need to have openssl first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile

For compilers to find openssl you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl/include"

For pkg-config to find openssl you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"
複製程式碼

最後沒辦法,安裝提示試試吧,執行

echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
brew install libimobiledevice --HEAD
複製程式碼

又是報錯:

Error: An exception occurred within a child process:
  RuntimeError: /usr/local/opt/readline not present or broken
Please reinstall readline. Sorry :(
複製程式碼

雖然報錯,但是說明把 openssl 的問題解決了,那麼依葫蘆畫瓢,在來解決readline.

brew link --force readline
複製程式碼

後面執行一次brew install libimobiledevice --HEAD

報錯的有:

Error: An exception occurred within a child process:
  RuntimeError: /usr/local/opt/sqlite not present or broken
Please reinstall sqlite. Sorry :(

Error: An exception occurred within a child process:
  RuntimeError: /usr/local/opt/libxml2 not present or broken
Please reinstall libxml2. Sorry :(

複製程式碼

這兩個錯誤和 openssl 一樣,也是需要reinstall,之後執行echo 'export PATH="/usr/local/opt/libxml2/bin:$PATH"' >> ~/.bash_profile

最後一次執行 brew install libimobiledevice --HEAD 報:

hecking for libusbmuxd >= 1.1.0... no
configure: error: Package requirements (libusbmuxd >= 1.1.0) were not met:

Requested 'libusbmuxd >= 1.1.0' but version of libusbmuxd is 1.0.10
複製程式碼

參考:www.jianshu.com/p/1ec36db7d…

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
複製程式碼

完了之後重新執行 brew install libimobiledevice --HEAD,終於成功了。

二、安裝 WebDriverAgent

需要改 bundleIdentifier,安裝到手機是,安裝是執行 test 的 target,或者 Command + U快捷鍵。執行完後在console 上也確實輸出了server的 ip 地址,其實就是 手機的 ip 地址,

WebDriverAgentRunner-Runner[331:18887] ServerURLHere->http://10.192.228.18:8100<-ServerURLHere
複製程式碼

根據網上教程,在瀏覽器輸入 http://10.192.228.18:8100/status,但是訪問不了,後來在網上找到需要做埠對映

iproxy 8100 8100
複製程式碼

執行完,終端會顯示 waiting for connection,這時候在瀏覽器裡輸入http://localhost:8100/status,可以看到輸出的 json。

參考這裡:www.cnblogs.com/xiyuan2016/…

三、 啟動 Appium Desktop

啟動 AppiumDesktop,用預設設定就好,之後在啟動 server。

配置Desired Capabilities

可以參考:github.com/appium/appi…

例如:

{
  "automationName": "appium",
  "platformName": "iOS",
  "platformVersion": "12.0",
  "app": "/Users/Shared/Jenkins/Home/workspace/***.ipa",
  "deviceName": "iPhone",
  "udid": "d8cf9de0ee74526c9f14e7a0a74a027217644346",
  "xcodeOrgId": "4J5FV4S6P3",
  "xcodeSigningId": "WildcardAppIDProfile",
  "bundleId": "com.******"
}
複製程式碼

最後點選Start Session開始會話。

相關文章