1

我正在使用sikuli-script.jar單擊圖像鏈接與Selenium WebDriver(與TestNG框架)。當我運行我的代碼運行TestNGSuite或螞蟻運行(從命令提示符)時,同樣工作正常。 下面是我的代碼: -Jenkins引發FindFailed:異常Sikuli

WebDriver driver=new FirefoxDriver(); 
driver.get("http://google.com"); 
driver.manage().window().setSize(new Dimension(1366, 768));  
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); 
System.out.println("Title is " +driver.getTitle()); 
System.out.println("Browser opened"); 
try { 


Screen s=new Screen(); 
Pattern image=new Pattern("D:\\LoyalityFiles\\gmail\\1476714460371.png"); 

s.find(image); 
s.click(image); 
System.out.println("clicked on gmail"); 
System.out.println("Title of this page is " +driver.getTitle()+" and url is " +driver.getCurrentUrl()); 

driver.quit(); 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

} 

問題: - 當通過詹金斯運行此代碼,它拋出: -

FindFailed: can not find P(D:\LoyalityFiles\gmail\1476714460371.png) S: 0.7 on the screen. 
    [testng] Line 1574, in file Region.java 
    [testng] 
    [testng]  at org.sikuli.script.Region.handleFindFailed(Region.java:1574) 
    [testng]  at org.sikuli.script.Region.wait(Region.java:1682) 
    [testng]  at org.sikuli.script.Region.find(Region.java:1590) 
    [testng]  at sikuli.ImageC.Google(ImageC.java:33) 
    [testng]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    [testng]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    [testng]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    [testng]  at java.lang.reflect.Method.invoke(Method.java:606) 
    [testng]  at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85) 
    [testng]  at org.testng.internal.Invoker.invokeMethod(Invoker.java:639) 
    [testng]  at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816) 
    [testng]  at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124) 
    [testng]  at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) 
    [testng]  at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108) 
    [testng]  at org.testng.TestRunner.privateRun(TestRunner.java:774) 
    [testng]  at org.testng.TestRunner.run(TestRunner.java:624) 
    [testng]  at org.testng.SuiteRunner.runTest(SuiteRunner.java:359) 
    [testng]  at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354) 
    [testng]  at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312) 
    [testng]  at org.testng.SuiteRunner.run(SuiteRunner.java:261) 
    [testng]  at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) 
    [testng]  at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) 
    [testng]  at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215) 
    [testng]  at org.testng.TestNG.runSuitesLocally(TestNG.java:1140) 
    [testng]  at org.testng.TestNG.run(TestNG.java:1048) 
    [testng]  at org.testng.TestNG.privateMain(TestNG.java:1355) 
    [testng]  at org.testng.TestNG.main(TestNG.java:1324) 

請注意: - 我運行詹金斯作爲Windows服務。請提出建議!

+0

您的測試運行在哪裏?詹金斯是那個機器嗎?該機器是否附有物理屏幕,您可以看到發生了什麼? –

+0

我在我的代碼託管的本地機器上運行我的jenkins。我的意思是jenkins和代碼都在同一臺機器上,而且我正在運行jenikns作爲windows服務。 –

+0

將詹金斯作爲服務運行可能是您的問題。找到負責Jenkins的Java進程並殺死它。然後再從命令行再次手動啓動Jenkins。然後再試一次。 –

回答

0

SikuliX在3秒內無法在屏幕上找到您的圖案(默認值爲Settings.AutoWaitTimeout),並拋出FindFailed異常。嘗試提高Settings.AutoWaitTimeout或實施自己的智能服務員而不是screen.find()

+0

: - 你可以寫代碼,我需要使用,而不是screen.find() –