WebElement bouncingBall = driver.findElementById("com.example.app:id/bouncing_ball");
TouchAction action = new TouchAction(driver); action.longPress(ElementOption.element(bouncingBall)) .moveTo(PointOption.point(500, 1000)) .release() .perform();
Dimension screenSize = driver.manage().window().getSize(); int screenWidth = screenSize.getWidth(); int screenHeight = screenSize.getHeight(); int ballSize = bouncingBall.getSize().getWidth(); int ballStartPositionX = bouncingBall.getLocation().getX(); int ballEndPositionX = ballStartPositionX + 500; int ballStartPositionY = bouncingBall.getLocation().getY(); int ballEndPositionY = ballStartPositionY + 1000 - ballSize / 2; if (ballEndPositionY > screenHeight) { ballEndPositionY = screenHeight - ballSize / 2; }
Assert.assertEquals(bouncingBall.getLocation().getX(), ballEndPositionX); Assert.assertEquals(bouncingBall.getLocation().getY(), ballEndPositionY);
通过这些步骤,就可以在移动应用程序中检查动画中弹球的位置了。