我想要做的是通过图像在android屏幕上“点击”/“触摸”,因为我想测试一个游戏,而这个游戏没有任何xpath。如果我不能使用图像识别,那么我至少希望使用坐标在屏幕上“点击”。
但到目前为止,这些选择对我来说都不起作用。我已经走了这么远。现在我使用的是Appium驱动。
在桌面上使用图像识别:
公共空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上不起作用,只能在桌面上起作用。我听说你可以用tap,performTouchAction和press来代替,但我不知道如何使用它们。
在ANDROID上使用PRESS:
TouchAction TouchAction=新驱动程序;action.press(10,0).moveTo(22,33).release().perform();
这里的问题是,我不知道如何为android获得正确的坐标。
有没有人尝试过在android上测试自动化手机游戏/或类似的东西,或者在android上使用图像识别,或者在android上使用坐标?或者,您是否使用了不同的策略在android或其他设备上测试automate?
提前感谢!
发布于 2017-11-11 00:43:55
目前还不清楚你正在使用什么库来进行图像识别(你要导入什么来使用Screen类?)。
但很明显,只有Appium是不足以测试它的。
您可以研究Appium + Sikuli API或Appium+OpenCV原型。
到目前为止有几个链接:
https://stackoverflow.com/questions/47223751
复制相似问题