12

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")
Nathaniel Waisbrot
  • 23,261
  • 7
  • 71
  • 99
Leonardo Sobral
  • 121
  • 1
  • 1
  • 3

3 Answers3

15

The function is capture, as in

screen = Screen()
file = screen.capture(screen.getBounds())
print("Saved screen as "+file)

It takes a screen-shot, saves it in a file, and gives you the path to that file back.

See the Sikuli documentation on it for full details.

Nathaniel Waisbrot
  • 23,261
  • 7
  • 71
  • 99
  • 3
    This will launch the manual screen capture screen. If a automated screenshot is needed, you have to provide the coordinates: screen.capture(screen.x, screen.y, screen.w, screen.h) – JayTheKay May 25 '13 at 15:24
  • @kel thanks for the catch. Fixed it to be non-interactive whole-screen capture. – Nathaniel Waisbrot May 26 '13 at 03:01
4

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!

chicks
  • 2,393
  • 3
  • 24
  • 40
HAL-9000
  • 61
  • 2
2

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'))
Tenzin
  • 2,415
  • 2
  • 23
  • 36