Clean up reports and images

Best practices, code snippets for common functionality, examples, and guidelines.
csolanki
Posts: 120
Joined: Thu Mar 22, 2018 8:51 am

Clean up reports and images

Post by csolanki » Thu Sep 20, 2018 8:58 am

Hi Team,

I have been browsing about cleaning up files from ranorex folders. So, got some generic clean up folders zip file from forum. But is there way for ex. it is there in Python, we can clean up by `bin/cleanup`.

Do we have any terminal command or a file which can clean up result files, not specific folder.

You support is always appreciated. Thanks.
Regards,
Charu Solanki
Ranorex User

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Clean up reports and images

Post by odklizec » Thu Sep 20, 2018 9:26 am

Hi,

You can use simple batch commands for cleanup at the end of test. I'm using something like this in my Jenkins configuration (in post build steps).

Code: Select all

echo delete success report files older than 2 days
forfiles -p "%WORKSPACE%\Reports" -s -m *_Success.rxzlog -d -2 -c "cmd /c del @path"
echo delete failed report files older than 30 days
forfiles -p "%WORKSPACE%\Reports" -s -m *_Failed.rxzlog -d -30 -c "cmd /c del @path"

echo delete bin\Reports folder
cd %WORKSPACE%\tfs\RHMonitoring\bin
rmdir /S /Q %WORKSPACE%\tfs\RHMonitoring\bin\Reports

echo delete Reports\unpacked folder
cd %WORKSPACE%\Reports
rmdir /S /Q %WORKSPACE%\Reports\unpacked

if ERRORLEVEL 1 exit 0
Eventually, you can use something like this, for deleting uncompressed report files at the end of each test run, ideally, call this method as a very last line in program.cs (just before return):

Code: Select all

		/// <summary>
		/// Delete uncompressed report files
		/// </summary>
		public static void DeleteUncompressedReport()
		{
			Ranorex.Core.Reporting.TestReport.EndTestCaseContainer();
			Ranorex.Core.Reporting.TestReport.SaveReport();
			List<string> listReportFiles = Ranorex.Core.Reporting.TestReport.ReportEnvironment.GetDependentFiles();
			foreach(string file in listReportFiles)
			{
				try
				{
					System.IO.File.Delete(file);					
				}
				catch (Exception e)
				{
					Report.Info("Unexpected exception occurred: " + e.ToString());
				}
			}
			string pathReportImagesDir = Ranorex.Core.Reporting.TestReport.ReportEnvironment.ReportScreenshotFolderPath;
			if (System.IO.Directory.Exists(pathReportImagesDir))
			{
				try
				{
					System.IO.Directory.Delete(pathReportImagesDir);
				}
				catch (Exception e)
				{
					Report.Info("Unexpected exception occurred: " + e.ToString());
				}				
			}
		} 
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

csolanki
Posts: 120
Joined: Thu Mar 22, 2018 8:51 am

Re: Clean up reports and images

Post by csolanki » Thu Sep 20, 2018 2:28 pm

Hey,

I have executed the same. Added this module before return errors and called it in logout function. But still I can find reports present in reports folder. PFA, if it can help in identification of proceeding wrong steps.
You do not have the required permissions to view the files attached to this post.
Regards,
Charu Solanki
Ranorex User

csolanki
Posts: 120
Joined: Thu Mar 22, 2018 8:51 am

Re: Clean up reports and images

Post by csolanki » Mon Sep 24, 2018 11:05 am

Output folder and logout function call.
You do not have the required permissions to view the files attached to this post.
Regards,
Charu Solanki
Ranorex User

McTurtle
Posts: 297
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Clean up reports and images

Post by McTurtle » Tue Sep 25, 2018 1:52 pm

Hello csolanki,

You wrote: "Added this module before return errors and called it in logout function." I think it does not really matter where you add the method. However, it does matter where you call it. You need to call it before return not in logout function:
Ranorex Studio.png
Does this help?

Regards,
McTurtle
You do not have the required permissions to view the files attached to this post.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Clean up reports and images

Post by odklizec » Tue Sep 25, 2018 2:45 pm

Hi csolanki,

McTurtle is right! It must be called as a very last thing in Program.cs, just before return.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

csolanki
Posts: 120
Joined: Thu Mar 22, 2018 8:51 am

Re: Clean up reports and images

Post by csolanki » Mon Nov 26, 2018 1:17 pm

Hey Mcturtle and Odklizec,

Thanks a lot for helping me out. It worked after addition of delete method in program.cs.


Regards,
Charu Solanki
Regards,
Charu Solanki
Ranorex User