美文网首页软件测试测试开发
Mac 上安装 Appium 详解

Mac 上安装 Appium 详解

作者: 蓝白自由 | 来源:发表于2017-07-21 10:12 被阅读1045次
    一、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

    MAC中配置JDK详解链接

    ~ mac$ java -version
    java version "1.8.0_141"
    Java(TM) SE Runtime Environment (build 1.8.0_141-b15)
    Java HotSpot(TM) 64-Bit Server VM (build 25.141-b15, mixed mode)
    
    
    • jdk的安装目录为:/Library/Java/JavaVirtualMachines,里面有所有安装的JDK

    Mac 中其它程序版本:
    • git程序
      命令行中输入:git --version
      git version 2.3.2 (Apple Git-55)
    ~ admin$ git --version
    git version 2.11.0 (Apple Git-81)
    
    ~ mac$ ruby --version
    ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]
    
    • python程序
      命令行中输入:python -V
      Python 2.7.10
    ~ admin$ python -V
    Python 2.7.10
    
    • 安装 node.js (如果没有安装brew,按照下面的步骤安装)
      Appium 依赖 Node.js环境,因此需要先安装node 环境。
      终端执行命令:

    • $ brew install node

    • 具体如下:

    ~ mac$ brew install node
    Updating Homebrew...
    ==> Auto-updated Homebrew!
    Updated 1 tap (homebrew/core).
    ==> Updated Formulae
    cromwell            jfrog-cli-go        paket               psqlodbc
    
    ==> Installing dependencies for node: icu4c
    ==> Installing node dependency: icu4c
    ==> Downloading https://homebrew.bintray.com/bottles/icu4c-58.2.sierra.bottle.ta
    ######################################################################## 100.0%
    ==> Pouring icu4c-58.2.sierra.bottle.tar.gz
    ==> Using the sandbox
    ==> Caveats
    This formula is keg-only, which means it was not symlinked into /usr/local,
    because macOS provides libicucore.dylib (but nothing else).
    
    If you need to have this software first in your PATH run:
      echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.bash_profile
      echo 'export PATH="/usr/local/opt/icu4c/sbin:$PATH"' >> ~/.bash_profile
    
    For compilers to find this software you may need to set:
        LDFLAGS:  -L/usr/local/opt/icu4c/lib
        CPPFLAGS: -I/usr/local/opt/icu4c/include
    For pkg-config to find this software you may need to set:
        PKG_CONFIG_PATH: /usr/local/opt/icu4c/lib/pkgconfig
    
    ==> Summary
    🍺  /usr/local/Cellar/icu4c/58.2: 242 files, 65MB
    ==> Installing node
    ==> Downloading https://homebrew.bintray.com/bottles/node-8.1.4.sierra.bottle.ta
    ######################################################################## 100.0%
    ==> Pouring node-8.1.4.sierra.bottle.tar.gz
    ==> Caveats
    Bash completion has been installed to:
      /usr/local/etc/bash_completion.d
    ==> Summary
    🍺  /usr/local/Cellar/node/8.1.4: 3,782 files, 44.5MB
    
    

    • 或者升级
    ~ admin$ brew install node
    Error: node 7.10.0 is already installed
    To upgrade to 8.2.0_1, run `brew upgrade node`
    ZhaoMengXin:~ admin$ brew upgrade node
    ==> Upgrading 1 outdated package, with result:
    node 8.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
    ==> Caveats
    Bash completion has been installed to:
      /usr/local/etc/bash_completion.d
    ==> Summary
    🍺  /usr/local/Cellar/node/8.2.0_1: 4,151 files, 45.9MB
    
    
    • 安装完成后,可以执行 node -v 查看node版本。
    ~ mac$ node -v
    v8.1.4
    

    brew 程序安装

    brew 全称 Homebrew 是 Mac OSX 上的软件包管理工具
    Homebrew 安装和卸载工具只用一行命令就能完成
    官方地址: http://brew.sh/index.html

    ~ mac$ brew -v
    Homebrew 1.2.4
    Homebrew/homebrew-core (git revision 37792; last commit 2017-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
    
    // 按回车键继续或任何其他中止键
    Press RETURN to continue or any other key to abort 
    
    ==> /usr/bin/sudo /bin/mkdir -p /Users/mac/Library/Caches/Homebrew
    Password:  //输入电脑密码
    ==> /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
    ==> Downloading and installing Homebrew...
    remote: Counting objects: 1201, done.
    remote: Compressing objects: 100% (660/660), done.
    remote: Total 1201 (delta 912), reused 704 (delta 507), pack-reused 0
    Receiving objects: 100% (1201/1201), 602.94 KiB | 197.00 KiB/s, done.
    Resolving deltas: 100% (912/912), completed with 359 local objects.
    From https://github.com/Homebrew/brew
     + b38c52f930...f2c2964cf7 master     -> origin/master  (forced update)
     * [new tag]               1.1.12     -> 1.1.12
     * [new tag]               1.1.13     -> 1.1.13
     * [new tag]               1.2.0      -> 1.2.0
     * [new tag]               1.2.1      -> 1.2.1
     * [new tag]               1.2.2      -> 1.2.2
     * [new tag]               1.2.3      -> 1.2.3
     * [new tag]               1.2.4      -> 1.2.4
    HEAD is now at f2c2964cf7 Merge pull request #2912 from jonchang/python-shadowing-docs
    
    Updated 2 taps (homebrew/core, homebrew/versions).
    ==> Cleaning up /Library/Caches/Homebrew...
    ==> Migrating /Library/Caches/Homebrew to /Users/mac/Library/Caches/Homebrew...
    ==> Deleting /Library/Caches/Homebrew...
    ==> New Formulae
    adr-tools                                jenkins-lts
    afuse                                    jhipster
    alexjs                                   jing-trang
    allure                                   jose
    ...
    ...
    ...
    libmatroska                              zookeeper
    libmaxminddb                             zsh
    libmemcached                             zsh-autosuggestions
    libmicrohttpd                            zsh-completions
    libmikmod                                zstd
    libming                                  zurl
    ==> Renamed Formulae
    bazel02 -> bazel@0.2
    bigdata -> blazegraph
    bison27 -> bison@2.7
    ...
    ...
    ...
    varnish4 -> varnish@4
    vim74 -> vim@7.4
    zeromq32 -> zeromq@3.2
    zeromq40 -> zeromq@4.0
    ==> Deleted Formulae
    autotrace                                homebrew/versions/redis1310
    blucat                                   libgc
    devhelp                                  libtess2
    dvtm                                     multirust
    elasticsearch@1.7                        node@0.10
    elasticsearch@2.3                        node@0.12
    fb-adb                                   scsh
    gnupg2                                   snescom
    homebrew/versions/gst-ffmpeg010          webkitgtk
    homebrew/versions/imagemagick-ruby186    xplanetfx
    homebrew/versions/mono3                  xstow
    homebrew/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 (and how to opt-out) here:
      http://docs.brew.sh/Analytics.html
    
    ==> Next steps:
    - Run `brew help` to get started
    - Further documentation: 
        http://docs.brew.sh
    
    Mac:~ mac$ brew -v
    Homebrew 1.2.4
    Homebrew/homebrew-core (git revision 37792; last commit 2017-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.jianshu.com/p/20ea93641bda


    安装npm

    npm是什么?
    �NPM的全称是Node Package Manager ,是一个NodeJS包管理和分发工具,已经成为了非官方的发布Node模块(包)的 标准

    • 如何安装
    • 如果你安装了Homebrew
    • 直接使用命令:$ brew install node
    • 执行完上面的命令,你就安装好了nodejs和npm
    查看npm程序版本 命令行中输入:npm -v
    ~ mac$ npm -v
    5.0.3
    

    下载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文件,打开后在该文件中添加:
    export JAVA_HOME=$(/usr/libexec/java_home)
    export ANDROID_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环境有两种方法:

    • 终端输出信息像下面这样全是对号,则表示环境安装成功了。
    Last login: Tue Nov  1 14:55:59 on ttys002
    wldeMacBook-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/Developer
    info AppiumDoctor  ✔ Xcode Command Line Tools are installed.
    info AppiumDoctor  ✔ DevToolsSecurity is enabled.
    info AppiumDoctor  ✔ The Authorization DB is set up properly.
    info AppiumDoctor  ✔ The Node.js binary was found at: /usr/local/bin/node
    info AppiumDoctor  ✔ HOME is set to: /Users/wl
    info AppiumDoctor  ✔ ANDROID_HOME is set to: /usr/local/android-sdk-macosx
    info AppiumDoctor  ✔ JAVA_HOME is set to: /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
    info AppiumDoctor  ✔ adb exists at: /usr/local/android-sdk-macosx/platform-tools/adb
    info AppiumDoctor  ✔ android exists at: /usr/local/android-sdk-macosx/tools/android
    info AppiumDoctor  ✔ emulator exists at: /usr/local/android-sdk-macosx/tools/emulator
    info 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_HOME is set to '/usr/local/android-sdk-macosx' but this is NOT 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 adb and add it to PATH.
    WARN AppiumDoctor - Manually install android and add it to PATH.
    WARN AppiumDoctor - Manually install emulator and add it to PATH.
    
    • 终端输入命令:
      vi .bash_profile
    • 完成后点i进入编辑模式,加入
    export JAVA_HOME=$(你的Java安装到的地址)
    例如 export JAVA_HOME=$(/usr/Library/java)
    
    export ANDROID_HOME=你刚才下载的SDK在的地址
    例如 export ANDROID_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 -v
    1.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.”

    参考的文章: https://testerhome.com/topics/1225

    相关文章

      网友评论

      • 追你跑丢了鞋:ARN AppiumDoctor ✖ adb could NOT be found at '/Users/zhangbijiang/Documents/android-sdk-macosx/platform-tools/adb'! 楼主帮忙看下
      • 64cdaed94c92:我的是mac环境有问题, 我安装了carthage 并且用appium-doctor检查环境的时候所有都是对的,但是我启动桌面端的appium 启动一个模拟器的时候 它就会报错 说找不到

        Encountered internal error running command: Error: Unable to launch WebDriverAgent because of xcodebuild failure: "Carthage binary is not found. Install using `brew install carthage` if it is not installed and make sure the root folder, where carthage binary is installed, is present in PATH environment variable. The current PATH value: '/usr/bin:/bin:/usr/sbin:/sbin'".

        我感觉我的问题就是出在环境变量没有配置好 但是我并不知道正确的该怎么配置 在网上也找不到相关的教程
      • 我是龙俊:感谢,写的很详细啊

      本文标题:Mac 上安装 Appium 详解

      本文链接:https://www.haomeiwen.com/subject/hhockxtx.html