Search code examples
javascriptwebdriverappiumwebdriver-io

drag&drop faster in appium


I am testing application trough appium with webdriver.io library. In there I have simple JS code, where I open screen testing application and then draw the line from one point to another. Problem is I don't know how to change speed which the line is drawing. I couldn't find any documentation.

Here is all my code:

const wdio = require("webdriverio")
const opts = {
  port: 4723,
  capabilities: {
    platformName: "Android",
    deviceName: "cbb3309d",
    appPackage: "jp.rallwell.siriuth.touchscreentest",
    appActivity: ".TouchScreenTestActivity",
    automationName: "UiAutomator2",
    noReset: true,
  }
}

function timeout(ms) {
  return new Promise(resolve => setTimeout(resolve, ms))
}

async function main() {
  const client = await wdio.remote(opts)
  client.setTimeouts(15000)
  await timeout(5000)
  client.touchAction([
        { action: 'longPress', x: 500, y: 100,},
        { action: 'moveTo', x: 500, y: 2000},
        'release'
])
}

main()

Solution

  • I found there is another function for it so I created my own function:

    async function dragAndDrop(options) {
        let actions = new wd.W3CActions(driver);
        let touchInput = actions.addTouchInput();
        touchInput.pointerMove({
            duration: 0,
            x: options.fromX,
            y: options.fromY
        });
        touchInput.pointerDown({
            button: 0
        });
        touchInput.pause({
            duration: options.pressTime
        });
        touchInput.pointerMove({
            duration: options.moveTime,
            x: options.toX,
            y: options.toY
        });
        touchInput.pause({
            duration: options.releaseTime
        });
        touchInput.pointerUp({
            button: 0
        });
        await actions.perform();
    }