我在Java中使用sikuli,当前的IDE是eclipse氧气
这是我的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Automation</groupId>
<artifactId>SeleniumTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>LATEST</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sikulix</groupId>
<artifactId>sikulixapi</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
</project>
我的代码就像这样
@Test(description = "spin test")
public void spinLongPeriod() throws Exception {
int wait_time, last = 5000;
caseReq.addAll(Arrays.asList(
new Pattern("src/test/resources/spin.png"),
new Pattern("src/test/resources/spin-stop.png"),
new Pattern("src/test/resources/spin-disabled.png"),
new Pattern("src/test/resources/good-luck.png"),
new Pattern("src/test/resources/spin-auto.png")
));
screen.wait(caseReq.get(0), 10);
while (last >= 0) {
screen.click(caseReq.get(0));
screen.click(caseReq.get(1));
wait_time = 60;
screen.wait(caseReq.get(0), wait_time);
// while (wait_time >= 0) {
// Thread.sleep(1000);
// wait_time -= 1000;
// if (screen.exists(caseReq.get(0)) != null) {
// break;
// }
// }
--last;
}
}
我放弃了sikuli Screen.wait方法,因为它失败了
暂时使用“while + Thread.sleep”解决方案
但这次没有出现错误信息
FindFailed: can not find P(src/test/resources/spin-stop.png) S: 0.7 in S(0)[0,0 1920x1080]
我长期从互联网上寻求解决方案......
有什么建议吗?
答案 0 :(得分:0)
我使用下一个方法
private boolean exists(Pattern img, int sec) {
try {
window.wait(img, sec);
return true;
} catch (FindFailed exeption) {
return false;
}
}
效果很好。如果找不到某些图像,请尝试通过.similar((float)0.5);
进行调整