一、Appium 配置 [? pi' ?m]
Mac 平臺能真正發揮 Appium 的功能,因為 Mac 平臺既能 測試 Android App 又能測試 iOS? App。
Mac 中安裝 Appium 需要安裝 jdk,git ,ruby,python,brew,node,npm,wd 等程序。
Mac OS X 中安裝 jdk 8
下載 jdk 程序包。
jdk 程序下載URL地址:
http://www.oracle.com/technetwork/java/javase/downloads/index.html(這個可以下載Java SE Development Kit 12- - Downloads )
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
下載文件:jdk-8u141-macosx-x64.dmg// (20170719)不能下載
雙擊下載的 .dmg 文件,進行 jdk 的安裝
打開<終端> 輸入? java -version
~ mac$ java -versionjava version"1.8.0_141"Java(TM) SE Runtime Environment (build1.8.0_141-b15)Java HotSpot(TM)64-Bit Server VM (build25.141-b15, mixed mode)
jdk 的安裝目錄為:/Library/Java/JavaVirtualMachines,里面有所有安裝的 JDK
Mac 中其它程序版本:
git 程序
命令行中輸入:git --version
git version 2.3.2? (Apple Git-55)
~ admin$ git --versiongit version2.11.0(Apple Git-81)
ruby 程序MAC_Ruby 安裝詳解鏈接20170719
命令行中輸入:ruby --version
~ mac$ ruby --versionruby2.4.0p0(2016-12-24revision57164) [x86_64-darwin16]
python 程序
命令行中輸入:python -V
Python 2.7.10
~ admin$ python -VPython2.7.10
安裝 node.js (如果沒有安裝brew,按照下面的步驟安裝)
Appium 依賴Node.js環境,因此需要先安裝 node 環境。
終端執行命令:
$ brew install node
具體如下:
eMacBook-Air:~ mac$ brew install nodeUpdating Homebrew...==> Homebrew is run entirely by unpaid volunteers. Please consider donating:? https://github.com/Homebrew/brew#donations==> Auto-updated Homebrew!Updated1tap (homebrew/core).==>NewFormulaeaws-okta? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? micronautbadtouch? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? miniserveblack? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? pagmo、、、、、、、、、libatomic_ops? ? ? ? ? ? ? ? ? ? ? ? ? ? zsh-completionslibbi==> Renamed Formulaerebar@3-> rebar3==> Deleted Formulaedirmngr? ? ? ghc@8.0gnupg@2.0gpg-agent? ? llvm@3.7node@4==> Installing dependenciesfornode: icu4c==> Installing node dependency: icu4c==> Downloading https://homebrew.bintray.com/bottles/icu4c-62.1.high_sierra.bott######################################################################## 100.0%==> Pouring icu4c-62.1.high_sierra.bottle.tar.gz==> Caveatsicu4c is keg-only, which means it was not symlinked into /usr/local,because macOS provides libicucore.dylib (but nothingelse).Ifyou need to have icu4c first in your PATH run:echo'export PATH="/usr/local/opt/icu4c/bin:$PATH"'>> ~/.bash_profileecho'export PATH="/usr/local/opt/icu4c/sbin:$PATH"'>> ~/.bash_profileForcompilers to find icu4c you may need to set:? export LDFLAGS="-L/usr/local/opt/icu4c/lib"export CPPFLAGS="-I/usr/local/opt/icu4c/include"Forpkg-config to find icu4c you may need to set:? export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig"==> Summary??? /usr/local/Cellar/icu4c/62.1:250files,67.3MB==> Installing node==> Downloading https://homebrew.bintray.com/bottles/node-10.10.0.high_sierra.bo######################################################################## 100.0%==> Pouring node-10.10.0.high_sierra.bottle.tar.gz==> CaveatsBash completion has been installed to:? /usr/local/etc/bash_completion.d==> Summary??? /usr/local/Cellar/node/10.10.0:3,940files,49.3MB==> Caveats==> icu4cicu4c is keg-only, which means it was not symlinked into /usr/local,because macOS provides libicucore.dylib (but nothingelse).Ifyou need to have icu4c first in your PATH run:echo'export PATH="/usr/local/opt/icu4c/bin:$PATH"'>> ~/.bash_profileecho'export PATH="/usr/local/opt/icu4c/sbin:$PATH"'>> ~/.bash_profileForcompilers to find icu4c you may need to set:? export LDFLAGS="-L/usr/local/opt/icu4c/lib"export CPPFLAGS="-I/usr/local/opt/icu4c/include"Forpkg-config to find icu4c you may need to set:? export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig"==> nodeBash completion has been installed to:? /usr/local/etc/bash_completion.d
或者升級
~ admin$ brew install nodeError: node7.10.0is already installedTo upgrade to8.2.0_1, run `brew upgrade node`ZhaoMengXin:~ admin$ brew upgrade node==> Upgrading1outdated package, with result:node8.2.0_1==> Upgrading node ==> Downloading https://homebrew.bintray.com/bottles/node-8.2.0_1.sierra.bottle.######################################################################## 100.0%==> Pouring node-8.2.0_1.sierra.bottle.tar.gz==> Using the sandbox==> CaveatsBash completion has been installed to:? /usr/local/etc/bash_completion.d==> Summary??? /usr/local/Cellar/node/8.2.0_1:4,151files,45.9MB
安裝完成后,可以執行 node -v 查看 node 版本。
~ mac$ node -vv10.10.0
brew 程序安裝
brew 全稱 Homebrew? 是 Mac OSX 上的軟件包管理工具
Homebrew 安裝和卸載工具只用一行命令就能完成
官方地址:http://brew.sh/index.html
~ mac$ brew -vHomebrew1.7.4Homebrew/homebrew-core (git revision37792; last commit2017-07-18)
當沒有安裝 brew 程序時,在終端執行下列命令行,安裝brew程序:
ruby -e"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
具體安裝步驟如下:
~ mac$ ruby -e"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"==> This script will install:/usr/local/bin/brew/usr/local/share/doc/homebrew/usr/local/share/man/man1/brew.1/usr/local/share/zsh/site-functions/_brew/usr/local/etc/bash_completion.d/brew/usr/local/Homebrew// 按回車鍵繼續或任何其他中止鍵PressRETURNtocontinueorany other key to abort ==> /usr/bin/sudo /bin/mkdir -p /Users/mac/Library/Caches/HomebrewPassword://輸入電腦密碼==> /usr/bin/sudo /bin/chmod g+rwx /Users/mac/Library/Caches/Homebrew==> /usr/bin/sudo /usr/sbin/chown mac /Users/mac/Library/Caches/Homebrew==> /usr/bin/sudo /bin/mkdir -p /Library/Caches/Homebrew==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew==> /usr/bin/sudo /usr/sbin/chown mac /Library/Caches/Homebrew==> Downloadingandinstalling Homebrew...remote: Counting objects:1201, done.remote: Compressing objects:100% (660/660), done.remote: Total1201(delta912), reused704(delta507), pack-reused0Receiving objects:100% (1201/1201),602.94KiB |197.00KiB/s, done.Resolving deltas:100% (912/912), completed with359local objects.From https://github.com/Homebrew/brew+ b38c52f930...f2c2964cf7 master? ? -> origin/master? (forced update) * [newtag]1.1.12->1.1.12* [newtag]1.1.13->1.1.13* [newtag]1.2.0->1.2.0* [newtag]1.2.1->1.2.1* [newtag]1.2.2->1.2.2* [newtag]1.2.3->1.2.3* [newtag]1.2.4->1.2.4HEAD is now at f2c2964cf7 Merge pull request#2912 from jonchang/python-shadowing-docsUpdated2taps (homebrew/core, homebrew/versions).==> Cleaning up /Library/Caches/Homebrew...==> Migrating /Library/Caches/Homebrew to /Users/mac/Library/Caches/Homebrew...==> Deleting /Library/Caches/Homebrew...==>NewFormulaeadr-tools? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? jenkins-ltsafuse? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? jhipsteralexjs? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? jing-trangallure? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? jose.........libmatroska? ? ? ? ? ? ? ? ? ? ? ? ? ? ? zookeeperlibmaxminddb? ? ? ? ? ? ? ? ? ? ? ? ? ? zshlibmemcached? ? ? ? ? ? ? ? ? ? ? ? ? ? zsh-autosuggestionslibmicrohttpd? ? ? ? ? ? ? ? ? ? ? ? ? ? zsh-completionslibmikmod? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? zstdlibming? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? zurl==> Renamed Formulaebazel02 -> bazel@0.2bigdata -> blazegraphbison27 -> bison@2.7.........varnish4 -> varnish@4vim74 -> vim@7.4zeromq32 -> zeromq@3.2zeromq40 -> zeromq@4.0==> Deleted Formulaeautotrace? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? homebrew/versions/redis1310blucat? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? libgcdevhelp? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? libtess2dvtm? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? multirustelasticsearch@1.7node@0.10elasticsearch@2.3node@0.12fb-adb? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? scshgnupg2? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? snescomhomebrew/versions/gst-ffmpeg010? ? ? ? ? webkitgtkhomebrew/versions/imagemagick-ruby186? ? xplanetfxhomebrew/versions/mono3? ? ? ? ? ? ? ? ? xstowhomebrew/versions/play14==> Migrating cloog018 to cloog==> Unlinking cloog018==> Moving cloog018 children==> Linking cloog==> Installation successful!==> Homebrew has enabled anonymous aggregate user behaviour analytics.Read the analytics documentation (andhow to opt-out) here:? http://docs.brew.sh/Analytics.html==> Next steps:- Run `brew help` to get started- Further documentation:? ? http://docs.brew.shMac:~ mac$ brew -vHomebrew1.2.4Homebrew/homebrew-core (git revision37792; last commit2017-07-18)
使用 brew 安裝軟件
比如安裝git
brew install git
比如安裝wget
brew install wget
使用brew卸載軟件
brew uninstall wget
使用brew查詢軟件
brew search /wge/
/wge
/是個正則表達式, 需要包含在其中
其他brew命令
brew list? ? ? ? ? 列出已安裝的軟件
brew update? ? 更新brew
brew home? ? ? 用瀏覽器打開brew的官方網站
brew info? ? ? ? 顯示軟件信息
brew deps? ? ? ? 顯示包依賴
Mac上安裝 Node 和 npm 鏈接:http://www.lxweimin.com/p/20ea93641bda
安裝 npm
npm 是什么?
?NPM的全稱是Node Package Manager ,是一個NodeJS包管理和分發工具,已經成為了非官方的發布Node模塊(包)的標準。
如何安裝
如果你安裝了Homebrew
直接使用命令:$ brew install node
執行完上面的命令,你就安裝好了nodejs和npm
查看npm程序版本 命令行中輸入:npm -v
~ mac$ npm -v6.4.1
下載 Android SDK,測試 Android App 需要。
下載地址:http://www.androiddevtools.cn/
選擇:[android-sdk_r24.4.macosx.zip](寫本文時的最新版,使用迅雷會比較快)如圖:
解壓縮到任意位置,比如 /usr/local/android-sdk-macosx下。
運行/usr/local/android-sdk-macosx/tools/android,即可啟動Android SDK Manager。
不過我躺槍了 天朝有墻!!!
直接點擊close 接著等待。。。
已經吐血了!!!
google的很多網站在國內無法訪問,苦逼了我們!
打開 SDK Manager 的圖形界面
Android SDK Manager -> Preferences...
http proxy server 這里填寫: mirrors.neusoft.edu.cn (感謝東軟搭建國內的鏡像服務器,為廣大程序員造福無數)
端口填寫80,然后把Force https:// 前的勾勾上
Mac頂部菜單Tools->Manage Add-on Site
把下面這堆網址:
http://mirrors.neusoft.edu.cn/android/repository/addon-6.xml
http://mirrors.neusoft.edu.cn/android/repository/addon.xml
http://mirrors.neusoft.edu.cn/android/repository/extras/intel/addon.xml
http://mirrors.neusoft.edu.cn/android/repository/sys-img/android-tv/sys-img.xml
http://mirrors.neusoft.edu.cn/android/repository/sys-img/android-wear/sys-img.xml
http://mirrors.neusoft.edu.cn/android/repository/sys-img/android/sys-img.xml
http://mirrors.neusoft.edu.cn/android/repository/sys-img/google_apis/sys-img.xml
http://mirrors.neusoft.edu.cn/android/repository/sys-img/x86/addon-x86.xml
http://mirrors.neusoft.edu.cn/android/repository/addons_list-2.xml
http://mirrors.neusoft.edu.cn/android/repository/repository-10.xml
全手動New加進去,然后就可以下載
如圖:
下載和更新 Android SDK Tolls 和 Android SDK Platform-tools 。如下圖的前3個就可以了。。。
保持默認的選項即可,點擊Install 8 packages…。進入到下圖:
Accept License。然后Install就可以了。這個過程根據網速不同,可能需要10-20分鐘,耐心等待。
設置Android環境變量:
方法 1:點擊桌面空白位置然后使用快捷鍵shift+cmd+G
輸入~/.bash_profile,找到.bash_profile文件,打開后在該文件中添加:
exportJAVA_HOME=$(/usr/libexec/java_home)exportANDROID_HOME=/usr/local/android-sdk-macosx
終端執行 source ~/.bash_profile 使環境變量生效。
方法 2:終端輸入:vi .bash_profile
按 i 鍵進入bash_profile文件編輯模式,完成之后esc鍵退出編輯,:wq結束。 同樣執行 source ~/.bash_profile 使環境變量生效。
至此,為了安裝Appium所需要的Mac平臺已經配置完畢了。接下來開始安裝Appium。
Appium 安裝
Mac 平臺環境安裝完畢之后,就可以開始安裝 Appium了。
Mac下搭建 appium 環境有兩種方法:
直接下載 appium.dmg 運行即可
Appium官網下載鏈接:https://bitbucket.org/appium/appium.app/downloads/直接安裝即可。
appium doctor用來appium的是否成功安裝,即點擊下圖按鈕:
終端輸出信息像下面這樣全是對號,則表示環境安裝成功了。
Last login: Tue Nov? 1 14:55:59 on ttys002wldeMacBook-Pro:~ wl$'/Applications/Appium.app/Contents/Resources/node/bin/node''/Applications/Appium.app/Contents/Resources/node_modules/appium-doctor/appium-doctor.js'info AppiumDoctor### Diagnostic starting ###info AppiumDoctor? ? Xcode is installed at: /Applications/Xcode7.3.1.app/Contents/Developerinfo AppiumDoctor? ? Xcode Command Line Tools are installed.info AppiumDoctor? ? DevToolsSecurity is enabled.info AppiumDoctor? ? The Authorization DB issetup properly.info AppiumDoctor? ? The Node.js binary was found at: /usr/local/bin/nodeinfo AppiumDoctor? ? HOME issetto: /Users/wlinfo AppiumDoctor? ? ANDROID_HOME issetto: /usr/local/android-sdk-macosxinfo AppiumDoctor? ? JAVA_HOME issetto: /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Homeinfo AppiumDoctor? ? adb exists at: /usr/local/android-sdk-macosx/platform-tools/adbinfo AppiumDoctor? ? android exists at: /usr/local/android-sdk-macosx/tools/androidinfo AppiumDoctor? ? emulator exists at: /usr/local/android-sdk-macosx/tools/emulatorinfo AppiumDoctor### Diagnostic completed, no fix needed. ###info AppiumDoctor info AppiumDoctor Everything looks good,bye!info AppiumDoctor
不過想象是美好的,但是結果是殘酷的:
這個問題存在的原因就是appium 不兼容最新的mac10.12版本。
由于10.12是最新mac版本,appium1.5.3并未提供支持,所以:
在終端輸入
$ grep -rl"Could not detect Mac OS X Version from sw_vers output:"/Applications/Appium.app/
找出包含的文件并修改版本號。
這個時候你會看到這個結果 :
得到了四個js文件的地址,使用vim 命令一一打開這幾個文件 例:
~ mac$ vim /Applications/Appium.app//Contents/Resources/node_modules/appium/node_modules/appium-support/build/lib/system.js
打開第一個后看到這個文件,找到這行:
看到的可能沒有那么多新的版本,那這時候點擊i進入編輯模式將你們的系統版本加進去,編輯完后點擊Esc,輸入
:wq 保存修改 修改為:
打開第二個地址看到這個地方 :
修改為:
這個時候還有兩個文件,打開后你會發現差不多,一樣的方法打開完成修改后我們再來診斷一下
但是也有可能會遇到 X Xcode Command Line Tools are not installed.這個情況,那不用擔心,小問題:
這是因為在從App Store上下載Xcode后,默認是不會安裝Command Line Tools的,Command Line Tools是在Xcode中的一款工具,可以在命令行中運行C程序。
解決辦法:
打開命令行終端,輸入以下命令:xcode-select --install
回車,出來以下安裝畫面
安卓的SDK 安裝出錯:
WARN AppiumDoctor? ? ANDROID_HOMEisset to'/usr/local/android-sdk-macosx'but thisisNOT a valid path!WARN AppiumDoctor? ? adb could NOT be found at'/usr/local/android-sdk-macosx/platform-tools/adb'!WARN AppiumDoctor? ? android could NOT be found at'/usr/local/android-sdk-macosx/tools/android'!WARN AppiumDoctor? ? emulator could NOT be found at'/usr/local/android-sdk-macosx/tools/emulator'!WARN AppiumDoctor - Manually configure ANDROID_HOME.WARN AppiumDoctor - Manually install adbandadd it to PATH.WARN AppiumDoctor - Manually install androidandadd it to PATH.WARN AppiumDoctor - Manually install emulatorandadd it to PATH.
終端輸入命令:
vi .bash_profile
完成后點i進入編輯模式,加入
exportJAVA_HOME=$(你的Java安裝到的地址)例如exportJAVA_HOME=$(/usr/Library/java)exportANDROID_HOME=你剛才下載的SDK在的地址例如exportANDROID_HOME=/usr/local/android-sdk-macosx
點擊Esc退出,輸入:wq保存,還有比較重要的一步 !!!
輸入: $ source ~/.bash_profile
讓環境變量生效,切記
最終:
備注:
也有node報錯的:
The Node.js binary was not found at: /usr/local/bin/node**
盡管有些說安裝了appium會自動安裝nodejs,但事實好像并不是這樣,一樣無腦的解決辦法,去node官網,地址:http://nodejs.cn/download/,下載Mac版,解壓,安裝,安裝完成繼續診斷。
~ admin$ appium -v1.6.5
也有使用 使用npm安裝(這里不做講解,下面有鏈接可以參考一下學習)
下載dmg包安裝的方法,很簡單,和安裝所有的dmg包一樣。不多介紹了。下面主要介紹下通過npm安裝的方法。
官網上提供的步驟是下面這樣的:
> brew install node# get node.js> npm install -g appium# get appium> npm install wd# get appium client> appium &# start appium> node your-appium-test.js
先升級homebrew:brew update,以便能夠安裝最新版的node。我第一遍安裝的時候,就是因為沒有升級brew,所以通過brew install node安裝的node版本比較低,導致用npm安裝appium提示“’appnium’ is not in the npm registry.”