1.安装jdk
2.安装sdk,这里选择直接安装android studio
3.配置环境
终端输入touch .bash_profile创建
输入open .bash_profile打开文件将下面的内容写进去
export ANDROID_HOME=/Users/你的用户名/Library/Android/sdk
export PATH=${PATH}:/Users/你的用户名/Library/Android/sdk/platform-tools:/Users/你的用户名/Library/Android/sdk/tools
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home
export PATH=${JAVA_HOME}/bin:$PATH
想要立刻生效终端输入source ~./bash_profile
4.安装python
Mac自带python2,自己可以下载python3,使用的时候使用python3和pip3
5.安装appium
-安装homebrew
homebrew 简称brew,是Mac OSX上的软件包管理工具,能在Mac中方便的安装软件或者卸载软件,可以说Homebrew就是mac下的apt-get、yum等神器。
/usr/bin/ruby−e" / u s r / b i n / r u b y − e " (curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
安装libimobiledevice:libimobiledevice 是一个跨平台的软件库,支持 iPhone®, iPod Touch®, iPad® and Apple TV® 等设备的通讯协议。不依赖任何已有的私有库,不需要越狱。应用软件可以通过这个开发包轻松访问设备的文件系统、获取设备信息,备份和恢复设备,管理 SpringBoard 图标,管理已安装应用,获取通讯录、日程、备注和书签等信息,使用 libgpod 同步音乐和视频。
$ brew install libimobiledevice –HEAD
-安装carthage:carthage 使用于 Swift 语言编写,只支持动态框架,只支持 iOS8+的Cocoa依赖管理工具。
$ brew install carthage
-安装node:node是安装npm的前置条件。
$ brew install node
-安装npm:npm是一个NodeJS包管理和分发工具,已经成为了非官方的发布Node模块(包)的标准。
$ brew install npm
-安装cnpm:国内直接用npm下载安装会有好多网络问题,安装淘宝的cnpm要比npm好用,https://npm.taobao.org/
$ npm install -g cnpm –registry=https://registry.npm.taobao.org
-安装ios-deploy:ios-deploy是一个使用命令行安装ios app到连接的设备的工具,原理是根据os x命令行工程调用系统底层函数,获取连接的设备、查询/安装/卸载app。
$ cnpm install -g ios-deploy
-安装xcpretty: xcpretty是用于对xcodebuild的输出进行格式化。并包含输出report功能。
$ gem install xcpretty
-安装appium,appium-doctor
$ cnpm install -g appium
$ cnpm install -g appium-doctor
-使用appium-doctor检查appium环境
如图配置完成
5.安装appium-desktop
Appium-desktop项目地址:https://github.com/appium/appium-desktop
下载地址:https://github.com/appium/appium-desktop/releases
安装完成桌面会生成一个紫色的appium 图标,双击打开。
默认显示监控的 host 和 port ,这和 Appium-Server中是一致的。点击 “Start Server V 1.7.1” 按钮启动服务。
启动移动设备(真机或模拟器),编写 Appium 自动化测试脚本
如果直接使用点击右上角的放大镜配置
点击start
将测试脚本写在.py文件中cd进入所在文件夹终端python3 test.py运行测试脚本
# coding=utf-8
from appium import webdriver
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4.4'
desired_caps['deviceName'] = 'Android Emulator'
desired_caps['appPackage'] = 'com.android.calculator2'
desired_caps['appActivity'] = '.Calculator'
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
driver.find_element_by_id("com.android.calculator2:id/digit1").click()
driver.find_element_by_id("com.android.calculator2:id/digit5").click()
driver.find_element_by_id("com.android.calculator2:id/digit9").click()
driver.find_element_by_id("com.android.calculator2:id/del").click()
driver.find_element_by_id("com.android.calculator2:id/digit9").click()
driver.find_element_by_id("com.android.calculator2:id/digit5").click()
driver.find_element_by_id("com.android.calculator2:id/plus").click()
driver.find_element_by_id("com.android.calculator2:id/digit6").click()
driver.find_element_by_id("com.android.calculator2:id/equal").click()
#driver.quit()
1.使用android自带的模拟器时appium-desktop连接出现error
[error] [MJSONWP] Encountered internal error running command: Error: Error executing adbExec. Original error: ‘Command ‘/Users/bytedance/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell pm install -r /data/local/tmp/6d482723f8021e2dad07a70707a7b77b.apk’ exited with code 1’; Stderr: ‘Failure [INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract native libraries, res=-113]’; Code: ‘1’
不知道是不是模拟器有问题,更换了其他模拟器就可以了
不使用desktop直接打开appium在android studio模拟器上运行上边计算器的测试脚本,虚拟机可以显示计算器但是无法继续运行
存一下日志
[info] [Appium] Welcome to Appium v1.7.1
[info] [Appium] Non-default server args:
[info] [Appium] address: 127.0.0.1
[info] [Appium] Appium REST http interface listener started on 127.0.0.1:4723[info] [HTTP] --> POST /wd/hub/session {"capabilities":{"firstMatch":[{}],"alwaysMatch":{"platformName":"Android"}},"desiredCapabilities":{"platformName":"Android","platformVersion":"8.0","deviceName":"Android Emulator","appPackage":"com.android.calculator2","appActivity":".Calculator"}}
[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{"platformName":"Android","platformVersion":"8.0","deviceName":"Android Emulator","appPackage":"com.android.calculator2","appActivity":".Calculator"},null,{"firstMatch":[{}],"alwaysMatch":{"platformName":"Android"}}]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1522821137710 (13:52:17 GMT+0800 (CST))
[info] [Appium] Creating new AndroidDriver (v1.28.1) session
[info] [Appium] Capabilities:
[info] [Appium] platformName: 'Android'
[info] [Appium] platformVersion: '8.0'
[info] [Appium] deviceName: 'Android Emulator'
[info] [Appium] appPackage: 'com.android.calculator2'
[info] [Appium] appActivity: '.Calculator'
[info] [BaseDriver] Session created with session id: a6e462f6-38d9-4e7b-8c61-290d91b727ed
[debug] [AndroidDriver] Getting Java version[info] [AndroidDriver] Java version is: 1.8.0_161
[info] [ADB] Checking whether adb is present
[info] [ADB] Using adb from /Users/bytedance/Library/Android/sdk/platform-tools/adb
[info] [AndroidDriver] Retrieving device list
[debug] [ADB] Trying to find a connected android device
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[info] [AndroidDriver] Looking for a device with Android '8.0'
[debug] [ADB] Setting device id to emulator-5554
[info] [ADB] Getting device platform version
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","getprop","ro.build.version.release"]
[debug] [ADB] Current device property 'ro.build.version.release': 8.0.0
[info] [AndroidDriver] Using device: emulator-5554
[info] [ADB] Checking whether adb is present
[info] [ADB] Using adb from /Users/bytedance/Library/Android/sdk/platform-tools/adb
[debug] [ADB] Setting device id to emulator-5554
[info] [AndroidDriver] App file was not listed, instead we're going to run com.android.calculator2 directly on the device
[debug] [AndroidDriver] Checking whether package is present on the device
[debug] [ADB] Getting connected devices...[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","pm","list","packages","com.android.calculator2"][info] [AndroidDriver] Starting Android session
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","wait-for-device"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","echo","ping"]
[debug] [Logcat] Starting logcat capture
[debug] [AndroidDriver] Pushing settings apk to device...
[debug] [ADB] Uninstalling and re-installing 'io.appium.settings'
[debug] [ADB] Uninstalling io.appium.settings
[debug] [ADB] Getting install status for io.appium.settings
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","pm","list","packages","io.appium.settings"][debug] [ADB] App is installed
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","am","force-stop","io.appium.settings"][debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","uninstall","io.appium.settings"]
[debug] [ADB] ADB command output: Success
[info] [ADB] io.appium.settings was successfully uninstalled
[debug] [ADB] Getting install status for io.appium.settings
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","pm","list","packages","io.appium.settings"][debug] [ADB] App is not installed
[debug] [ADB] App '/private/var/folders/2v/hwlyn1m93ngd5v8n69llv7bc0000gn/T/AppTranslocation/67667BA5-5970-4BCE-89C0-3C34F5944F61/d/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/io.appium.settings/app/build/outputs/apk/settings_apk-debug.apk' not installed. Installing
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","install","/private/var/folders/2v/hwlyn1m93ngd5v8n69llv7bc0000gn/T/AppTranslocation/67667BA5-5970-4BCE-89C0-3C34F5944F61/d/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/io.appium.settings/app/build/outputs/apk/settings_apk-debug.apk"][debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","getprop","ro.build.version.sdk"]
[debug] [ADB] Current device property 'ro.build.version.sdk': 26
[debug] [ADB] Device API level: 26
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","dumpsys","package","io.appium.settings"][debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","pm","dump","io.appium.settings"][debug] [ADB] Got the following command chunks to execute: pm,grant,io.appium.settings,android.permission.READ_PHONE_STATE,;,pm,grant,io.appium.settings,android.permission.WRITE_SETTINGS,;,pm,grant,io.appium.settings,android.permission.ACCESS_FINE_LOCATION,;,pm,grant,io.appium.settings,android.permission.ACCESS_COARSE_LOCATION,;,pm,grant,io.appium.settings,android.permission.ACCESS_MOCK_LOCATION,;,pm,grant,io.appium.settings,android.permission.SET_ANIMATION_SCALE,;
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","pm","grant","io.appium.settings","android.permission.READ_PHONE_STATE",";","pm","grant","io.appium.settings","android.permission.WRITE_SETTINGS",";","pm","grant","io.appium.settings","android.permission.ACCESS_FINE_LOCATION",";","pm","grant","io.appium.settings","android.permission.ACCESS_COARSE_LOCATION",";","pm","grant","io.appium.settings","android.permission.ACCESS_MOCK_LOCATION",";","pm","grant","io.appium.settings","android.permission.SET_ANIMATION_SCALE",";"][debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","ps"]
[debug] [ADB] Device API level: 26
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","am","start","-W","-n","io.appium.settings/.Settings","-a","android.intent.action.MAIN","-c","android.intent.category.LAUNCHER","-f","0x10200000"][debug] [ADB] Device API level: 26
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","appops","set","io.appium.settings","android:mock_location","allow"]
[debug] [AndroidDriver] Pushing unlock helper app to device...
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","install","/private/var/folders/2v/hwlyn1m93ngd5v8n69llv7bc0000gn/T/AppTranslocation/67667BA5-5970-4BCE-89C0-3C34F5944F61/d/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-unlock/bin/unlock_apk-debug.apk"][debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","install","/private/var/folders/2v/hwlyn1m93ngd5v8n69llv7bc0000gn/T/AppTranslocation/67667BA5-5970-4BCE-89C0-3C34F5944F61/d/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-unlock/bin/unlock_apk-debug.apk"]
[debug] [ADB] Application '/private/var/folders/2v/hwlyn1m93ngd5v8n69llv7bc0000gn/T/AppTranslocation/67667BA5-5970-4BCE-89C0-3C34F5944F61/d/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-unlock/bin/unlock_apk-debug.apk' already installed. Continuing.
[info] [ADB] Getting device platform version
[debug] [ADB] Getting connected devices...[debug] [ADB] Current device property 'ro.build.version.release': 8.0.0
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","wm","size"][debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","getprop","ro.product.model"]
[debug] [ADB] Current device property 'ro.product.model': Android SDK built for x86
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","getprop","ro.product.manufacturer"]
[debug] [ADB] Current device property 'ro.product.manufacturer': Google
[warn] [AndroidDriver] No app sent in, not parsing package/activity
[debug] [AndroidDriver] No app capability. Assuming it is already on the device
[debug] [AndroidDriver] Running fast reset (stop and clear)
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","am","force-stop","com.android.calculator2"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","pm","clear","com.android.calculator2"][debug] [AndroidBootstrap] Watching for bootstrap disconnect
[debug] [ADB] Forwarding system: 4724 to device: 4724
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","forward","tcp:4724","tcp:4724"]
[debug] [UiAutomator] Starting UiAutomator
[debug] [UiAutomator] Moving to state 'starting'
[debug] [UiAutomator] Parsing uiautomator jar
[debug] [UiAutomator] Found jar name: 'AppiumBootstrap.jar'
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","push","/private/var/folders/2v/hwlyn1m93ngd5v8n69llv7bc0000gn/T/AppTranslocation/67667BA5-5970-4BCE-89C0-3C34F5944F61/d/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-android-bootstrap/bootstrap/bin/AppiumBootstrap.jar","/data/local/tmp/"]
[debug] [ADB] Attempting to kill all uiautomator processes
[debug] [ADB] Getting all processes with uiautomator
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","ps"]
[info] [ADB] No uiautomator process found to kill, continuing...
[debug] [UiAutomator] Starting UIAutomator
[debug] [ADB] Creating ADB subprocess with args: ["-P",5037,"-s","emulator-5554","shell","uiautomator","runtest","AppiumBootstrap.jar","-c","io.appium.android.bootstrap.Bootstrap","-e","pkg","com.android.calculator2","-e","disableAndroidWatchers",false,"-e","acceptSslCerts",false][debug] [UiAutomator] Moving to state 'online'
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Loading json...
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Registered crash watchers.
[info] [AndroidBootstrap] Android bootstrap socket is now connected
[debug] [ADB] Getting connected devices...
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Client connected
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","dumpsys","window"]
[info] [AndroidDriver] Screen already unlocked, doing nothing
[debug] [ADB] Device API level: 26
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/bytedance/Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","emulator-5554","shell","am","start","-W","-n","com.android.calculator2/.Calculator","-S"][info] [Appium] New AndroidDriver session created successfully, session a6e462f6-38d9-4e7b-8c61-290d91b727ed added to master session list
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1522821145182 (13:52:25 GMT+0800 (CST))
[debug] [MJSONWP] Responding to client with driver.createSession() result: {"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformName":"Android","platformVersion":"8.0","deviceName":"Android Emulator","appPackage":"com.android.calculator2","appActivity":".Calculator"},"platformName":"Android","platformVersion":"8.0.0","deviceName":"emulator-5554","appPackage":"com.android.calculator2","appActivity":".Calculator","deviceUDID":"emulator-5554","deviceScreenSize":"1080x1920","deviceModel":"Android SDK built for x86","deviceManufacturer":"Google"}
[info] [HTTP] <-- POST /wd/hub/session 200 7479 ms - 706
[info] [HTTP] --> POST /wd/hub/session/a6e462f6-38d9-4e7b-8c61-290d91b727ed/element {"using":"id","value":"com.android.calculator2:id/digit1","sessionId":"a6e462f6-38d9-4e7b-8c61-290d91b727ed"}
[debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["id","com.android.calculator2:id/digit1","a6e462f6-38d9-4e7b-8c61-290d91b727ed"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.android.calculator2:id/digit1","context":"","multiple":false}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.android.calculator2:id/digit1","context":"","multiple":false}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.android.calculator2:id/digit1' using 'ID' with the contextId: '' multiple: false
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.android.calculator2:id/digit1][debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.android.calculator2:id/digit1' using 'ID' with the contextId: '' multiple: false
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.android.calculator2:id/digit1]
[debug] [AndroidBootstrap] Received command result from bootstrap
[info] [HTTP] <-- POST /wd/hub/session/a6e462f6-38d9-4e7b-8c61-290d91b727ed/element 500 575 ms - 164
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":7,"value":"No element found"}
2.待更新