A wrapper for wd node package optimized for Android to work with appium.io.

Install

npm install wd - android

Prerequisites

You need to install Appium.

You can install with npm:

npm install - g appium

or download it from appium website.

and then check if your ANDROID_HOME and JAVA_HOME are correctly.

You can achieve this by running:

$ appium-doctor --android Running Android Checks ✔ ANDROID_HOME is set to "/path/to/android/sdk" ✔ JAVA_HOME is set to "/path/to/java/sdk" ✔ ADB exists at /sdk/platform-tools/adb ✔ Android exists at /sdk/tools/android ✔ Emulator exists at /sdk/tools/emulator ✔ Android Checks were successful. ✔ All Checks were successful

If you're usigin Android Studio and you have installed the sdk in Android Studio folder, may you need to run:

$ ln -s /path/to/Android Studio.app /path/to/AndroidStudioApp $ export ANDROID_HOME=/path/to/AndroidStudioApp/sdk

Cause Appium doesn't work with spaces in ANDROID_HOME or JAVA_HOME paths.

Before start

Before launch your script with wd-android you need to run the appium server. It's quite simple:

$ appium

Usage

How to instantiate:

var wd = require ( ' wd ' ) , WdAndroid = require ( ' wd-android ' ) ; var wdAndroid = new WdAdndroid ( wd ) ; var driver = wdAndroid . promiseChainRemote ( ) ; driver . init ( ) . setImplicitWaitTimeout ( 10000 ) ; driver . viewPagerElement ( ) . swipe ( { startX : 0 . 9 , startY : 0 . 5 , endX : 0 . 1 , endY : 0 . 5 , duration : 800 } ) . waitForLinearLayout ( ) . click ( ) ;

Api

More friendly methods to referer to Android Elements than by XPath.

driver . frameLayoutElement ( ) ; driver . linearLayoutElement ( ) ; driver . listViewElement ( ) ; driver . viewPagerElement ( ) ; driver . webViewElement ( ) ;

Simple Id

Pass the default package as secondo arguments in wd-android constructor to find element by their simple ids.

driver . elementById ( ' com.example.app:id/productsList ' ) ; var wdAndroid = new WdAndroid ( wd , ' com.example.app ' ) ; ... ... driver . elementBySimpleId ( ' productsList ' )

Sub-elements Reference

Access the sub-elements by passing parent element id.

N.B.: The original wd module hasn't this feature.

And yes, you can use the simple elements ids.

driver . frameLayoutChildren ( ' com.example.app:id/viewPager ' ) . then ( function ( els ) { return els [ 1 ] . click ( ) ; } ) . linearLayoutChildren ( ' productList ' ) . then ( function ( els ) { return els [ 1 ] . click ( ) ; } ) ;

Alerts

Access the alert dialog showed without pain.

driver . elementBySimpleId ( ' takeButtonBox ' ) . click ( ) . shouldAppearAlertElement ( ) . positiveAlertButton ( ) . text ( ) . should . become . eql ( " Ok " ) . negativeAlertButton ( ) . text ( ) . should . become . eql ( " Cancel " ) ;

Mobile Gestures

Built in methods to perform mobile gestures.

driver . swipe ( { startX : 0 . 9 , startY : 0 . 5 , endX : 0 . 1 , endY : 0 . 5 , duration : 800 } ) ;

Mobile Gestures for specific element

driver . elementById ( ' com.example.app:id/loginButton ' ) . swipeElement ( { startX : 0 . 9 , startY : 0 . 5 , endX : 0 . 1 , endY : 0 . 5 , duration : 800 } ) ; driver . elementById ( ' com.example.app:id/loginButton ' ) . tapElement ( { x : 0 . 9 , y : 0 . 5 } ) ;

Should integration

driver . . elementById ( ' com.example.app:id/loginButton ' ) . then ( function ( el ) { return el . getTagName ( function ( err , name ) { return name ; } ) ; } ) . then ( function ( name ) { return name . should . be . eql ( ' android.widget.Button ' ) } ) ; driver . elementById ( ' com.example.app:id/loginButton ' ) . shouldBeButtonElement ( )

Mocha Integration