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?
How to save a file to report directory
- Support Team
- 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
Hi zero,
In order to write e.g. a text file to the “Report”-folder you can use following code:
Robert
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
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)
Example:
1. User hits pay button
2. Download invoice.pdf as ..\Reports\invoice_20140224_195557.pdf
3. Verify PDF (and keep it for reporting)
- Support Team
- 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
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.
Regards,
Robert
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
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 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
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
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
- Support Team
- 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
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:
Replace the “currentWorkingDirectory” with the “reportFileDirectory” within the code
Robert
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:
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.
Re: How to save a file to report directory
That's it!
Thanks a lot!!
Regards,
Roman
Thanks a lot!!
Regards,
Roman
Re: How to save a file to report directory
Hi,
Is there anyway to download pdf from an url using javascirpt within Ranorex?
Is there anyway to download pdf from an url using javascirpt within Ranorex?
- Support Team
- 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
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
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