How to save a file to report directory

Class library usage, coding and language questions.
zero
Posts: 22
Joined: Thu Jan 16, 2014 3:43 pm

How to save a file to report directory

Post by zero » Wed Feb 19, 2014 1:38 pm

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?

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to save a file to report directory

Post by Support Team » Tue Feb 25, 2014 4:51 pm

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

zero
Posts: 22
Joined: Thu Jan 16, 2014 3:43 pm

Re: How to save a file to report directory

Post by zero » Wed Feb 26, 2014 5:30 pm

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)

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to save a file to report directory

Post by Support Team » Thu Feb 27, 2014 4:26 pm

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

zero
Posts: 22
Joined: Thu Jan 16, 2014 3:43 pm

Re: How to save a file to report directory

Post by zero » Mon Mar 03, 2014 10:00 am

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

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to save a file to report directory

Post by Support Team » Tue Mar 04, 2014 2:31 pm

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
You do not have the required permissions to view the files attached to this post.

zero
Posts: 22
Joined: Thu Jan 16, 2014 3:43 pm

Re: How to save a file to report directory

Post by zero » Tue Mar 04, 2014 7:05 pm

That's it! :D

Thanks a lot!!

Regards,
Roman

tong
Posts: 1
Joined: Thu Jun 18, 2015 9:44 pm

Re: How to save a file to report directory

Post by tong » Thu Jun 18, 2015 9:47 pm

Hi,

Is there anyway to download pdf from an url using javascirpt within Ranorex?

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to save a file to report directory

Post by Support Team » Mon Jun 22, 2015 9:50 pm

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