【发布时间】:2018-04-23 17:45:38
【问题描述】:
我想做的是通过图像在android屏幕上“单击”/“触摸”,因为我想测试一个游戏,而这个游戏没有任何xpath。 如果我不能使用图像识别,那么我至少想使用坐标在屏幕上“点击”。
但到目前为止,这些选项都没有对我有用。 我已经到这一步了。现在我使用 Appium 驱动程序。
在桌面上使用图像识别:
public void playGame() 抛出 InterruptedException, FindFailed {
Screen screen = new Screen();
String imageLibrary = "src/main/resources/automated-tests/images/";
String skipIntro = imageLibrary + "JackAndTheBeanstalk/skip.PNG";
String skipInfo = imageLibrary + "JackAndTheBeanstalk/continue.PNG";
String bet = imageLibrary + "JackAndTheBeanstalk/increaseStakes.PNG";
String play = imageLibrary + "JackAndTheBeanstalk/play.PNG";
Thread.sleep(10000);
if (screen.exists(new Pattern(skipIntro).similar((float) 0.8)) != null) {
System.out.println("Start playing Jack and the beanstalk");
Thread.sleep(10000);
screen.click(new Pattern(skipIntro).similar((float) 0.8));
screen.click(new Pattern(skipIntro).similar((float) 0.8));
screen.click(new Pattern(skipInfo).similar((float) 0.8));
screen.click(new Pattern(bet).similar((float) 0.8));
screen.click(new Pattern(play).similar((float)0.8));
}
}
此图像识别在桌面上运行良好。我的目标是做到这一点,但在 android 上!但是点击方法不适用于android,只能在桌面上使用。我听说您可以使用点击、执行触摸操作和按下,但我不知道如何使用它们。
在安卓上使用新闻:
TouchAction action = new TouchAction(driver); action.press(10, 0).moveTo(22,33).release().perform();
这里的问题是我不知道如何为 android 获取正确的坐标。
有没有人尝试在 android 上测试自动化手机游戏/或类似的东西,或在 android 上使用图像识别或在 android 上使用坐标?或者你有没有使用不同的策略在 android 或其他设备上测试自动化?
提前致谢!
【问题讨论】:
标签: java android testing automation appium