Bug
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
Screenshot is taken successfully
Run test on TC agent
Test code
await t.takeScreenshot()
Hello @satispunk! If you are starting the TeamCity agent as a service, can you please try to start it from CLI: https://confluence.jetbrains.com/display/TCD9/Setting+up+and+Running+Additional+Build+Agents#SettingupandRunningAdditionalBuildAgents-StartingtheBuildAgent?
The issue should be fixed with the #1691. The fix is published in the latest dev version:
npm install [email protected] or npm install testcafe@dev.
Feel free to reopen the issue if the problem still occurs.
@AlexanderMoskovkin Thank you! will have a look and return with feedback
@AlexanderMoskovkin
Hi. I've test 17.2 version. The problems still exists.
But also found another way to reproduce it.
I get the same error:
Was unable to take a screenshot due to an error.
Command failed:
C:devconfirmit.hub.clientnode_modulestestcafe-browser-toolsbinwinscreenshot.exe
263454 chrome
C:devconfirmit.hub.clienttesttestcafereportsscreenshots2017-09-10_05-40-44test-1Chrome_60.0.3112_Windows_8.1_0.0.01.png
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 System.Drawing.Graphics.CopyFromScreen(Point upperLeftSource, Point
upperLeftDestination, Size blockRegionSize, CopyPixelOperation
copyPixelOperation)
at BrowserTools.Screenshot.CaptureFromScreen(IntPtr hwnd, WindowInfo wi)
at BrowserTools.Screenshot.CaptureWindow(IntPtr hwnd, String
processName)
at BrowserTools.Screenshot.Main(String[] args)
So I assume that if the desktop is not shown physically then testcafe can't get window handle to make screenshot
@satispunk Thanks for the info, we'll investigate it /cc @AndreyBelym
I also have the same issue. I'm running TestCaf茅 in OctopusDeploy as custom script using command
testcafe chrome .\tests.ts --screenshots C:\screenshots --screenshots-on-fails
OctopusDeploy runs in Windows Server 2012 under LocalSystem account. Node.js version is 8.9.4 and TestCaf茅 version is 0.18.6. Chrome version is 64.0.
The error message is:
Was unable to take a screenshot due to an error.
Command failed: C:\Program Files\nodejs\node_modules\testcafe\node_modules\testcafe-browser-tools\bin\win\screenshot.exe 4194442 chrome C:\screenshots\2018-03-06_11-13-20\test-2\Chrome_63.0.3239_Windows_8.0.0\errors\1.png
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 System.Drawing.Graphics.CopyFromScreen(Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
at BrowserTools.Screenshot.CaptureFromScreen(IntPtr hwnd, WindowInfo wi)
at BrowserTools.Screenshot.CaptureWindow(IntPtr hwnd, String processName)
at BrowserTools.Screenshot.Main(String[] args)
Hi there, same for me with TFS.
Windows 10, testcafe 0.19.2, Firefox 59, node 10.0, npm: 5.6.0
My command to run testcafe:
testcafe chrome,opera,firefox -c 2 src/tests -r spec,nunit:results/nunit-results.xml -S -s logs/screenshots
Warnings (1):
--
Was unable to take a screenshot due to an error.
Error: Command failed:
C:\agent\_work\1\s\node_modules\testcafe-browser-tools\bin\win\screenshot.exe
853870 firefox
C:\agent\_work\1\s\logs\screenshots\2018-05-07_01-58-18\test-65\Firefox_59.0.0_Windows_10.0.0\errors\1.png
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 System.Drawing.Graphics.CopyFromScreen(Point upperLeftSource, Point
upperLeftDestination, Size blockRegionSize, CopyPixelOperation
copyPixelOperation)
at BrowserTools.Screenshot.CaptureFromScreen(IntPtr hwnd, WindowInfo wi)
at BrowserTools.Screenshot.CaptureWindow(IntPtr hwnd, String
processName)
at BrowserTools.Screenshot.Main(String[] args)
at ChildProcess.exithandler (child_process.js:282:12)
at ChildProcess.emit (events.js:182:13)
at ChildProcess.EventEmitter.emit (domain.js:442:20)
at maybeClose (internal/child_process.js:947:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:236:5)
#[error]Process completed with exit code 2.
Hi @satispunk, @panupetteri, @viraxslot, from what I have now it looks like it's a technical limitation in Windows. Maybe there is group policy or something to keep desktop GUI operational for remote connections. Currently you could try to use browsers in headless mode.
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.
Can you please share the resolution details? What made it fix?
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.
@miherlosev
Hi, thanks a lot. Now I have no errors on making screenshots in TFS + testcafe 0.20.4
Is there any options to shoot window with scroll?
Hi, thanks a lot. Now I have no errors on making screenshots in TFS + testcafe 0.20.4
Excellent.
Is there any options to shoot window with scroll?
Please describe in more detail what options do you need?
@miherlosev
Please describe in more detail what options do you need?
On screenshot now I see only active part of browser window, but want to see all window (scrolled from the beginning to the end). Is it possible?
At present, it is not possible.
Track an issue https://github.com/DevExpress/testcafe/issues/1520 to be aware about progress.
This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.