What's the command to take a picture in Sikuli

限于喜欢 提交于 2020-01-22 11:09:02

问题


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")

回答1:


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.




回答2:


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!




回答3:


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'))


来源:https://stackoverflow.com/questions/16745722/whats-the-command-to-take-a-picture-in-sikuli

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!