Page 1 of 1
How to save a file to report directory
Posted: Wed Feb 19, 2014 1:38 pm
by zero
How can I save a file (e.g. a generated PDF) to the current report directory?
I don't know the current report directory. I saw that there is the class ReportEnvironment which has a property ReportFileDirectory. How can I access this property?
Re: How to save a file to report directory
Posted: Tue Feb 25, 2014 4:51 pm
by Support Team
Hi zero,
In order to write e.g. a text file to the “Report”-folder you can use following code:
System.IO.File.WriteAllText(@"../../Reports/sample.txt","mytext");
Regards,
Robert
Re: How to save a file to report directory
Posted: Wed Feb 26, 2014 5:30 pm
by zero
Thank you Robert, but that was not what I was searching for. Saving a test case specific file to the general (output folder for all test case data) "Reports" folder is not what I want. Instead, the file should be saved in the test case specific report folder, e.g. images_<MyProject>_20140226_161818 or have the same datestamp in its file name as the other files that were generated during the test run.
Example:
1. User hits pay button
2. Download invoice.pdf as ..\Reports\invoice_20140224_195557.pdf
3. Verify PDF (and keep it for reporting)
Re: How to save a file to report directory
Posted: Thu Feb 27, 2014 4:26 pm
by Support Team
Hi zero,
Thank you for your additional information.
I created a small sample solution which copies a PDF-file from a predefined directory to the current working directory of your solution. Additionally the PDF-file is renamed and a time stamp is added.
public void MovePDF()
{
//Assume that you have downloaded your pdf to your local drive.
//Define source and destination
string source = @"C:\Users\XXXXX\test.pdf";
string currentWorkingDirectory = Ranorex.Core.Reporting.TestReport.ReportEnvironment.ReportFileDirectory;
//Add timestamp
string timestamp = System.DateTime.Now.ToString("yyyyMMdd_HHmmss");
string destination = currentWorkingDirectory + @"\" + timestamp + "_test.pdf";
//Move the PDF
System.IO.File.Move(source,destination);
}
Hopefully that solution meet all your requirements
Regards,
Robert
Re: How to save a file to report directory
Posted: Mon Mar 03, 2014 10:00 am
by zero
Hello Robert,
thanks a lot for your effort! But unfortunately this is still not the solution I am searching for
In your example the file is moved to the directory "<MyProject>\bin\Debug", since that is what
Code: Select all
Ranorex.Core.Reporting.TestReport.ReportEnvironment.ReportFileDirectory
delivers.
But I want to save the file to a directory which belongs to this current test run. When I look into the directory "<MyProject>\bin\Debug", there are a lot of folders which belong to specific test runs, e.g. images_<MyProject>_20140303_093429. Is it ok to store test output files (the above mentioned PDF) there? How can I get the name of this folder?
Maybe I am on the wrong path and there are other better ways to achieve this with Ranorex?
Again, thanks a lot for your time!
Roman
Re: How to save a file to report directory
Posted: Tue Mar 04, 2014 2:31 pm
by Support Team
Hello Roman,
I created a new sample which allows you to have a folder for each test run. Please set the “Report File Directory” within the TestSuite properties to:
TestSuiteProperties.png
Replace the “currentWorkingDirectory” with the “reportFileDirectory” within the code
//Define source and destination
string source = @"C:\Users\XXXXX\test.pdf";
string reportFileDirectory = Ranorex.Core.Reporting.TestReport.ReportEnvironment.ReportFileDirectory.ToString();
//Add timestamp
string timestamp = System.DateTime.Now.ToString("yyyyMMdd_HHmmss");
string destination = reportFileDirectory + @"\" + timestamp + "_test.pdf";
//Move the PDF
System.IO.File.Move(source,destination);
Regards,
Robert
Re: How to save a file to report directory
Posted: Tue Mar 04, 2014 7:05 pm
by zero
That's it!
Thanks a lot!!
Regards,
Roman
Re: How to save a file to report directory
Posted: Thu Jun 18, 2015 9:47 pm
by tong
Hi,
Is there anyway to download pdf from an url using javascirpt within Ranorex?
Re: How to save a file to report directory
Posted: Mon Jun 22, 2015 9:50 pm
by Support Team
Hi,
You could use the
ExecuteScript() method as described on in our API documentation.
A small example how to use this method can also be found in the following forum post.
Regards,
Bernhard