Append image to RTF file from Clipboard (PRINTSCREEN)

Asked by Nikola

Hi,

One question:
How to append image to RTF file from Clipboard (PRINTSCREEN)

I need this because in one part of my testing script I need to capture reproduced error and save it as a picture.
Just to see what happend..
how to do that?

standard code that I'm using is not working...

def errorSPR(msgL):
    type(Key.PRINTSCREEN)
    f = open("C:\\Users\\Nikola\\Desktop\\ERRORS.rtf","a")
    f.write(msgL+"\n")
    f.write(paste(Env.getClipboard()))
    f.close()

i also tried:
msg=Env.getClipboard().paste()
f.write(msg)

and some other stuff..

but obviously I'm missing something for picture manipulation :)

Thanks for response :)

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Eugene S
Solved:
Last query:
Last reply:
Revision history for this message
Best Eugene S (shragovich) said :
#1

Hi,

That's one possible implementation:

def takeScreenShot(imageName):
 img = capture(SCREEN)
 shutil.move(img, 'C:\\<Path>\\%(appName)s.png' %{"appName": imageName})

The first command captures the whole screen and saves the an image file (.png) in temp folder. This image will be deleted once the script done running.
The second command will copy that temporary image to the desired location.

In addition, you can add timestamps or any other useful information to the file name if desired.

Cheers,
Eugene

Revision history for this message
Nikola (nikola-kudeljas) said :
#2

Hi,

Thanks for help.
your code is not working for me (some shutil errors and problems with path reading or something)

But I created working solution for me thanks to you :)

---------------------------------------------
def takeScreenShot(name):
    img = capture(SCREEN)
    shutil.move(img, "C:\\<PATH>\\"+name+"Error.png")
-------------------------------------------

And this works good enough for me.

Enjoy

Revision history for this message
Nikola (nikola-kudeljas) said :
#3

Thanks Eugene S, that solved my question.