Appium Mac环境搭建

环境依赖

  • Node.js
  • Appium
  • Appium-doctor
  • Appium-Python-Client
  • Python
  • JDK
  • Andriod SDK

安装Node.js

下载地址:https://nodejs.org/en/download/releases/

注意:Node.js版本要注意与Appium兼容, 查看Appium版本依赖Node.js版本详情请点击:https://github.com/appium/appium/releases

输入如下命令:

1
2
3
4
5
atx:~ atx$ node -v
v14.16.0
atx:~ atx$ npm -v
6.14.11
atx:~ atx$

说明:

  • npm(node package manage)是node.js安装包管理工具,类似Python中的pip工具。
  • 如果显示‘npm’不是内部命令提示,则可以管理员身份运行cmd,如果还是失败,则需要检查一下环境变量是否配置,或者重新安装nodejs。

Appium 安装

安装命令

使用如下命令来执行安装:

1
2
3
4
5
#安装最新版本
npm install -g appium

#安装指定版本
npm install appium@1.7.2 -g

appium-chromedriver 报错

如果安装时遇到如下报错,是由于appium-chromedriver无法下载造成的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[06:44:08] Error: EACCES: permission denied, mkdir '/root/.nvm/versions/node/v12.21.0/lib/node_modules/appium/node_modules/appium-chromedriver/chromedriver'
[06:44:08] Downloading Chromedriver can be skipped by using the '--chromedriver-skip-install' flag or setting the 'APPIUM_SKIP_CHROMEDRIVER_INSTALL' environment variable.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! appium-chromedriver@4.27.3 postinstall: `node install-npm.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the appium-chromedriver@4.27.3 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-03-03T06_44_11_004Z-debug.log
[root@22fea2c5fd87 .nvm]# appium
bash: appium: command not found
[root@22fea2c5fd87 .nvm]# npm install -g appium --chromedriver-skip-install
/root/.nvm/versions/node/v12.21.0/bin/appium -> /root/.nvm/versions/node/v12.21.0/lib/node_modules/appium/build/lib/main.js


解决方案:加参数npm install -g appium --chromedriver-skip-install跳过即可,在mac中默认是安装路径一般为 /usr/local/lib/node_modules/appium中。

appium运行

在控制台输入命令 appium即可启动appium服务,命令appium -v查看版本

1
2
3
atx:~ atx$ appium
[Appium] Welcome to Appium v1.22.3
[Appium] Appium REST http interface listener started on 0.0.0.0:4723

退出appium

按键 ctrl+c 选择y 即可退出

安装Appium-desktop

下载地址:https://github.com/appium/appium-desktop/releases

上面提到的问题可以使用前面我们已经介绍了Appium Server来解决,Appium-desktop工具其实也封装了Appium server和Node.js依赖环境。

appium-desktop是我们初学者最容易上手的工具,后面课程首先会基于这个工具来讲解!然后再基于appium 命令来讲。

python环境安装配置

见之前的视频教程:3-2 Python 安装与配置

安装成功之后输入命令 python –version看到如下提示即可

1
2
C:\Users\Shuqing>python --version
Python 3.5.0

安装Appium-Python-Client

通过命令: pip install Appium-Python-Client 进行安装。
安装后可以通过如下命令来检测是否安装成功。

输入命令“from appium import webdriver” 回车,如果控制台没有报错,则说明安装成功。

1
2
3
4
5
C:\Users\Shuqing>python
Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from appium import webdriver

如果出现如下报错,则说明安装失败

1
2
ImportError: No module named 'appium'
ImportError: cannot import name “webdriver”

说明:装Appium-Python-Client安装后的路径一般为:

1
{Python 安装路径}\Lib\site-packages\appium

JDK安装配置

jdk下载地址:

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

jdk环境变量配置

http://jingyan.baidu.com/article/624e74599e8ad834e8ba5a94.html

安装配置完成后,打开命令提示符窗口,然后输入如下面命令有对应提示说明安装配置成功。

1
2
3
4
C:\Users\Shuqing>java -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

Andriod sdk 安装

下载地址:
http://tools.android-studio.org/index.php/sdk

根据自己的PC平台下载对应版本即可。

安装完成后需要配置环境变量:ANDROID_HOME,第二章有详细说明。

安装 appium-doctor

appium-doctor可以检测Appium整体依赖环境配置情况。

1
C:\Users\Shuqing>cnpm install appium-doctor -g
  • 在控制台输入命令:appium-doctor 看到如下提示说明整体环境配置成功。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
C:\Users\Shuqing>appium-doctor
info AppiumDoctor Appium Doctor v.1.4.3
info AppiumDoctor ### Diagnostic starting ###
info AppiumDoctor ✔ The Node.js binary was found at: D:\program files\nodejs\node.exe
info AppiumDoctor ✔ Node version is 6.11.3
info AppiumDoctor ✔ ANDROID_HOME is set to: E:\Andriod_sdk
info AppiumDoctor ✔ JAVA_HOME is set to: C:\Program Files\Java\jdk1.8.0_05
info AppiumDoctor ✔ adb exists at: E:\Andriod_sdk\platform-tools\adb.exe
info AppiumDoctor ✔ android exists at: E:\Andriod_sdk\tools\android.bat
info AppiumDoctor ✔ emulator exists at: E:\Andriod_sdk\tools\emulator.exe
info AppiumDoctor ✔ Bin directory of %JAVA_HOME% is set
info AppiumDoctor ### Diagnostic completed, no fix needed. ###
info AppiumDoctor
info AppiumDoctor Everything looks good, bye!
info AppiumDoctor

如果上面某一项显示为“X”则说明相关环境没有配置好,需要重新安装配置。

踩坑相关

fsevents依赖问题

1
2
3
4
platform unsupported fsevents@1.x Package require os(darwin) not compatible with your platform(win32)
[fsevents@1.x] optional install error: Package require os(darwin) not compatible with your platform(win32)
[24/29] appium-android-driver@1.x installed at node_modules\_appium-android-driver@1.40.1@appium-android-driver

解决方案:
运行下面的命令

1
2
3
4
npm rebuild node-sass

npm install

uiautomator相关apk不可读

1
2
3
[ADB] Running 'E:\Andriod_sdk\platform-tools\adb.exe -P 5037 -s 7643c658 forward tcp:8200 tcp:6790'
[UiAutomator2] Server package at 'C:\Program Files\Appium Server GUI\resources\app\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v4.24.0.apk' is not writeable. Will copy it into the temporary location at 'C:\Users\Shuqing\AppData\Local\Temp\20211130-30096-11ux4rt.rldb' as a workaround. Consider making this file writeable manually in order to improve the performance of session startup.
[UiAutomator2] Server package at 'C:\Program Files\Appium Server GUI\resources\app\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-debug-androidTest.apk' is not writeable. Will copy it into the temporary location at 'C:\Users\Shuqing\AppData\Local\Temp\20211130-30096-11ux4rt.rldb' as a workaround. Consider making this file writeable manually in order to improve the performance of session startup.

解决方案

appium版本太高,而测试设备系统版本太低会导致该问题,例如appium V1.22与Android 7.X的设备测试时就会出现该问题。

apksigner.jar文件找不到

1
2
3
4
5


An unknown server-side error occurred while processing the command. Original error: Cannot verify the signature of 'C:\Users\Administrator\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v4.17.4.apk'. Original error: Could not find 'apksigner.jar'


需要把apksigner.jar文件放在提示报错的位置,一般是$Android home/platform-tools/

参考资料