So i'm running a ui test with power shell.
When i get an error i want to take a screen shot of just the ie window this can be done with alt print scrn
%{prtsc}
but it only takes a jpg of the active window.
I tryied this
$h = (Get-Process iexplore).MainWindowHandle
SetForegroundWindow((Get-Process -name iexplore).MainWindowHandle)
sleep -sec 2
$h = (Get-Process -id $pid).MainWindowHandle
Also any help with a way to identify ie error would be great thanks.
function screenshot
{
param(
[Switch]$OfWindow
)
begin {
Add-Type -AssemblyName System.Drawing
$jpegCodec = [Drawing.Imaging.ImageCodecInfo]::GetImageEncoders() |
Where-Object { $_.FormatDescription -eq "JPEG" }
}
process {
Start-Sleep -Milliseconds 250
if ($OfWindow) {
[Windows.Forms.Sendkeys]::SendWait("%{PrtSc}")
} else {
[Windows.Forms.Sendkeys]::SendWait("{PrtSc}")
}
Start-Sleep -Milliseconds 250
$bitmap = [Windows.Forms.Clipboard]::GetImage()
$ep = New-Object Drawing.Imaging.EncoderParameters
$ep.Param[0] = New-Object Drawing.Imaging.EncoderParameter ([System.Drawing.Imaging.Encoder]::Quality, [long]100)
$screenCapturePathBase = "$pwd\ScreenCapture"
$c = 0
while (Test-Path "${screenCapturePathBase}${c}.jpg") {
$c++}
$bitmap.Save("${screenCapturePathBase}${c}.jpg", $jpegCodec, $ep)
}
}