Page 1 of 1

extending Ranorex.Report

Posted: Thu Jan 12, 2017 1:47 am
by sergii
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.

Re: extending Ranorex.Report

Posted: Fri Jan 13, 2017 9:45 am
by RobinHood42

Re: extending Ranorex.Report

Posted: Fri Jan 13, 2017 11:08 pm
by sergii
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.

Re: extending Ranorex.Report

Posted: Wed Jan 18, 2017 10:52 am
by RobinHood42
Hi,

I'm afraid that this is not possible.

Further reading:
Cheers,
Robin

Re: extending Ranorex.Report

Posted: Wed Jan 18, 2017 2:27 pm
by krstcs
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());

Re: extending Ranorex.Report

Posted: Mon Jan 23, 2017 11:18 pm
by sergii
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();