How to get actual image if the expected image was not found

Asked by belemekadem yassine

Hi,
In a test case, I use assert(exists(<expected-screenShot.png>.similar(80%))) and I get a failure ( assertion error ) which is normal in my case.
Is there a way to get the actual screen shot image if the expected screen shot image was not found ?

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

import shutil
shot = capture(SCREEN)
shutil.move(shot, "absolute-path-of-image.png")

the target directory must exist.

to pack this in test:

res = exists(Pattern(img).similar(0.8))
if not res:
    import shutil
    shot = capture(SCREEN)
    shutil.move(shot, "absolute-path-of-image.png")
assert(res)

Revision history for this message
belemekadem yassine (m-y-belemkadem) said :
#2

Thank you RaiMan.

I suppose that "exists(Pattern(img).similar(0.8))" take a screen shot a compare the given image with the screen shot.

My question is:

The image returned by capture(SCREEN) and the one used in "exists" are the same ?

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

To be sure, take your shot before using exists() (max 3 seconds difference).
If your screen is static during this time: Yes, same image.

If this is really critical for you and you are familiar with Java programming, you might add some Java code, to access the last taken screen shot, which is stored with the relevant region as a buffered image.

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

Not really clear, saying: To be sure, take your shot before using exists() (max 3 seconds difference).

When searching the whole screen, you have about one screenshot per second (might be more with smaller regions (up to 3-5 per second)).

So it depends on your intention: need the shot before or/and after the completion of the find operation (which might fail)?

Can you help with this problem?

Provide an answer of your own, or ask belemekadem yassine for more information if necessary.

To post a message you must log in.