Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the command to take a picture in Sikuli

Tags:

sikuli

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")
like image 675
Leonardo Sobral Avatar asked May 25 '13 02:05

Leonardo Sobral


People also ask

How to add images to your Sikuli project?

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.

How do I take a screenshot with Sikuli?

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.

What is image recognition in Sikuli?

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.

How do I run a Sikuli script?

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.


2 Answers

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'))
like image 113
Tenzin Avatar answered Oct 28 '22 22:10

Tenzin


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!

like image 25
HAL-9000 Avatar answered Oct 28 '22 21:10

HAL-9000