Unable to compare Expected SS to Actual Output

Asked by Justin Veerman

I am simply trying to compare my Expected output screenshot to the Actual output screenshot after running a test.

The following is what I am trying to use:

if (screen.exists(image6.similar(95), timeout) != null) {
   System.out.println("Screenshot matches baseline.");
  }
   else {
    System.out.println("Screenshot does not match baseline.");
  }

I thought it would see if screen exists, if so, then check to see if image6(which is my Expected output) is on the screen(with 95% similarity, being 95% same pixels).

I am unable to get the results I require , such as comparing a screenshot to a screenshot when I know both are exactly the same(I even put 95% similar).

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
Justin Veerman (veerman) said :
#1

Also, I just want to make note of how difficult it was to find some example code. Comparing a screenshot to expected output, I would think, is a common problem for testing automation. There was really only two Sikuli tutorials on Youtube and even they did not address the comparisons.

Revision history for this message
Eugene Maslov (emaslov1) said :
#2

95 is wrong.

found=reg.exists(Pattern("myimage.png").similar(0.95),1)
if found:
    print "match"
else:
    print "no match"

Revision history for this message
Justin Veerman (veerman) said :
#3

Hi Eugene,

Thanks for the response, however I am still a bit confused. What is this code doing? Why is 95 wrong if you included it in your response? Is it right that found is a Match type? You also put (if found), isn't the if supposed to be conditional on it being true?

I tried my best to convert your answer to Java:

 Match found = screen.exists(image6.similar((float) 0.95),1);
  if (found != null) {
   System.out.println("Match");
  } else {
    System.out.println("No Match");
   }

Revision history for this message
RaiMan (raimund-hocke) said :
#4

not knowing, what type image6 has, this is needed to add a wanted similarity score (as seen in Eugene's comment):

Match found = screen.exists(new Pattern(image6).similar(0.95f),1);

Revision history for this message
Justin Veerman (veerman) said :
#5

This did solve my issue, but I am curious why the 1 was needed. I don't really know what the 1 is referring to.

Revision history for this message
RaiMan (raimund-hocke) said :
#6
Revision history for this message
Justin Veerman (veerman) said :
#7

I did look at the docs but I couldn't figure out(before) how to write the commands in Java. I don't know where to find the format for Match within the docs, I am sure there they are but I couldn't find it.

eg Match found = screen.exists(new Pattern(image6).similar(0.95),1);

I usually like seeing an example of code and then applying it to my project, but I found that a bit difficult with the docs.

Revision history for this message
Eugene Maslov (emaslov1) said :
#8

Justin, the magic help tool is Google. If a problem is solvable, Sikuli examples are usually present in the web, e.g. "sikuli java exists image not found", or a similar phrase, returns the examples, e.g. https://answers.launchpad.net/sikuli/+question/146397 .

Revision history for this message
Justin Veerman (veerman) said :
#9

I understand. I just meant that having a start to finish example(a simple use-case) showing how Java/Selenium/Sikuli integrate with each other would be helpful. I tried to piece together examples from different places.

Thanks for your help.

Revision history for this message
Best RaiMan (raimund-hocke) said :
#10

@Justin
Ok, understood.
So if you are more the type "programming-by-example", then the docs of Sikuli currently do not have much for Java. Here I fully agree with Eugene. I will surely enhance that over the next months.

... but on the other hand: a Java programmer must be able to read javadocs:
http://nightly.sikuli.de/docs/index.html

so since
screen.exists(new Pattern(image6).similar(0.95),1);

returns a Match object, it has to be
Match myMatch = screen.exists(new Pattern(image6).similar(0.95),1);

to store the Match object for later use.

Revision history for this message
Justin Veerman (veerman) said :
#11

Thanks RaiMan, that solved my question.