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.
extending Ranorex.Report
- RobinHood42
- Posts: 324
- Joined: Fri Jan 09, 2015 3:24 pm
Re: extending Ranorex.Report
Hi sergii,
I guess the best way would be to use extension methods.
Further readings:
Cheers,
Robin
I guess the best way would be to use extension methods.
Further readings:
- http://www.ranorex.com/forum/extend-the ... tml#p28208
https://msdn.microsoft.com/en-us/library/bb311042.aspx
https://msdn.microsoft.com/en-us/library/bb383977.aspx
Cheers,
Robin
Re: extending Ranorex.Report
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.
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.
- RobinHood42
- Posts: 324
- Joined: Fri Jan 09, 2015 3:24 pm
Re: extending Ranorex.Report
Hi,
I'm afraid that this is not possible.
Further reading:
Robin
I'm afraid that this is not possible.
Further reading:
- http://stackoverflow.com/questions/1116 ... or-why-not
http://stackoverflow.com/questions/8995 ... ion-method
Robin
Re: extending Ranorex.Report
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...
Re: extending Ranorex.Report
I have found pretty elegant and easy solution to my problem.
I just needed to add this two methods to the extension methods:
As a result, now I can use the following code in an easy to read that is self explanatory.
For some reason I found this:
to be much harder to read than this:
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());
}
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());
Code: Select all
("myInt="+myInt).Print();