Clean up reports and images

Best practices, code snippets for common functionality, examples, and guidelines.
csolanki
Posts: 73
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.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3922
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: 73
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.
Attachments
programcspart3.PNG
programcspart3.PNG (24.96 KiB) Viewed 81 times
programcspart2.PNG
programcspart2.PNG (39.93 KiB) Viewed 81 times
programcspart1.PNG
programcspart1.PNG (31.64 KiB) Viewed 81 times

csolanki
Posts: 73
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.
Attachments
ReportRanorex.PNG
ReportRanorex.PNG (12.41 KiB) Viewed 80 times
Logoutprogramcs.PNG
Logoutprogramcs.PNG (14.73 KiB) Viewed 80 times

McTurtle
Posts: 191
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
Ranorex Studio.png (17.23 KiB) Viewed 67 times
Does this help?

Regards,
McTurtle

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3922
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