5

I've got a problem with Xamarin.UITest, specifically screenshot feature. It is not working as expected.

I'm trying to copy "created" screenshot to another directory, but I get the following error:

Message: System.IO.FileNotFoundException : Could not find file 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\screenshot-1.png'.

I'm using this piece of code to copy image file:

var screen = app.Screenshot("Welcome screen.");
screen.CopyTo(@"C:\Users\someuser\Desktop\screenshotTest.png");

How to specify first path/location for screenshots, because the original path probably needs admin privileges, that I don't have.

Marko Jovanović
  • 2,647
  • 3
  • 27
  • 36

5 Answers5

6

Screenshots saved with App.Screenshot() are located in your test project's directory: MyTestProject"\bin\Debug folder where the first screenshot is named screenshot-1.

Ali
  • 2,702
  • 3
  • 32
  • 54
Blake
  • 61
  • 1
  • 4
3

Half solution to the problem: I downgraded NUnit from 3.11.0 to 2.7.0, so it works OK.

Marko Jovanović
  • 2,647
  • 3
  • 27
  • 36
  • 1
    NUnit 3 versions are not supported to use with Xamarin.UITest. The official documentation recomends to use NUnit 2.6.4 so basically you solved all about running your tests with Xamarin.UITest (including Screenshots) – David López May 19 '19 at 16:39
  • 5
    NUnit 3 is now supported, woo hoo! – Damian Jul 15 '19 at 00:53
0

Use MoveTo() insted of CopyTo().

var screenshot = app.Screenshot($"{DateTime.Now}_{platform}");
screenshot.MoveTo($@"{Destination}\{screenshot.Name}.{screenshot.Extension}");
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 22 '22 at 19:20
0

My screenshots are saving to C:\Users\username\AppData\Local\Temp

Try this code

[TearDown]
public void Teardown()
{
   SaveScreenshotIfTestFails();
}

private void SaveScreenshotIfTestFails()
{
   if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
   {
      var testName = TestContext.CurrentContext.Test.Name;
      var filename = $"{testName}.png";
      var file = app.Screenshot(testName);
      var dir = file.DirectoryName;
      File.Delete(dir + "\\" + filename);
      file.MoveTo($"{testName}.png");
   }
}
gords
  • 51
  • 7
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 17 '23 at 00:58
-1

Screenshots are saved to the Current Directory. Change it via Directory.SetCurrentDirectory.

Roy John
  • 29
  • 5