What's the command to take a picture in Sikuli

前端 未结 3 1965
悲&欢浪女
悲&欢浪女 2021-02-08 06:38

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



        
相关标签:
3条回答
  • 2021-02-08 07:28

    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!

    0 讨论(0)
  • 2021-02-08 07:32

    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.

    0 讨论(0)
  • 2021-02-08 07:43

    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'))
    
    0 讨论(0)
提交回复
热议问题