testcafe: Screenshot on teamcity agent fails with error

Are you requesting a feature or reporting a bug?

Bug

What is the current behavior?

t.takeScreenshot fails in a background.

Was unable to take a screenshot due to an error.|n|nCommand failed: E:\BuildAgent\work\8a3cefc0dd10ecd5\node_modules\testcafe-browser-tools\bin\win\screenshot.exe 3539314 firefox E:\BuildAgent\work\8a3cefc0dd10ecd5\test\testcafe\reports\screenshots\2017-07-18_04-17-21\test-1\Firefox_45.0.0_Windows_8.1_0.0.0\1.png|n|nUnhandled Exception: System.ComponentModel.Win32Exception: The handle is invalid|r|n   at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)|r|n   at System.Drawing.Graphics.CopyFromScreen(Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize, CopyPixelOperation copyPixelOperation)|r|n   at BrowserTools.Screenshot.CaptureFromScreen(IntPtr hwnd, WindowInfo wi)|r|n   at BrowserTools.Screenshot.CaptureWindow(IntPtr hwnd, String processName)|r|n   at BrowserTools.Screenshot.Main(String|[|] args)|n|n		Was unable to take a screenshot due to an error.|n|nCommand failed: E:\BuildAgent\work\8a3cefc0dd10ecd5\node_modules\testcafe-browser-tools\bin\win\screenshot.exe 7602576 chrome E:\BuildAgent\work\8a3cefc0dd10ecd5\test\testcafe\reports\screenshots\2017-07-18_04-17-21\test-1\Chrome_59.0.3071_Windows_8.1_0.0.0\1.png|n|nUnhandled Exception: System.ComponentModel.Win32Exception: The handle is invalid|r|n   at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)|r|n   at System.Drawing.Graphics.CopyFromScreen(Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize, CopyPixelOperation copyPixelOperation)|r|n   at BrowserTools.Screenshot.CaptureFromScreen(IntPtr hwnd, WindowInfo wi)|r|n   at BrowserTools.Screenshot.CaptureWindow(IntPtr hwnd, String processName)|r|n   at BrowserTools.Screenshot.Main(String|[|] args)|n

What is the expected behavior?

Screenshot is taken successfully

How would you reproduce the current behavior (if this is a bug)?

Run test on TC agent

Provide the test code and the tested page URL (if applicable)

Test code

await t.takeScreenshot()

Specify your

  • operating system: Windows 8.1
  • testcafe version: 0.16
  • node.js version: 6.6.0

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

At present, it is not possible. Track an issue https://github.com/DevExpress/testcafe/issues/1520 to be aware about progress.

Hi @maqpratika

Starting with 0.20.4 version, TestCafe uses a build-in browser functionality for making screenshots (only for Chrome and Firefox). It allows TestCafe to prevent all platform-specific problems with screenshots.

Try this version and tell us about your results.

This issue must be fixed by https://github.com/DevExpress/testcafe/pull/2492. I’ll notify you when a build with the fix will be published on NPM. Feel free to try the fixed build and reopen the issue if the problem isn’t solved in your environment.

@AlexanderMoskovkin Thank you! will have a look and return with feedback