How to create sceenshot by using "Save-UIAScreenshot" or "Get-UIAScreenshot"?

Sep 18, 2012 at 1:52 PM
Edited Sep 18, 2012 at 1:58 PM

Seems I always get exception by using these two command. I need to save the screen shot to a file.

BTW, the error message is too general to specify the real reason.

Coordinator
Sep 18, 2012 at 2:52 PM

Hi,

I was sure that I fixed it earlier, but the bug is now here. :(

The problem is that both cmdlets can't decide which parameter set should be used (there is in the module a lot of inheritance, and several parameter sets are seen by a cmdlet).

Quick fix: use the Description parameter:

Start-Process calc -PassThru | Get-UIAWindow | Save-UIAScreenshot -Description asdf

This generates the following file: %TEMP%\[year][month][day]...._asdf.bmp

Now (will be published this week), I fixed it surely and the sample below is working and after having run it, I have a screenshot of the window as well as screenshots of every button:

Start-Process charmap -PassThru | Get-UIAWindow | Save-UIAScreenshot
Start-Process charmap -PassThru | Get-UIAWindow | Get-UIAButton | Save-UIAScreenshot

There is another bug: earlier, being run without pipeline input, the cmdlet returned the picture of the desktop. I'll fix it too.

 

 

Sep 19, 2012 at 1:35 PM

Thanks for your quick reply. 

Start-Process calc -PassThru | Get-UIAWindow | Save-UIAScreenshot -Path C:\temp\2.bmp

If I want to specify the path for the screenshot, it only works when the file is already there. Please also check it.

Thanks in advance!

Coordinator
Sep 19, 2012 at 2:37 PM

Thanks for pointing my attention to the -Path parameter: I fixed it earlier, but I didn't check the fix (as I see in code). It creates a file by a custom path if 1) the path is not empty 2) file already exists :) Just a type, the code should be checking that the file does not exist before writing to a file (file operations are not included in the suite autotests and bug has been passed to the release page).

There is a fun workaround:

"test" > c:\1\test1.bmp
Start-Process calc -PassThru | Get-UIAWindow | Save-UIAScreenshot -Description 1 -Path C:\1\test1.bmp

I must admit that description is ignored if you use custom path.

Well, I'll fix it in the following way:

1) the -Path parameter and 2) the -File/Name parameter instead of the single -Path parameter as it's done now

3) the -Description parameter versus -Path + -File/Name parameter (i.e., in two separate parameter sets).

 

Coordinator
Sep 21, 2012 at 5:34 PM

Finally, all the code below is working:

# saves the desktop
Save-UIAScreenshot

# saves the desktop to a specified file
Save-UIAScreenshot -Path c:\1 -Name 20120921_1.bmp

# saves a window
Start-Process calc -PassThru | Get-UIAWindow | Save-UIAScreenshot

# saves a window to the specified file
Start-Process calc -PassThru | Get-UIAWindow | Save-UIAScreenshot -Path c:\1 -Name 20120921_2.bmp

# throws an exception 'Save-UIAScreenshot : File 'c:\1\20120921_2.bmp' already exists'
Start-Process calc -PassThru | Get-UIAWindow | Get-UIAButton -n 1 | Save-UIAScreenshot -Path c:\1 -Name 20120921_2.bmp

# saves a button to the specified file
Start-Process calc -PassThru | Get-UIAWindow | Get-UIAButton -n 1 | Save-UIAScreenshot -Path c:\1 -Name 20120921_3.bmp

# generates a screenshot for each numeric button (ten screenshots)
Start-Process calc -PassThru | Get-UIAWindow | Get-UIAButton -SearchCriteria @{automationid='13*'} | Save-UIAScreenshot