Xamarin.UITest Screenshot location - screenshot

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.

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}");

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");
}
}

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

Related

Extent Report: Name of output file does not change even when defined

Im not able to change the name of the outputfile from the extent reports. It does always create the report file called index.html.
In my code, i want to display the name + date/time.html
Here is the codeline for the path definition:
private const string ExtentReportPath = #".\ExtentReports\";
[OneTimeSetUp]
public void ExtentStart()
{
ExtentHtmlReporter htmlreporter = new ExtentHtmlReporter(ExtentReportPath + "UnlockInstruction_Test" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss") + ".html");
extent = new ExtentReports();
extent.AttachReporter(htmlreporter);
}
[OneTimeTearDown]
public void ExtentClose()
{
extent.Flush();
}
First solution ive found is:
I changed ExtentHtmlReporter to ExtentV3HtmlReporter.
But after using ExtentV3HtmlReporter, VS is displaying a warning which says, that this method is obsolete and wont be supported in the future.. so still waiting for a up to date solution.
From what I read the static name (index) is expected behavior to increase the efficiency of reporting.
You can add a unique name to the folder name instead of the file, so you would create sub-folders for each index file like this:
String path =System.getProperty("user.dir")+"//reports//"+time+"//index.html";
ExtentSparkReporter reporter = new ExtentSparkReporter(path);

Xamarin.Forms Open local PDF

I tried to open a locally stored pdf with xamarin.
example code:
var files = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
var filepath = "file://" + files[0];
if (File.Exists(filepath))
{
await Launcher.OpenAsync(filepath);
}
But the file does not open. The only message I get is (android device):
what do I miss?
EDIT
the variable filepath contains:
file:///data/user/0/com.companyname.scgapp_pdfhandler/files/.config/test.pdf
also tried
file://data/user/0/com.companyname.scgapp_pdfhandler/files/.config/test.pdf
does not help
Figured I would add my comment as an answer for easier visibility in case others run into it in the future.
Pass a OpenFileRequest object instead, if you use a string it has to be the correct uri scheme for it. I suspect the uri scheme you are passing to it isn't something that is understood by the system

A question regarding pptx files in react-native app

I have an application where I need to show the .pptx and .pdf files. For pdf files I am using react-native-pdf and file is opening fine in my App but when it comes to .pptx files we have 2 libraries:
1. https://www.npmjs.com/package/react-native-doc-viewer
2. https://www.npmjs.com/package/react-native-file-viewer
react-native-doc-viewer is not being actively maintained and a lot of issues :(
But both of them were giving a prompt to select an app like Wps Office or Microsoft apps but they were not opening as Pdf files opened in my app. Whats the reason behind this? We cannot open pptx file in our app?
I read the react-native-doc-viewer android native code. it is actually is to download a doc not to view it. the following is the code:
#ReactMethod
public void openDoc(ReadableArray args, Callback callback) {
final ReadableMap arg_object = args.getMap(0);
try {
if (arg_object.getString("url") != null && arg_object.getString("fileName") != null) {
// parameter parsing
final String url = arg_object.getString("url");
final String fileName =arg_object.getString("fileName");
final String fileType =arg_object.getString("fileType");
final Boolean cache =arg_object.getBoolean("cache");
final byte[] bytesData = new byte[0];
// Begin the Download Task
new FileDownloaderAsyncTask(callback, url, cache, fileName, fileType, bytesData).execute();
}else{
callback.invoke(false);
}
} catch (Exception e) {
callback.invoke(e.getMessage());
}
}
it uses FileDownloaderAsyncTask to download files. if you are familiar with it.
if you want to show excels, Docx, you can use the google doc line convert it to Html, then in the webView to show it. the format like it: https://docs.google.com/gview?embedded=true&url=[doc address], the same effect as ios.

Selenium Webdriver-- getting error while Taking screenshot

public void testTakeScreenshot()
{
try{
File fscreenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
System.out.println(fscreenshot.getPath());
File fdest = new File("E:/");
FileUtils.copyFile(fscreenshot,fdest);
System.out.println(fdest.getPath());
}catch(Exception e)
{
e.printStackTrace();
}
}
Generated Output at console :
C:\Users\Bunty\AppData\Local\Temp\screenshot1773089913844817102.png
java.io.IOException: Destination 'E:\' exists but is a directory
The test is running Ok but the file is created as shown in the console. while copying the link . I couldnt find any file for the same. Also the copy function is not working ; hence no file is present in E drive.
As the errormessage suggests, you shouldn't give the path to the directory ('E:\'), but the path to the file. Try:
File fdest = new File("E:/screenshot.png");

Renaming a file in as3 AIR - how to do it if you have file's native path in a var?

The following code is great for renaming a file if you know the file is in applicationStorageDirectory
var sourceFile:File = File.applicationStorageDirectory;
sourceFile = sourceFile.resolvePath("Kalimba.snd");
var destination:File = File.applicationStorageDirectory;
destination = destination.resolvePath("test.snd");
try
{
sourceFile.moveTo(destination, true);
}
catch (error:Error)
{
trace("Error:" + error.message);
}
How do you set the sourceFile if all you have is the file's native path in a string? Like this:
D:\Software\files\testList.db
This throws errors:
sourceFile = sourceFile.resolvePath("D:\Software\files\testList.db");
The idea is I want to rename a file I had previously loaded into a var. I figured I'd extract the native path to a String var, null the File var (so the OS doesn't tell me it can't be renamed while the file is opened in flash), resolve that nativePath as the sourceFile, and use moveTo to rename the file on the hard drive.
Cheers for taking a look.
EDIT:
I've set up a test AIR app with only the following in it:
import flash.events.*;
import flash.filesystem.*;
var original = File.documentsDirectory;
original = original.resolvePath("D:\\Software\\test\\October.db");
var destination:File = File.documentsDirectory;
destination = destination.resolvePath("copy.db");
original.addEventListener(Event.COMPLETE, fileMoveCompleteHandler);
original.addEventListener(IOErrorEvent.IO_ERROR, fileMoveIOErrorEventHandler);
original.moveToAsync(destination);
function fileMoveCompleteHandler(event:Event):void {
trace(event.target); // [object File]
}
function fileMoveIOErrorEventHandler(event:IOErrorEvent):void {
trace("I/O Error.");
}
This fails, as does using D:\Software\test\October.db
I guess what I want to know it - how do you do the resolvePath thing if you already know the full path?
I guess what I want to know it - how do you do the resolvePath thing if you already know the full path?
You don't AFAIK. If your path is actually d:\software\test\october.db you can set a File ref like:
var original:File = new File();
original.nativePath = "d:\software\test\october.db";