Ranorex Reports always with Screenshots

Ask general questions here.
saengk
Posts: 1
Joined: Tue Dec 11, 2018 11:08 am

Ranorex Reports always with Screenshots

Post by saengk » Tue Dec 11, 2018 10:57 pm

Hello,

I have a question about screenshots in reports.
If you start a test and it aborts with an error, then I get screenshots for the complete test case in the report. In the previous test cases are missing the screenshots.
Or if the test is completely error-free, then no screenshots will be contained in the report.

Now my question, how and where can I change that the report always contains screenshots? I have already searched the forum and the Internet search, but found nothing. I also do not want to call in every test case methods for screenshot creation.
I hope it’s existing a simply solution.

Thank you in advance

Ranorex 8.3
Windows 7

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

Re: Ranorex Reports always with Screenshots

Post by odklizec » Wed Dec 12, 2018 11:18 am

Hi,

As far as I know, there is no "one switch" option (not even via public API) to enable report screenshots for each step. Currently, Ranorex creates screenshots only for failing steps. The only way to achieve what you want is to manually add a Report Screenshot action before/after each step.

BTW, you can make a feature request here:
https://uservoice.ranorex.com/forums/15 ... ve-ranorex
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

User avatar
Support Team
Site Admin
Site Admin
Posts: 11963
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Ranorex Reports always with Screenshots

Post by Support Team » Wed Dec 12, 2018 1:21 pm

Hi guys,

I found a way to actually log a screenshot for every single step within your solution.

Please be aware that this might cause performance issues and the report size will increase significantly.

First of all, you'll need to add a new C# Code File to your project. Let's call it MyLogger(), there you need to implement the IReportLogger interface:
public class MyLogger : IReportLogger

Use the following code to enable the screenshot for every step:
void IReportLogger.LogText(Ranorex.ReportLevel level, string category, string message, bool escape, System.Collections.Generic.IDictionary<string, string> metaInfos)
		{
			if(category != "MyCategory")
			{
				foreach (var info in metaInfos)
				{				
					if(info.Key == "type" && info.Value == "repoitem")
					{
						//Logs the whole screen
						Report.Screenshot(ReportLevel.Info, "MyCategory", "", null , false, null);
						
						//Logs specific repo item 
						Report.Screenshot(ReportLevel.Info, "MyCategory", "", Host.Local.FindSingle(GetPathFromMetaInfos(metaInfos)), false, null);
					}
				}
			}
		}
		
		private RxPath GetPathFromMetaInfos(System.Collections.Generic.IDictionary<string, string> metaInfos)
		{
			foreach (var info in metaInfos)
		{
				if(info.Key == "path")
				{
					return info.Value;
				}
			}
			
			return String.Empty;
		}
	
Hint: Its not required to implement the other methods from the interface, simply delete the "threw new Exception".

