I'm running Xamarin.UITest tests on Windows 7, using an Andorid emulator and Android device. In both cases I'm unable to take screenshots.
I'm initialising things like this:
ConfigureApp
.Android
.ApkFile(apkPath)
.EnableLocalScreenshots()
.StartApp();
And taking a screenshot like this:
App.Screenshot("App Started");
However, when calling App.Screenshot I get this exception:
System.Exception : Error while performing Screenshot("App Started")
----> System.Exception : Failed to create C:\Users\USERNAME\.nuget\packages\xamarin.uitest\3.0.3\lib\net45\screenshot-1.png. You may need to set the working directory, which can be done using System.IO.Directory.SetCurrentDirectory().
at Xamarin.UITest.Utils.ErrorReporting.With[T](Func`1 func, Object[] args, String memberName)
at Xamarin.UITest.Android.AndroidApp.Screenshot(String title)
at ACME.App.UITest.BaseUITest.BeforeEachTest() in C:\ACME\ACME.Application.UITest\BaseUITest.cs:line 29
at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.GetResult() in D:\a\1\s\src\NUnitFramework\framework\Internal\TaskAwaitAdapter.cs:line 99
at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func`1 invoke) in D:\a\1\s\src\NUnitFramework\framework\Internal\AsyncToSyncAdapter.cs:line 60
at NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunSetUpOrTearDownMethod(TestExecutionContext context, MethodInfo method) in D:\a\1\s\src\NUnitFramework\framework\Internal\Commands\SetUpTearDownItem.cs:line 111
at NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunSetUp(TestExecutionContext context) in D:\a\1\s\src\NUnitFramework\framework\Internal\Commands\SetUpTearDownItem.cs:line 68
at NUnit.Framework.Internal.Commands.SetUpTearDownCommand.<>c__DisplayClass0_0.<.ctor>b__0(TestExecutionContext context) in D:\a\1\s\src\NUnitFramework\framework\Internal\Commands\SetUpTearDownCommand.cs:line 48
at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.<>c__DisplayClass1_0.<Execute>b__0() in D:\a\1\s\src\NUnitFramework\framework\Internal\Commands\BeforeAndAfterTestCommand.cs:line 58
at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action) in D:\a\1\s\src\NUnitFramework\framework\Internal\Commands\BeforeAndAfterTestCommand.cs:line 73
--Exception
at Xamarin.UITest.Android.JavaScreenshotTaker.Screenshot(String title)
at Xamarin.UITest.Android.AndroidApp.<>c__DisplayClass84_0.<Screenshot>b__0()
at Xamarin.UITest.Utils.ErrorReporting.With[T](Func`1 func, Object[] args, String memberName)
Looking at the log file that's generated, I see:
Could not take screenshot
java.io.IOException: EOF
at com.android.ddmlib.AdbHelper.read(AdbHelper.java:874)
at com.android.ddmlib.AdbHelper.getFrameBuffer(AdbHelper.java:333)
at com.android.ddmlib.CalabashAdbHelper.getFrameBuffer(Unknown Source)
at com.android.ddmlib.CalabashDevice.getScreenshot(Unknown Source)
at sh.calaba.screenshot.ScreenshotTaker.takeScreenshot(Unknown Source)
at sh.calaba.screenshot.ScreenshotTaker.main(Unknown Source)
What I've tried:
- Setting a different directory using
Directory.SetCurrentDirectory()- this seems to be ignored, as I see the same path in the Exception regardless (C:\Users\USERNAME\.nuget\packages\xamarin.uitest\...) - Giving the
Everyonegroup access to the pathC:\Users\USERNAME\.nuget\packages\xamarin.uitest\3.0.3\lib\net45\- no effect - Ensuring that tests can write files to the path above - they can, so it shouldn't be a permissions issue
- Updating to the latest dev build of Xamarin.UITest,
3.0.4-dev1- same result
I have had the same problem this week, and it was related to a security improvement to avoid taking screenshots on the app. If you did this (https://forums.xamarin.com/discussion/96818/disable-the-screenshot-functionality-in-xamarin-forms-application) probably that is the problem. With just a #if !DEBUG you could fix it.
Hope to help someone.