我正在Windows 7上使用Andorid模拟器和Android设备运行Xamarin.UITest测试。在两种情况下,我都无法截图。
我正在初始化这样的事情:
ConfigureApp
.Android
.ApkFile(apkPath)
.EnableLocalScreenshots()
.StartApp();
并截取这样的屏幕截图:
App.Screenshot("App Started");
但是,在调用App.Screenshot
时出现此异常:
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)
查看生成的日志文件,我看到:
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)
我尝试过的事情:
Directory.SetCurrentDirectory()
设置其他目录-这似乎被忽略了,因为无论(C:\Users\USERNAME\.nuget\packages\xamarin.uitest\...
),我在Exception中都看到相同的路径Everyone
组授予对路径C:\Users\USERNAME\.nuget\packages\xamarin.uitest\3.0.3\lib\net45\
的访问权限-无效3.0.4-dev1
-相同的结果答案 0 :(得分:0)
本周我遇到了同样的问题,这与安全性提高有关,以避免在应用程序上截屏。 如果您这样做(https://forums.xamarin.com/discussion/96818/disable-the-screenshot-functionality-in-xamarin-forms-application)可能就是问题所在。只需#if!DEBUG,您就可以修复它。
希望能帮助别人。