Xamarin.UITest Screenshot location

Viewed 2698

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.

4 Answers

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.

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

Use MoveTo() insted of CopyTo().

var screenshot = app.Screenshot($"{DateTime.Now}_{platform}");
screenshot.MoveTo($@"{Destination}\{screenshot.Name}.{screenshot.Extension}");

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

Related