Page 1 of 1

How Can I Modify Repository’s Template for Code Generation?

Posted: Tue Jan 22, 2013 3:25 am
by WHAuden
We are using Ranorex repository extensively for our web testing. The structure of our repository, almost always, represents the structure of our web pages.

For example if customer order page has the structure:

Code: Select all

We organize the repository such that: “Order “ is the root; “Customer” is a folder under root; “MailingAddress” is a subfolder under "Customer" and naturally “StreetAddress” is an item under “MailingAddress” folder. With this structure in place, Ranorax generates a very intuitive class structure that allows us to access each elements of the page very easily.

So we can access StresstAddress by typing:

Code: Select all

This is very nice but going forward, I would like to expand the inner most member: Repository item (In the example above that would be the StreetAddress item) by adding a few properties and methods.

For example I want to add a property called:

Code: Select all

and a method called

Code: Select all

LoadFromDataSource(string DataSourceName)
so I can write:

Code: Select all

Order.Customer.MailingAddress.StreetAddress.ExpectedValue = “Hello”;

Code: Select all

These properties and methods are simple, always identical and tedious to write. It’s trivial to add these functions to Repository.cs but clearly they get overwritten every time something changes in the repository.

I assume that Ranorex uses a template similar to Visual Studio & T4 to generate the repository code. If there is such a template, it will be great if I can modify it to get Ranorex to automatically generate the code for our custom properties and methods.
  • Is there a way to modify the code generating template for the repository?
  • If there is, what steps are required to add custom methods and properties for each items in the repository?
  • Are there any other mechanisms in Ranorex that allows for automated creation of custom properties & methods for each items in the repository? (We already do use module variables)

We're open to any solution with the same effect.

Re: How Can I Modify Repository’s Template for Code Generation?

Posted: Wed Jan 23, 2013 8:41 am
by Support Team

Unfortunately that's not possible in Ranorex to change some kind of a repository template, but you can create a new class which inherits the original repository class. With an instance of the new class you will have access to the repo items in the original repository.
public class RepoExtension : OrigRepoClassRepository
   // add your methods and properties here
Is this an option for you?