Appium Plugins

Available Plugins

appium plugin install --source=local <path to plugin>
appium plugin install --source=npm appium-wait-plugin
appium --plugins=element-wait

Plugin Installation

Plugin Activation

Actions API for gestures

Drag & Drop using W3C Action API

Drag & Drop using Actions API

MobileElement dragMe = (MobileElement) new WebDriverWait(driver, 30)
     .until(elementToBeClickable(MobileBy.AccessibilityId("dragMe")));
                
Point source = dragMe.getCenter();
Point target = driver.findElementByAccessibilityId("dropzone").getCenter();
PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");

Sequence dragNDrop = new Sequence(finger, 1);
dragNDrop.addAction(finger.createPointerMove(ofMillis(0),
                PointerInput.Origin.viewport(), source.x, source.y));
                
dragNDrop.addAction(finger.createPointerDown(PointerInput.MouseButton.MIDDLE.asArg()));

dragNDrop.addAction(new Pause(finger, ofMillis(600)));

dragNDrop.addAction(finger.createPointerMove(ofMillis(600),
       PointerInput.Origin.viewport(), target.x, target.y));
       
dragNDrop.addAction(finger.createPointerUp(PointerInput.MouseButton.MIDDLE.asArg()));
        
driver.perform(singletonList(dragNDrop));

How to build your own plugin?

  • Create new routes

  • Override/modify existing Appium Methods

  "dependencies": {
    "@appium/base-plugin": "^1.6.4"
  },  
  "appium": {
    "pluginName": "<plugin name>",
    "mainClass": "<class name>"
  },
  
export default class AppiumPlugin extends BasePlugin {

 async createSession(next, driver, jwpDesCaps, jwpReqCaps, caps) {
   log.info('Building my new appium plugin');
   .....
   await next();
   }
}

Step 1

Step 2

static newMethodMap = {
    '/session/:sessionId/fake_data': {
      GET: {command: 'getFakeSessionData'}
    },
};


async getFakeSessionData (next, driver) {
    await B.delay(1);
    return driver.fakeSessionData || null;
}

Adding new routes

driver.getFakeData()

Server

Client

Drag & Drop using Gestures Plugin

MobileElement source = (MobileElement) new WebDriverWait(driver, 30)
    .until(elementToBeClickable(MobileBy.AccessibilityId("dragMe")));
MobileElement destination = (MobileElement) new WebDriverWait(driver, 30)
    .until(elementToBeClickable(MobileBy.AccessibilityId("dropzone")));

driver.addCommand(HttpMethod.POST, 
	String.format("/session/%s/plugin/actions/dragAndDrop", 
    	driver.getSessionId()), "dragAndDrop");
        
driver.execute("dragAndDrop", ImmutableMap.of(
	"sourceId", source.getId(), 
    "destinationId", destination.getId()));

TODO: Long Press

Appium Plugins Workshop

By Srinivasan Sekar

Appium Plugins Workshop

  • 788