Take a screenshot during dragging in Appium

2019-05-28 21:13发布

In Android, I need to drag an object in my app and take a screenshot WHILE STILL HOLDING the object.

I know that there are two ways of using touch actions (I'm not even considering the higher-level methods such as swipe() as they give me much less control over my touch actions):

new TouchAction(driver).press(element).moveTo(x,y).release().perform();

and

driver.performTouchAction(new TouchAction(driver).press(element).moveTo(x,y).release());

When I try to divide my touch action into two parts, and inserting a screenshot capture in between as in the code below:

new TouchAction(driver)
    .press(x,y)
    .moveTo(newX,newY)
    .perform();

takeScreenshot(); // My own implementation for readability 

new TouchAction(driver)
    .release()
    .perform();

I get the following error:

org.openqa.selenium.WebDriverException: ERROR running Appium command: Cannot read property 'x' of null
Command duration or timeout: 14 milliseconds

The program fails during the second touch action, i.e., the screenshot is being successfully taken, but I have no way of releasing the object after grabbing it in this manner.

Any ideas?

1条回答
倾城 Initia
2楼-- · 2019-05-28 21:51

By looking at your question

new TouchAction(driver)
    .release()
    .perform();

for release provide some x and y location to release have a try might work

查看更多
登录 后发表回答