0

Can not find Image path in Upload document script using Sikuli with selenium web driver, I am using latest Sikuli jar. I am getting following Error while running followed code snippet:

Screen src = new Screen();
Match addFile= src.find("C:\\Users\\Inknopwledge\\Desktop\\TestSikuli\\Capture.PNG");


FindFailed: can not find C:\Users\Inknopwledge\Desktop\Sikuli\Capture.PNG on the screen.
Line ?, in File ?
    at org.sikuli.script.Region.handleFindFailed(Region.java:420)
    at org.sikuli.script.Region.wait(Region.java:511)
    at org.sikuli.script.Region.find(Region.java:381)
    at pagefactory.profile_section.ResearchandExp_pageFact.click_Attach_Documents(ResearchandExp_pageFact.java:195)
    at TestCase.ResearchandExpertise_TC.attach_Document_to_Research(ResearchandExpertise_TC.java:311)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Unable to upload document [Ljava.lang.StackTraceElement;@17c395e
Shweta Tetambe
  • 21
  • 1
  • 3
  • 8

2 Answers2

0

"As per your statement Exception is : FindFailed: can not find C:\Users\Inknopwledge\Desktop\Sikuli\Capture.PNG on the screen.

This exception occurs when image with given path not found on screen within 3 second (default auto wait timeout for find operation in sikuli is 3 seconds) with default simillarity 0.7

You can make wait to load image then use find command or use:

Screen s = new Screen();
Pattern p = new Pattern ("img path/path").similar( (float) 0.7);
if (s.exists(p , 7) != null) {
Match match = s.getLastMatch();
}

Above command wait for 7 sec for image to appear on screen. Change your similarity percentage to get match. you image may be different form that displayed on app.

Umesh
  • 121
  • 6
  • Thanks Umesh, I tried above snippet. But Getting [error] Can't create OS Util: org.sikuli.script.Win32Util error at Line Screen s= new Screen(); – Shweta Tetambe Jul 28 '15 at 12:05
  • please see the link : https://bugs.launchpad.net/sikuli/+bug/893909 this is bug and appear in some machine. Please try using |Region object instead of Screen object. like this : Region r = new Region (....); r.exists .... – Umesh Jul 29 '15 at 19:07
  • Thnx I am using following code to enter file location using sikuli, But Is There any way to specify dynamic location as per different system.. if (src.exists(fileName , 10) != null) { System.out.println("File Name Pattern exist.."); Match match = src.getLastMatch(); match.find(fileName); match.click(fileName); match.type(fileName, "Z:\\mentis_test_v2\\Sikuli\\20150429-NSFBio-Gray.docx"); match.setAutoWaitTimeout(50); } – Shweta Tetambe Jul 31 '15 at 11:40
0

I had the same issue when using this in conjunction with Appium Driver. I realized that the image that I was snipping using my mac was not the one Sikuli could find. There are two resolutions then:

  1. Download and install Sikuli IDE and use that for the snaps
  2. Use the following code:

    import org.sikuli.script.FindFailed;

    import org.sikuli.script.Screen;

    public void capture (String path){

    Screen screen = new Screen();

    screen.userCapture().save(path);

    }

This would basically freeze the screen and allow you to snip the image and store it in the path which you mention. You can use an IDE to run this or create an executable jar file to run it from command line

prakash krishnan
  • 801
  • 6
  • 10