Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Win32Exception thrown while attempting to take screenshot from remote machine #225

Closed
mkulava opened this issue Nov 19, 2015 · 6 comments
Closed

Comments

@mkulava
Copy link

mkulava commented Nov 19, 2015

Hi,

I can't provide clear steps to reproduce this issue, but it happens occasionally on the remote machine (never met it while running tests locally). Here is the stacktrace:

Unhandled Exception: System.ComponentModel.Win32Exception: The handle is invalid at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation) at canopy.core.takeScreenShotIfAlertUp() in C:\projects\canopy\src\canopy\canopy.fs:line 46 at canopy.core.takeScreenshot(String directory, String filename) in C:\projects\canopy\src\canopy\canopy.fs:line 60 at canopy.core.screenshot(String directory, String filename) in C:\projects\canopy\src\canopy\canopy.fs:line 68 at canopy.runner.fail(Exception ex, String id) in C:\projects\canopy\src\canopy\runner.fs:line 86 at canopy.runner.runtest$cont@110(suite suite, Test test, Unit unitVar) in C:\projects\canopy\src\canopy\runner.fs:line 123 at canopy.runner.runtest@105(suite suite, Test test) in C:\projects\canopy\src\canopy\runner.fs:line 110 at [email protected](Test w) in C:\projects\canopy\src\canopy\runner.fs:line 158 at Microsoft.FSharp.Primitives.Basics.List.iter[T](FSharpFunc2 f, FSharpList1 x) at canopy.runner.run$cont@148(suite s, Unit unitVar) in C:\projects\canopy\src\canopy\runner.fs:line 158 at [email protected](suite s) in C:\projects\canopy\src\canopy\runner.fs:line 148 at Microsoft.FSharp.Primitives.Basics.List.iter[T](FSharpFunc2 f, FSharpList1 x) at canopy.runner.run() in C:\projects\canopy\src\canopy\runner.fs:line 145 at Main.main(String[] argv) in d:\jenkins_sits\workspace\Mikz_UITests_Dev\Mikz.AutoTests.Publisher.UI\Program.fs:line 41

Seems like it happens only when the alert appears on the page? Any ideas how to handle this exception properly?

P.S. I have also found similar problem on stackoverflow. But I do not know how other screenshots are taken without problemn on the same remote machine.

@lefthandedgoat
Copy link
Owner

Yah that code is in a function called takeScreenShotIfAlertUp and is an attempt to still take a screen shot even when an alert is up.

Alerts really mess up UI Automation because they are not a part of the DOM. They are not even an item in your current tab. They are a part of the browser at the same level/importance as a tab. They are basically outside of the scope of the actual website. When a alert is open, Selenium will not a take a screenshot. That function is an attempt to take a screenshot with Windows calls.

I can try to reproduce the problem locally and improve the function. Long term, for your own sanity, its probably a good idea work towards removing and avoiding alerts, and using another mechanism for displaying things to your users.

@lefthandedgoat
Copy link
Owner

I've thought about this and the best thing I can do is to either

A) not attempt a screenshot if its a remote server
B) Catch any exception and return an empty byte array... which may be the better solution since it will prevent this problem from happening again.

Either one acceptable to you?

@mkulava
Copy link
Author

mkulava commented Nov 25, 2015

I think "B" is better solution, at least for me. Thank you.

@mkulava
Copy link
Author

mkulava commented Dec 2, 2015

hello Chris, have you released the fix? thanks in advance

lefthandedgoat added a commit that referenced this issue Dec 2, 2015
@lefthandedgoat
Copy link
Owner

Sorry for the delay!

https://www.nuget.org/packages/canopy/0.9.43

@mkulava
Copy link
Author

mkulava commented Dec 28, 2015

Thank you, solved my problems.

@mkulava mkulava closed this as completed Dec 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants