extending Ranorex.Report

Ask general questions here.
sergii
Posts: 30
Joined: Fri Jun 07, 2013 11:07 pm

extending Ranorex.Report

Post by sergii » Thu Jan 12, 2017 1:47 am

As I understand there is a Ranorex namespace with public class Report inside.

We have a need to extend the standard logging functionality.
One of the simplest examples is to make a wrapper for Report.Info(string s) to make it possible to pass not only variables, but int variables as well.

I'm trying to think about ways to extend the Ranorex.Report class with something like this:
Report.Info(int i){
Report.Info(i.ToString());
}

As well as several other custom useful methods.

Is there a way to properly extend the functionality of Ranorex classes?


PS. I'm already extending adapter methods with custom options like adapter.RightClickAndSelect(string s) so code looks very nice and easy to read for non-automation people. I would appreciate any ideas what else can be extended to provide better customization.

User avatar
RobinHood42
Posts: 239
Joined: Fri Jan 09, 2015 3:24 pm

Re: extending Ranorex.Report

Post by RobinHood42 » Fri Jan 13, 2017 9:45 am


sergii
Posts: 30
Joined: Fri Jun 07, 2013 11:07 pm

Re: extending Ranorex.Report

Post by sergii » Fri Jan 13, 2017 11:08 pm

Thank you.
We are already using extension methods, but I'm unable to extend the Ranorex.Report functionality.

Anybody added new methods to Ranorex class itself here? (Instead of creating new Methods to the Ranorex objects)
I understand that I can extend the Adapter for example and can make Ranorex.Button.NewMethod() to do something new.

User avatar
RobinHood42
Posts: 239
Joined: Fri Jan 09, 2015 3:24 pm

Re: extending Ranorex.Report

Post by RobinHood42 » Wed Jan 18, 2017 10:52 am

Hi,

I'm afraid that this is not possible.

Further reading:
Cheers,
Robin

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: extending Ranorex.Report

Post by krstcs » Wed Jan 18, 2017 2:27 pm

The Ranorex Report class expects all message elements to be strings. You should convert your data to a string before using the Report method of your choice. This is the best and most appropriate way to handle this type of situation.

Code: Select all

Report.Info("myInt = " + myInt.ToString());
Shortcuts usually aren't...

sergii
Posts: 30
Joined: Fri Jun 07, 2013 11:07 pm

Re: extending Ranorex.Report

Post by sergii » Mon Jan 23, 2017 11:18 pm

I have found pretty elegant and easy solution to my problem.
I just needed to add this two methods to the extension methods:

Code: Select all

        public static void Print(this String s){
            Report.Info(s);
        }
        
        public static void Print(this int i){
            Report.Info(i.ToString());
        }
As a result, now I can use the following code in an easy to read that is self explanatory.

Code: Select all

int age = 40;
("his age is "+age).Print();
(123).Print();
"searching for patient with specific name".Print(); 

For some reason I found this:

Code: Select all

Report.Info("myInt = " + myInt.ToString());
to be much harder to read than this:

Code: Select all

("myInt="+myInt).Print();