Appium Android Driver是Android设备的测试自动化工具。Appium Android驱动程序自动化原生的,混合的和移动的Web应用程序,在模拟器,仿真器和真实设备上进行测试。Appium Android驱动程序是Appium移动测试自动化工具的一部分。

注意:此repo的问题跟踪已被禁用。请改用主要的Appium问题追踪器

  

安装

npm install appium-android-driver

  

用法

导入Android驱动程序,设置所需功能并创建会话:

import { AndroidDriver } from `appium-android-driver`
 
let defaultCaps = {
  app: 'path/to/your.apk',
  deviceName: 'Android',
  platformName: 'Android'
};
 
let driver = new AndroidDriver();
await driver.createSession(defaultCaps);

 运行命令:

await driver.setOrientation('LANDSCAPE');
console.log(await driver.getOrientation()); // -> 'LANDSCAPE'

 

指定和选择设备/仿真器

驱动程序将根据desiredCapabilities对象中的这些属性尝试连接到设备/仿真器:

  1. avd:以给定的名称启动或连接到仿真器。
  2. udid:使用给定的UDID连接到设备。
  3. platformVersion:连接到操作系统以所需操作系统开始的第一个设备或主动仿真器。这意味着如果有多个可用,将从输出中platformVersion: 5获取第一个5x设备adb devices

如果没有给出这些功能,驱动程序将连接到从输出返回的第一个设备或主动仿真器adb devices

如果给出了这些功能中的多个功能,驱动程序将仅使用上述顺序的功能。那就是avd优先考虑udid,优先考虑platformVersion

命令

  1 command
  2 activateIMEEngine
  3 availableIMEEngines
  4 back
  5 background
  6 clear
  7 click
  8 complexTap
  9 deactivateIMEEngine
 10 defaultContextName
 11 defaultWebviewName
 12 doKey
 13 doTouchAction
 14 doTouchDrag
 15 drag
 16 elementDisplayed
 17 elementEnabled
 18 elementSelected
 19 fakeFlick
 20 fakeFlickElement
 21 findElOrEls
 22 fixRelease
 23 flick
 24 getActiveIMEEngine
 25 getAlertText
 26 getAttribute
 27 getContexts
 28 getCurrentActivity
 29 getCurrentContext
 30 getDeviceTime
 31 getDisplayDensity
 32 getLocationInView
 33 getLog
 34 getLogTypes
 35 getName
 36 getNetworkConnection
 37 getOrientation
 38 getPageSource
 39 getScreenshot
 40 getSize
 41 getStrings
 42 getSystemBars
 43 getText
 44 getWindowSize
 45 hideKeyboard
 46 installApp
 47 isAppInstalled
 48 isIMEActivated
 49 isKeyboardShown
 50 isLocked
 51 isWebContext
 52 keyevent
 53 keys
 54 lock
 55 longPressKeyCode
 56 onChromedriverStop
 57 openNotifications
 58 openSettingsActivity
 59 parseTouch
 60 performGesture
 61 performMultiAction
 62 performTouch
 63 pinchClose
 64 pinchOpen
 65 postAcceptAlert
 66 postDismissAlert
 67 pressKeyCode
 68 pullFile
 69 pullFolder
 70 pushFile
 71 removeApp
 72 replaceValue
 73 reset
 74 setAlertText
 75 setContext
 76 setGeoLocation
 77 setLocation
 78 setNetworkConnection
 79 setOrientation
 80 setValue
 81 setUrl
 82 startActivity
 83 startChromedriverProxy
 84 stopChromedriverProxies
 85 suspendChromedriverProxy
 86 swipe
 87 tap
 88 toggleData
 89 toggleFlightMode
 90 toggleLocationServices
 91 toggleSetting
 92 toggleWiFi
 93 touchDown
 94 touchLongClick
 95 touchMove
 96 touchUp
 97 unlock
 98 unlockWithHelperApp
 99 unlockWithUIAutomation
100 wrapBootstrapDisconnect

API备注

lock在Android中的行为与iOS中的行为不同。在Android中,它没有任何参数,并锁定屏幕并立即返回。

Development

Transpile ES2015 code

gulp transpile

  

Watch

npm run watch

  

Test

npm test

  

一些测试需要特定的仿真器。目前它们有两个方面:

  1. API级别25:将ANDROID_25_AVD环境变量设置为avd的名称,或默认为"Nexus_5_API_25"如果不存在,则跳过测试。
  2. API级别24:将ANDROID_24_NO_GMS_AVD环境变量设置为avd的名称,或默认为"Nexus_5_API_24"如果不存在,则跳过测试。

一些测试还需要特定版本的Chromedriver(特别是2.20),该test/assets文件夹中可用,或者可以使用 CHROME_2_20_EXECUTABLE环境变量指定。

内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!