What App Center service does this affect?
Xamarin.UITest 3.0
Describe the bug
I'm trying to call app.Screenshot("name") method in test, but gets an error during test run:
_Exception: System.Exception: Failed to create C:\Windows\system32\screenshot-1.png. You may need to set the working directory, which can be done using System.IO.Directory.SetCurrentDirectory()._
To Reproduce
Steps to reproduce the behavior:
ConfigureApp.EnableLocalScreenshots(). Write test and call method app.Screenshot("name").Expected behavior
Test passed. Screenshot made.
Screenshots
https://monosnap.com/file/lkHIqS8cJfaoRGjhykmfG2NGldoGuN
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
I've also tried to call System.IO.Directory.SetCurrentDirectory(@"my\best\path");. But I've also got that error with new path:
_Exception: System.Exception: Failed to create my\best\path\screenshot-1.png. You may need to set the working directory, which can be done using System.IO.Directory.SetCurrentDirectory()._
@DimaOrdenov The team is looking into potential fixes for your bug. Thank you for reporting it.
@Oddj0b Hello, any updates on this?
There is now a pre-release version of UITest which changes the behaviour of screenshot creation: https://www.nuget.org/packages/Xamarin.UITest/3.0.1-dev1
Screenshots are saved to the current directory by default but falls back to the directory that Xamarin.UITest.dll is in, which is typically your bin/Debug or bin/Release directory.
Please try it and let us know if it fixes the problem for you.
There is now a pre-release version of UITest which changes the behaviour of screenshot creation: https://www.nuget.org/packages/Xamarin.UITest/3.0.1-dev1
Screenshots are saved to the current directory by default but falls back to the directory that
Xamarin.UITest.dllis in, which is typically yourbin/Debugorbin/Releasedirectory.Please try it and let us know if it fixes the problem for you.
So, I've tried two times with different configurations:
System.IO.Directory.SetCurrentDirectory(@"C:\Users\dmitry.ordenov");Could you add code immediately before you call Screenshot() which creates files in bin/Debug and C:\Users\dimitry.ordenov please?
If your test is unable to create these files then you'll need to use another directory which your tests can write to or to run them in a way that they do have permissions.
@jonstoneman
Here is how I initialize app:
public class AppInitializer
{
public static IApp StartApp(Platform platform)
{
if (platform == Platform.Android)
{
System.IO.Directory.SetCurrentDirectory(@"C:\Users\dmitry.ordenov");
return ConfigureApp
.Android
.InstalledApp("<MY_PACKAGE_NAME>")
.Debug()
.EnableLocalScreenshots()
.StartApp();
}
return ConfigureApp.iOS.StartApp();
}
}
Here is my set-up and test-method:
[SetUp]
public void BeforeEachTest()
{
_app = AppInitializer.StartApp(_platform);
}
[Test]
public void TestTakeScreenshot()
{
_app.Screenshot("Test_Screenshot");
}
We just need to confirm that the test really does have permission to create files in either bin/Debug and in C:\Users\dimitry.ordenov. Could you add some code to TestTakeScreenshot() (before the call to _app.Screenshot()) which creates new files in those locations please? Just a file named dummy.txt containing "Success" would do.
@jonstoneman Got you
This one creates test_file.txt in C:\Users\dimitry.ordenov if I am setting System.IO.Directory.SetCurrentDirectory(@"C:\Users\dmitry.ordenov") :
private string _filePathToWrite => @"C:\Users\dmitry.ordenov\TestTextFile.txt";
[Test]
public void TestTakeScreenshot()
{
File.WriteAllBytes(
Path.Combine(System.IO.Directory.GetCurrentDirectory(), "test_file.txt"),
File.ReadAllBytes(_filePathToWrite));
_app.Screenshot("Test_Screenshot");
}
And another one (w/o setting current directory) creates test_file.txt in Debug folder:
private string _projectPath = @"C:\Users\dmitry.ordenov\<MY_PATH_TO_UI_TEST_PROJECT>";
private string _filePathToWrite => @"C:\Users\dmitry.ordenov\TestTextFile.txt";
[Test]
public void TestTakeScreenshot()
{
File.WriteAllBytes(
Path.Combine(_projectPath, @"bin\Debug\test_file.txt"),
File.ReadAllBytes(_filePathToWrite));
_app.Screenshot("Test_Screenshot");
}
Those look good - what happens when you run them? Does it successfully create the files and then still throw and Exception at _app.Screenshot("Test_Screenshot")?
@jonstoneman
Yep, *.txt files creates successfully, which cannot be said about screenshots.
How very odd. Would you be able to share your app and test code with me so I can see if I experience the same problem? You can send files to us securely by crating a new conversation with support in https://appcenter.ms (button is bottom right of the screen).
@jonstoneman
If we are talking about this button https://monosnap.com/file/jg8boLI1ARWnGkAG8CfYe5SbeOr2M6 , I've created new conversation there and linked this issue and your profile.
Closing here, to keep all the communication through the support chat.
Did you managed to find a solution for this problem ? I am facing the same...
@codrinamerigo
Nope. I was trying on Windows 7, possibly this is the problem.
@codrinamerigo
Nope. I was trying on Windows 7, possibly this is the problem.
I am trying on Windows 10 and for the Android ui tests, is not working...
Having the same issue on Xamarin.UITest 3.0.3, on Windows 7 if it makes any difference.
I found a little more detail in the test log:
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)
...
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)