Take a screenshot of a region

Asked by William Elmer

Raimans Number one Fan here! :P

I have a quick question, I am writing a automation test, I have a script to write in some data, I would then like to come back and verify that data from the same data file. However due to some OCR problems that are currently outstanding I would like to tkae a screenshot of anything that fails and write to a log file.
So I would like to know the syntax on how to do that

Thanks!

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
j (j-the-k) said :
#1

see http://doc.sikuli.org/screen.html#Screen.capture

Use capture() to capture the whole screen.
The save location will be returned as a string.

Revision history for this message
William Elmer (william-elmer) said :
#2

So the syntax would look something like...

If(x != reg.print)
stringVar = reg.capture()
else
image.click()

#convert above to tabbed and python code :P I just wrote quick. but I wanna know if this is the generic syntax to use.

Revision history for this message
William Elmer (william-elmer) said :
#3

I also have a question about where i could change the string. For example, If I was a QA person, and I wanted to review these string shots, I would like them to be in a sub directory of my log files.

So an additonal question I may have would be if I can force an update to my string. I have a log file directory variable so I can just add to that.

ex

w = open('w", my_dir + AdditonalPathing)

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

comment #2:
f(x != reg.print)
stringVar = capture(reg)
else
image.click()

comment #2 and #3:
if you want to save the shots as logging information (aka permanently), then you need to move the images, since capture() stores the image in a temp folder and they are deleted at script termination.

- the principle
import shutil
import os
shotLog = my_dir + AdditonalPathing
shutil.move(capture(reg), os.path.join(shotLog, "you-name-it.png"))

Revision history for this message
William Elmer (william-elmer) said :
#5

Thanks RaiMan, that solved my question.