Appium自动化测试

一 基础环境安装

1.安装 Homebrew

1
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2.安装 libimobiledevice

brew install libimobiledevice

3.安装 ideviceinstaller(真机安装相关)

1
brew install  ideviceinstaller

4.安装 carthage

1
brew install carthage

安装 carthage容易出现以下错误

1
2
3
4
Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
Permission denied @ dir_s_mkdir - /usr/local/Frameworks
Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks

原因是carthage已经安装,但是没有 link 到 brew,还有就是文件夹权限问题,在终端输入:

1
2
3
4
sudo mkdir /usr/local/Frameworks
sudo chown $(whoami):admin /usr/local/Frameworks
brew link carthage

安装 node(目的是安装 npm)官方下载地址https://nodejs.org/en/download/,下载.pkg 文件安装
安装完会显示如下信息

1
2
3
4
This package has installed:
• Node.js v8.11.2 to /usr/local/bin/node
• npm v5.6.0 to /usr/local/bin/npm
Make sure that /usr/local/bin is in your $PATH.

下载安装appium-desktop

安装完顺便安装 appium doctor

npm install -g appium-doctor

1.安装 JDK

先去官网http://www.oracle.com

一步步安装之后安装在目录

在终端下路径如下:

1
/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home

2.安装 android-sdk

首先因为天朝墙的问题,我们无法访问,这里我推荐一两个地址:

http://www.android-studio.org/index.php/download

http://down.tech.sina.com.cn/page/45703.html

下载完之后,我们可以打开下载路径:

3.配置 Android 环境和 JDK 环境

首先,打开我们根目录下的.bash_profile文件

vim .bash_profile(有就会打开,没有就会创建)

按照以下的配置写入配置,路径换成你们自己的对应的路径就好了!

1
2
3
4
5
6
export PATH=${PATH}:/Users/kun/Library/Android/sdk
export PATH=${PATH}:/Users/kun/Library/Android/sdk/platform-tools
export PATH=${PATH}:/Users/kun/Library/Android/sdk/platform-tools/adb
export ANDROID_HOME=/Users/kun/Library/Android/sdk
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=${PATH}:${JAVA_HOME}/bin

退出保存之后想里面配置立马生效可以执行以下命令

source .bash_profile

验证 android 环境是否配置成功可以简单的使用 adb 命令

1
2
3
adb devices
List of devices attached
(没有连接设备,这里显示为空)

到此,我们再请出 appium-doctor来检测我们的所有的自动化环境:

appium-doctor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
info AppiumDoctor Appium Doctor v.1.15.1
info AppiumDoctor ### Diagnostic for necessary dependencies starting ###
info AppiumDoctor ✔ The Node.js binary was found at: /usr/local/bin/node
info AppiumDoctor ✔ Node version is 13.12.0
info AppiumDoctor ✔ Xcode is installed at: /Applications/Xcode.app/Contents/Developer
info AppiumDoctor ✔ Xcode Command Line Tools are installed in: /Applications/Xcode.app/Contents/Developer
info AppiumDoctor ✔ DevToolsSecurity is enabled.
info AppiumDoctor ✔ The Authorization DB is set up properly.
info AppiumDoctor ✔ Carthage was found at: /usr/local/bin/carthage. Installed version is: 0.34.0
info AppiumDoctor ✔ HOME is set to: /Users/kun
info AppiumDoctor ✔ ANDROID_HOME is set to: /Users/kun/Library/Android/sdk
info AppiumDoctor ✔ JAVA_HOME is set to: /Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home
info AppiumDoctor ✔ adb exists at: /Users/kun/Library/Android/sdk/platform-tools/adb
info AppiumDoctor ✔ android exists at: /Users/kun/Library/Android/sdk/tools/android
info AppiumDoctor ✔ emulator exists at: /Users/kun/Library/Android/sdk/tools/emulator
info AppiumDoctor ✔ Bin directory of $JAVA_HOME is set
info AppiumDoctor ### Diagnostic for necessary dependencies completed, no fix needed. ###
info AppiumDoctor
info AppiumDoctor ### Diagnostic for optional dependencies starting ###
WARN AppiumDoctor ✖ opencv4nodejs cannot be found.
WARN AppiumDoctor ✖ ffmpeg cannot be found
WARN AppiumDoctor ✖ mjpeg-consumer cannot be found.
WARN AppiumDoctor ✖ set-simulator-location is not installed
WARN AppiumDoctor ✖ idb and idb_companion are not installed
WARN AppiumDoctor ✖ applesimutils cannot be found
WARN AppiumDoctor ✖ ios-deploy cannot be found
WARN AppiumDoctor ✖ bundletool.jar cannot be found
WARN AppiumDoctor ✖ gst-launch-1.0 and/or gst-inspect-1.0 cannot be found
info AppiumDoctor ### Diagnostic for optional dependencies completed, 9 fixes possible. ###
info AppiumDoctor
info AppiumDoctor ### Optional Manual Fixes ###
info AppiumDoctor The configuration can install optionally. Please do the following manually:
WARN AppiumDoctor ➜ Why opencv4nodejs is needed and how to install it: https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/image-comparison.md
WARN AppiumDoctor ➜ ffmpeg is needed to record screen features. Please read https://www.ffmpeg.org/ to install it
WARN AppiumDoctor ➜ mjpeg-consumer module is required to use MJPEG-over-HTTP features. Please install it with 'npm i -g mjpeg-consumer'.
WARN AppiumDoctor ➜ set-simulator-location is needed to set location for Simulator. Please real https://github.com/lyft/set-simulator-location to install it
WARN AppiumDoctor ➜ Why idb is needed and how to install it: https://github.com/appium/appium-idb
WARN AppiumDoctor ➜ Why applesimutils is needed and how to install it: http://appium.io/docs/en/drivers/ios-xcuitest/
WARN AppiumDoctor ➜ ios-deploy is used as a fallback command to install iOS applications to real device. Please read https://github.com/ios-control/ios-deploy/ to install it
WARN AppiumDoctor ➜ bundletool.jar is used to handle Android App Bundle. Please read http://appium.io/docs/en/writing-running-appium/android/android-appbundle/ to install it
WARN AppiumDoctor ➜ gst-launch-1.0 and gst-inspect-1.0 are used to stream the screen of the device under test. Please read https://appium.io/docs/en/writing-running-appium/android/android-screen-streaming/ to install them and for more details
info AppiumDoctor
info AppiumDoctor ###
info AppiumDoctor
info AppiumDoctor Bye! Run appium-doctor again when all manual fixes have been applied!
info AppiumDoctor

完事具备,环境就此搭建好了!