Sunday, June 29, 2014

AutoIt Script For Saving Screenshot

Nowadays, I have been working on automation of tasks. I have used some tools, like Selenium, QTP / UFT and AutoIt. AutoIt is the most primitive but also the most effective one in my humble opinion. Today, I'd like to share an AutoIt automation code with you.

Assume that you want to take screenshots and name them accordingly by date and time. You can achieve this by following these steps:

  1. Press "PrintScreen" key on keyboard
  2. Start "Paint" application
  3. Paste the screenshot
  4. Save it and name it
No matter how fast you are, it will take you about 10 seconds and if you need to do this repeatedly (for example if you are running a test case), it will be more and more difficult to do it manually.

So, you can automate this task using AutoIt and the script below. After downloading and installing AutoIt IDE, you can try it on your computer.


; PrintScreen 
Send("!{PRINTSCREEN}") 

; OpenPaint 
Run("mspaint") 
WinWaitActive("Untitled - Paint") 

; PasteScreenShot 
Send("^v") 

; SaveWithTodaysDate 
Send("^s") 
WinWaitActive("Save As") 
Send(@ScriptDir & "\" & @YEAR & "." & @MON & "." & @MDAY & "-" & @HOUR & @MIN & ".jpeg") 
Send("{ENTER}") 
Send("y") 

; Close 
WinWaitActive(@YEAR & "." & @MON & "." & @MDAY & "-" & @HOUR & @MIN & ".jpeg - Paint") 
Send("!{F4}")

No comments:

Post a Comment