Android 搭建Appium自动化测试环境

昨天简单搭建了Appium自动化测试环境,目前也是入门学习阶段,这里简单记录搭建过程,方便今后继续学习。

(一)搭建环境:

目前开发使用Mac系统为:10.13.6 ;python使用Mac自带,版本为:2.7;电脑已经配置Android开发环境,JAVA JDK已经Android SDK均可用,不用再次下载安装。之前未配置ANDROID_HOME,此次添加。完整配置流程如下:

1.JDK安装参考文章:https://www.jianshu.com/p/506d7df216dd #Mac下如何安装JDK

2.安装Android sdk,可直接在官网下载Android studio 自带SDK,下载链接:http://www.android-studio.org/index.php/download

3.环境变量配置,比较重要:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home

export PATH=$JAVA_HOME/bin:$PATH

export ANDROID_HOME=/Users/xxx/Library/Android/sdk

export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools/

export PATH=$PATH:/usr/local/bin:/usr/local/sbin:${PATH}

export AAPT_HOME=/Users/xxx/Library/Android/sdk/build-tools/28.0.3

export AAPT_HOME

export PATH=$PATH:$AAPT_HOME

验证环境配置是否成功:

sdk验证:
xxxdeMacBook-Pro:~ xxx$ adb devices
List of devices attached
YDSC9HIV8DHENZBE	device

jdk验证:
xxxdeMacBook-Pro:~ xxx$ Java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

(二)下载安装Appium

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

Android 搭建Appium自动化测试环境_第1张图片

使用命令行安装:

先安装brew:/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
再安装npm:brew install npm
安装cnpm:npm install -g cnpm --registry=https://registry.npm.taobao.org
用cnpm安装appium:cnpm install -g appium
安装appium-doctor:npm install -g appium-doctor

安装好appium后在终端输入appium,如果出现如下界面说明安装成功

xxxdeMacBook-Pro:~ xxx$ appium
[Appium] Welcome to Appium v1.15.0
[Appium] Appium REST http interface listener started on 0.0.0.0:4723

用appium-doctor来检测我们的所有的自动化环境

xxxdeMacBook-Pro:~ xxx$ appium-doctor
info AppiumDoctor Appium Doctor v.1.12.0
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 10.16.3
WARN AppiumDoctor  ✖ Xcode is NOT installed!
info AppiumDoctor  ✔ Xcode Command Line Tools are installed in: /Library/Developer/CommandLineTools
info AppiumDoctor  ✔ DevToolsSecurity is enabled.
info AppiumDoctor  ✔ The Authorization DB is set up properly.
WARN AppiumDoctor  ✖ Carthage was NOT found!
info AppiumDoctor  ✔ HOME is set to: /Users/zcc
info AppiumDoctor  ✔ ANDROID_HOME is set to: /Users/zcc/Library/Android/sdk
info AppiumDoctor  ✔ JAVA_HOME is set to: /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home
info AppiumDoctor  ✔ adb exists at: /Users/zcc/Library/Android/sdk/platform-tools/adb
info AppiumDoctor  ✔ android exists at: /Users/zcc/Library/Android/sdk/tools/android
info AppiumDoctor  ✔ emulator exists at: /Users/zcc/Library/Android/sdk/tools/emulator
info AppiumDoctor  ✔ Bin directory of $JAVA_HOME is set
info AppiumDoctor ### Diagnostic for necessary dependencies completed, 2 fixes 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  ✖ idb and idb_companion are not installed
WARN AppiumDoctor  ✖ applesimutils cannot be found
WARN AppiumDoctor  ✖ bundletool.jar cannot be found
info AppiumDoctor ### Diagnostic for optional dependencies completed, 6 fixes possible. ###
info AppiumDoctor 
info AppiumDoctor ### Manual Fixes Needed ###
info AppiumDoctor The configuration cannot be automatically fixed, please do the following first:
WARN AppiumDoctor  ➜ Manually install Xcode, and make sure 'xcode-select -p' command shows proper path like '/Applications/Xcode.app/Contents/Developer'
WARN AppiumDoctor  ➜ Please install Carthage. Visit https://github.com/Carthage/Carthage#installing-carthage for more information.
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  ➜ 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  ➜ 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
info AppiumDoctor 
info AppiumDoctor ###
info AppiumDoctor 
info AppiumDoctor Bye! Run appium-doctor again when all manual fixes have been applied!
info AppiumDoctor 

到此为止环境搭建就完成了!

(三)简单的使用

打开appium配置Edit Configurations

Android 搭建Appium自动化测试环境_第2张图片

Android 搭建Appium自动化测试环境_第3张图片

 点击开始Start Server后再点击右上角的start inspector session(搜索按钮)配置参数如下:

Android 搭建Appium自动化测试环境_第4张图片

参数配置可以参考官方文档,链接:https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md

点击由下角,Start Ssession进入(appium自带的Inspector),如下图:

Android 搭建Appium自动化测试环境_第5张图片

上图简单获取了立即登录的id,后期会继续学习!

参考文档:

1.http://www.testclass.net/appium/about_appium

2..https://github.com/appium/appium

你可能感兴趣的:(Appium自动化测试)