As a final step, we need to add the custom logger to the current report (Program.cs):
class Program
	{
		[STAThread]
		public static int Main(string[] args)
		{
			// Uncomment the following 2 lines if you want to automate Windows apps
			// by starting the test executable directly
			//if (Util.IsRestartRequiredForWinAppAccess)
			//    return Util.RestartWithUiAccess();

			Keyboard.AbortKey = System.Windows.Forms.Keys.Pause;
			int error = 0;
			
                         //Add custom logger
			Ranorex.Report.AttachLogger(new MyLogger());
			Ranorex.Report.Start();

Hope this helps ;)

Sincerely,
Robert
.
Image

mariaspeigl
Posts: 13
Joined: Mon Jan 07, 2019 11:50 am
Location: Germany (Bavaria)

Re: Ranorex Reports always with Screenshots

Post by mariaspeigl » Mon Jan 14, 2019 12:40 pm

Hello Robert,

thanks for your instruction.
Generally it works for me (no adjustments made yet):
2019-01-14 12_37_21-C__Users_q32742_Documents_Maria_06_Workspace_14012019-1103_RanorexBamboo_Ranorex.jpg
2019-01-14 12_37_21-C__Users_q32742_Documents_Maria_06_Workspace_14012019-1103_RanorexBamboo_Ranorex.jpg (264.26 KiB) Viewed 237 times
As you can see the screenshots mostly contain all my used (3) screens.
How can I restrict it to only show the AUT?

Thank you in advance.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11963
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Ranorex Reports always with Screenshots

Post by Support Team » Tue Jan 15, 2019 10:37 am

Hello Maria,

You would simply need to use your "topmost" element of your application under test within the Report.Screenshot() method.

E.g.:
Report.Screenshot(ReportLevel.Info, "MyCategory", "", Host.Local.FindSingle("/form[@controlname='YOUR APP']"), false, null); 
Sincerely,
Robert
.
Image

mariaspeigl
Posts: 13
Joined: Mon Jan 07, 2019 11:50 am
Location: Germany (Bavaria)

Re: Ranorex Reports always with Screenshots

Post by mariaspeigl » Tue Jan 15, 2019 11:27 am

Thanks for your help. In future I will examine the code sample more in detail at first :wink:

I have got an additonal question to the Report.Screenshot function.
My code looks like this:

Code: Select all

Report.Screenshot(ReportLevel.Info, "Screenshot", "", Host.Local.FindSingle("/form[@processname='RxDemoApp']"), true, null);
Due to the fact that I would like to highlight the respective element, I set the value for the parameter highlightWithinSurroundingArea to true.
In the result-file there is no surrounding area and the screen is cropped on both sides.

Here is the comparison:

highlightWithinSurroundingArea = false
2019-01-15 11_24_48-RanorexBamboo_TS - Ranorex Studio (Administrator).jpg
2019-01-15 11_24_48-RanorexBamboo_TS - Ranorex Studio (Administrator).jpg (63.79 KiB) Viewed 220 times


highlightWithinSurroundingArea = true
2019-01-15 11_23_26-RanorexBamboo_TS - Ranorex Studio (Administrator).jpg
2019-01-15 11_23_26-RanorexBamboo_TS - Ranorex Studio (Administrator).jpg (66.01 KiB) Viewed 220 times


I supposed to get a screenshot of the AUT and see a red surrounding e.g. around the text box.
When I change the code to this:

Code: Select all

Report.Screenshot(ReportLevel.Info, "Screenshot", "", Host.Local.FindSingle(GetPathFromMetaInfos(metaInfos)), true, null);
I get the red surrounding for the element, but I can not see the whole AUT window:
RanorexB_b93ff564_rxlog.jpg
RanorexB_b93ff564_rxlog.jpg (9.41 KiB) Viewed 220 times

Do you have another option for solving this?
Sorry for all those questions - I am pretty new to Ranorex...
Attachments
2019-01-15 11_23_26-RanorexBamboo_TS - Ranorex Studio (Administrator).jpg
2019-01-15 11_23_26-RanorexBamboo_TS - Ranorex Studio (Administrator).jpg (66.01 KiB) Viewed 221 times

User avatar
Support Team
Site Admin
Site Admin
Posts: 11963
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Ranorex Reports always with Screenshots

Post by Support Team » Wed Jan 16, 2019 1:24 pm

Hello Maria,

It seems like the issue is related to the "RxDemoApp". Did you try to use the "highlightWithinSurroundingArea" for any other applications under test?

Sincerely,
Robert
.
Image

mariaspeigl
Posts: 13
Joined: Mon Jan 07, 2019 11:50 am
Location: Germany (Bavaria)

Re: Ranorex Reports always with Screenshots

Post by mariaspeigl » Thu Mar 21, 2019 2:54 pm

Hello Robert,

I did not use the "highlightWithinSurroundingArea" for any other applications under test.
I also tried this solution in our "real" application. The problem occurs there, too.

Code: Select all

Report.Screenshot(ReportLevel.Info, "Screenshot", "", Host.Local.FindSingle("/form[@controlname='FormFramework']"), true, null);
Image

User avatar
Support Team
Site Admin
Site Admin
Posts: 11963
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Ranorex Reports always with Screenshots

Post by Support Team » Thu Mar 28, 2019 8:36 am

Hello Maria,

Did you try to run the test on your local machine? Is the border visible if doing so?

Sincerely,
Robert
.
Image