I'm using Sikuli IDE. I'd like to know what the command to take a screenshot is, so I can capture the screen at the end of a test.
Something like this
try :
if bla bla bla:
print("blablabla")
else:
TAKESCREENSHOT() #------------------> What command do I put here?
print("TEST_FAILED")
Step #1) Take the screenshot of the required items on the screen, and put it inside your Sikuli project. [ Note: here, downloads icon is “source.png” and flower image is “destination.png”] Step #2) Put these pictures inside your project.
The Take screenshot button uses the default Sikuli screen capturing tool to take a screenshot and automatically places this image into the script. The second button Insert image allows you to select an image that you have saved in your local computer. This is really beneficial if you have a preference in using one screenshot tool over the other.
Sikuli uses the technique of “Image Recognition” and “Control GUI” to interact with elements of web pages and windows popups. In Sikuli, all the web elements are taken as images and stored inside the project.
This button is how you run the script once you have written it. Once you click “Run”, Sikuli takes over your computer and will run the code line by line. If you accidentally run your script and want to the stop the execution of the code, there is a hotkey to stop the script run and bring the Sikuli GUI back up: ALT-SHIFT-C.
To make a screenshot of the window that has focus you simple can use:
focusWindow = App.focusedWindow()
regionImage = capture(focusWindow)
shutil.move(regionImage, os.path.join(r'C:\Screenshots', 'Dummy1.png'))
Cheap Sikuli trick for screencaps is to have a defined region, then capture the region.
So if you've got a Chrome browser you want to cap, just set it up something like this:
App.focus('Chrome.app')
ChromeWindow = App('Chrome.app').window()
That will both focus the computer to the target application, and define a region composed of the window parameters of the application. Then run this:
capture(ChromeWindow)
Then use shutil (import shutil
) to move the file around to wherever you need it in your local directories. I usually put that code pile into a function I can call when needed TakePicture(Name)
where Name
is what I want to call the screencap when called in a particular test. Sikuli is both powerful and easy!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With