Sikuli with Selenium Java
I have successfully able to configure Sikuli with Selenium Web Driver. When I tried to automate calculator I was properly able to open calculator and click on the buttons.
However, when I am not able to validate the value in textbox of calculator.
Below is my code:
import java.io.
import java.io.
import java.io.
import java.util.
import org.sikuli.
import org.sikuli.
import org.sikuli.
import org.testng.
public class SikuliTest {
public static void main(String[] args) throws IOException, FindFailed, InterruptedExce
Properties deskIcon = new Properties();
deskIcon.load(new FileInputStream
Screen scrn = new Screen();
App.open(
scrn.
scrn.
scrn.
scrn.
scrn.
scrn.
scrn.
scrn.
if (deskIcon.
System.
}
else{
System.
}
}
}
The if condition is not working properly. It's not validating the value in textbox image (Calc_Scrn).
Please suggest how we can validate it.
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- SikuliX Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- RaiMan
- Solved:
- Last query:
- Last reply:
Revision history for this message
|
#1 |
The API you are using is not SikuliX.
The imports seem to reference some RC3 stuff (sikuli-script.jar ??).
Version 1.0.1 does not have:
org.sikuli.
org.sikuli.
the click function for RC3 reads
scrn.click(
... so what should click(some_image, 100) mean?
SikuliX has OCR based on Tesseract with the usage:
String text = some_region.text()
but I think the calculator numbers are not OCR-readable.
SikuliX does not know a feature:
deskIcon.
Taking your systematic, the deskIcon.
So where did you get your "Sikuli-API-ideas" ???
Revision history for this message
|
#2 |
As I have mentioned in the description "deskIcon" is the location where I have kept all the images.
I am able to click on Calculator's button using my code. click(some_image, 100) means that "click on the image and wait for 100 milliseconds before next click.
By using deskIcon.
Actually, I don't know how to get and validate the value in "Calc_Scrn" (image).
For more specification I am trying the below program:
Open Calculator -> Click on 1 -> Click on 0 -> Click on 0 -> Click on + -> Click on 1 -> Click on 0 -> Click on 0 -> Click on = (The answer appears is 200. Now If the value in answer text box is 200 then print PASS else print FAIL.
Thanks.
Revision history for this message
|
#3 |
what you wanted to do is clear - its somehow obvious.
... but you did not answer the question:
So where did you get your "Sikuli-API-ideas" ???
a feature
click(image, waittime)
does not exist in SikuliX.
So what version of Sikuli are you using?
Revision history for this message
|
#4 |
i installed sikuli 1.6
i have added sikuli .jar api to my selenium library and then i wrote this code.
does that helped u?
Revision history for this message
|
#5 |
if u want we can have a screeshare session. just mail it to me so that you will get more idea on it.
Revision history for this message
|
#7 |
I have downloaded "Sikuli-r930-win32" from Sikuli website. And then added .jar files from downloaded version to my selenium project. So that I can code using Selenium JAVA.
You can refer below link for example:
Revision history for this message
|
#8 |
Hi RaiMan, any update or solution to my problem?
Revision history for this message
|
#9 |
still you did not answer my questions in comment #3
You have to use the Sikuli API correctly.
Revision history for this message
|
#10 |
For your question where did you get your "Sikuli-API-ideas" ??? I have implemented it as per its mentioned on http://
So what version of Sikuli are you using? I have downloaded and extracted "Sikuli-r930-win32" and then added .jar files to my Selenium Library.
I thinks these are the proper answer I have.
Revision history for this message
|
#11 |
repeating things does not make it clearer.
the mentioned link shoes how to access sikuli-script.jar in a Java program, but does not talk about specific API features like yours:
click(image, wait time)
and
if (deskIcon.
So where did you get the idea, that this should work as you expect?
Did you ever look into the docs?
On the other hand I strongly recommend, to use version 1.0.1+ if you are planning to use Sikuli for more than some playground actions.
Start here: http://
and read carefully, before doing anything.
This is important: https:/
Revision history for this message
|
#12 |
Thanks, I will go through it.
Can you tell me the solution for which I am trying for "How to verify the value (200) from calculator." I am pursuing it from more that 15 days.
Please give your solution or code for the issue which I have documented initially.
Thanks in advance.
Revision history for this message
|
#13 |
SikuliX has the OCR feature Region.text()
see docs
about problems and advices you find many entries here.
Revision history for this message
|
#14 |
I have downloaded Sikuli X from the link you have provided but after installing it I didn't find sikuli-java.jar in the folder. I have already added sikuli-script.jar in the class path of the project.
I tried with OCR Region.text() and could not find the any solution. As this is one of the first script I am writing using Sikuli and Java, please help me with this.
I know I have taken much time of yours but this will be very helpful for me in future. As lot of script writing depends on verification and validations using IF conditions.
Revision history for this message
|
#15 |
I am unable to import "import org.sikuli.
Revision history for this message
|
#16 |
so you did not have run setup accordingly.
If you want the IDE + sikuli-java.jar select option 3
If you only want only sikuli-java.jar select option 4
This is clearly mentioned in the setup dialog and behind the help buttons.
sikuli-script.jar is from version RC3
if you use 1.0.1, it is sikuli-java .jar (as clearly mentioned in the above link comment #11 This is important: …
… and you should follow the advice exactly.
Revision history for this message
|
#17 |
… and if you decide to try 1.0.1, purge anything from your system and environment, that belongs to RC3.
Revision history for this message
|
#18 |
Hi RaiMan,
I was able to follow the instruction properly and I got the below error when i tried to execute the script:
[error] ResourceLoaderB
[error] ResourceLoaderB
[action] ResourceLoaderB
[error] ResourceLoaderB
[error] Terminating SikuliX after a fatal error(102)! Sorry, but it makes no sense to continue!
If you do not have any idea about the error cause or solution, run again
with a Debug level of 3. You might paste the output to the Q&A board.
Revision history for this message
|
#19 |
As clearly mentioned in the docs and infos about how to setup 1.0.1+:
Do not use a folder in the program folder. Put the Sikuli stuff into a folder, that is fully user writable.
Do not use blanks in the folder name.
recommended:
c:\SikuliX\
Revision history for this message
|
#20 |
Your suggestions are helping but I am still not able to read the value.
I have written below code to read the value:
if (scrn.find(
//scrn.
System.
}
else{
System.
But when I Watch scrn.find(
And when I trie dto watch scrn.find(
This is the only propblem I am facing now.
Please help me with this.
Revision history for this message
|
#21 |
I successfully ran this script on Windows 7 with the Calculator app and got finally printed
Pass: 200
imgRechner = Pattern(
if not exists(imgRechner, 0):
click(
find(imgRechner)
regResult = Region.
click(Pattern(
regResult.
click(Pattern(
click(Pattern(
click(Pattern(
click(Pattern(
click(Pattern(
Settings.
wait(1)
txtResult = result.text()
if "200" in txtResult:
print "Pass:", txtResult
else:
print "Fail"
Revision history for this message
|
#22 |
ok, you have to convert this to Java ;-)
Revision history for this message
|
#23 |
Well that's the problem......... I have to convert it in JAVA and I am stuck with IF condition. :-(
Revision history for this message
|
#24 |
ok, in Java:
Screen s = new Screen();
Pattern imgRechner = new Pattern(
if null = s.exists(
s.click(
}
s.find(imgRechner);
Region regResult = Region.
s.click(new Pattern(
regResult.
s.click(new Pattern(
s.click(new Pattern(
s.click(new Pattern(
s.click(new Pattern(
s.click(new Pattern(
Settings.
s.wait(1);
String txtResult = result.text();
if txtResult.
System.
else
System.
Revision history for this message
|
#25 |
Hi RaiMan,
Thanks for the code. I am able to execute the code successfully after making some changes. However, I am getting error message.
Below is the code I am executing:
public class SikuliTest {
public static void main(String[] args) throws IOException, FindFailed, InterruptedExce
Properties deskIcon = new Properties();
deskIcon.load(new FileInputStream
App.open(
Screen s = new Screen();
Pattern imgRechner = new Pattern(
if (s.exists(
s.click(new Pattern (deskIcon.
}
s.find(
Region regResult = Region.
regResult.
s.click(
s.click(
s.click(
s.click(
s.click(
s.click(
s.click(
s.click(
Settings.
String txtResult = regResult.text();
if (txtResult.
System.
else
System.
}
}
And I am getting below error message:
[log] App.open calc.exe(5168)
[log] CLICK on L(899,293)@S(0)[0,0 1152x864]
[error] Region(
[log] highlight R[866,292 69x-77]@Screen null E:Y, T:3.0 for 2.0 secs
[error] Region(
Exception in thread "main" java.lang.
at org.sikuli.
at org.sikuli.
at org.sikuli.
at org.sikuli.
at org.sikuli.
at SikuliTest.
Please help with this NullPointerExec
Revision history for this message
|
#26 |
Region regResult = Region.
not really clear what you want to say with a negative height??
Region.
corresponds to
Region.
where you have:
someLocation = s.getLastMatch(
is valid and gets the top left corner of the new region
with a width of 69 and a
height of -77 ????????
Revision history for this message
|
#27 |
Ok!! 69 and -77 is x and y for target :-(
I dont know how to calculate or get the width and height.
Revision history for this message
|
#28 |
Any help to calculate height and width of image.
Revision history for this message
|
#29 |
Hey got the height and width but I am getting error as "[error] TextRecognizer: init: tessdata folder not found at C:/SikuliX/libs/" Hence, String txtResult = regResult.text(); is showing "No Text"
Please help
Revision history for this message
|
#30 |
… height and width of image
of what image?
you have
Match m = s.getLastMatch()
and m is a Region that has m.w and m.h which corresponds to the width and height of the image that was use with the last search op in s:
s.find(
hence the respective image is imgRechner.
Revision history for this message
|
#31 |
ok.
Did you run setup with the text option?
If you did, then just delete the libs folder once and start all over with your test - the libs folder will be recreated now hopefully ;-) with the tessdata folder.
Revision history for this message
|
#32 |
I am still getting an error message as:
[error] TextRecognizer: init: tessdata folder not found at C:/SikuliX/libs/
[error] Region.text: text recognition is now switched off
Please help
Revision history for this message
|
#33 |
I deleted libs folder and ran the test but same error again :-(
Revision history for this message
|
#34 |
then your sikuli-java.jar does not contain the tessdata folder (not selected at setup).
So you have to run setup again:
- delete everything in the folder containing sikulix-setup.jar except sikulix-setup.jar
- run setup again
- select options 4 and 5
- after successful setup (now have sikuli-java.jar) delete the libs folder
- proceed with your work
Revision history for this message
|
#35 |
Yes it helped and the script executed properly.
Now the only problem is regResult.text() is showing "--No Text--"
Hence, it goes to 'else' in below If condition
String txtResult = regResult.text();
if (txtResult.
System.
else
System.
}
If you want to see the complete code then below is the code.
public class SikuliTest {
public static void main(String[] args) throws IOException, FindFailed, InterruptedExce
Properties deskIcon = new Properties();
deskIcon.load(new FileInputStream
App.open(
Screen s = new Screen();
Match m = s.getLastMatch();
Pattern imgRechner = new Pattern(
if (s.exists(
s.click(new Pattern (deskIcon.
}
s.find(
Region regResult = Region.
regResult.
s.click(
s.click(
s.click(
s.click(
s.click(
s.click(
s.click(
s.click(
Settings.
String txtResult = regResult.text();
if (txtResult.
System.
else
System.
}
}
This is the only issue I am facing now. Thanks in advance.
Revision history for this message
|
#36 |
Found out the cause, actually it is not finding and highlighting the right side of calculator screen (where we get the numbers) that's why it is showing as "--No Text--".
I tried lots of steps but unable to highlight the specific area of calculator's screen.
Revision history for this message
|
#37 |
This is an alternative to evaluate the result area:
App("Calculator
Region regResult = App.focusedWind
regResult.
String result = regResult.text()
Revision history for this message
|
#38 |
… but the --no text-- returned value means, that you still do not have your text feature ready.
at the beginning of your code put:
org.sikuli.
and check the log output.
You may send the log output silently to my mail at https:/
Revision history for this message
|
#39 |
I found the issue and my issue is resolved :-)
Thanks for your help Raiman..... You are very helpful and instant responces
Revision history for this message
|
#40 |
Thanks RaiMan, that solved my question.