RepoItem as variable in code module

Best practices, code snippets for common functionality, examples, and guidelines.
RekhaG
Posts: 17
Joined: Fri Sep 22, 2017 12:47 am

RepoItem as variable in code module

Post by RekhaG » Wed Dec 06, 2017 7:31 pm

Hello Ranorex Gurus,

I have a question regarding automation frame work design on how to pass the UI control name(repoItem) as user variable and get its xpath at runtime and perform the specified action on that control.

Below is the structure of the my UI automation framework

solution contains
-> Standard Controls Project( contains all the UI controls and their code modules. For Example: Textbox control and one of its code module "SetTextbyValue"))
->Repositories Project( contains only repositories)
->MainAutomationProject(contains Test suite, Standard Controls Project reference, Repositories Project reference)

If i have to build a test case and use "SetTextbyValue" code module to access LoginTextbox control on Login Page, how can i achieve that by just passing the repositoryItem(login textbox) as a user variable to "SetTextbyValue" code module?

I was going through some post in the forums and mentioned to use .net reflection for a similar issue. Can someone help me undersand in a better way (may be with example) on how can i achieve that please?

Thanks,
Rekha

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

Re: RepoItem as variable in code module

Post by odklizec » Thu Dec 07, 2017 8:45 am

Hi Rekha,

I believe that the .net reflection, mentioned in some old posts, was used at a time when there was no way to pass repo items as parameters? This limitation is long time gone and you can pass a repo item to method as an adapter or repoinfo object. Maybe I misunderstand something, but I don't see a reason why to pass the repo elements as string variables and then convert them to repo elements? ;)
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

RekhaG
Posts: 17
Joined: Fri Sep 22, 2017 12:47 am

Re: RepoItem as variable in code module

Post by RekhaG » Tue Dec 12, 2017 11:47 pm

Thanks for your reply Pavel!

This is basically what i wanted to do
Testcase
1.Pass the input for the Text box to CodeModule
2. Pass the Control name (For Example: LoginTextbox)
3. Pass the Repository name ?? (not sure if this is needed)

Steps 1-3 are all input variables to the code module "SetTextByValue". User will have the knowledge of only first 3 input values.
Based on your suggestion If i pass the repo Item to a Method. From where does the user inputs the value to this method? should not it be a UserVariable at the databinding level? So how does the rxPath get generated ?
For example:
GetTextControl(RepositoryItem item)
{

}

May be i am confused. Can you please help. May be with an example?

Thanks a lot!
Rekha

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

Re: RepoItem as variable in code module

Post by odklizec » Wed Dec 13, 2017 9:01 am

Hi,

Sorry, but I'm still confused ;) I'm failing to see a reason, why you would like to use element name as a variable? Using data connector for input values is obvious, but why using data connector for UI elements? Using recording/code modules with parametrized actions/methods (linked to mapped repo items) seems to be an obvious solution to me? But maybe I'm missing a crucial point? Could you please post a Ranorex snapshot of the app you are trying to automate? And maybe also screenshot of the recording/code module (and test suite structure as well) you are trying to use? Ideally, post a small Ranorex sample solution. Thanks.
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

RekhaG
Posts: 17
Joined: Fri Sep 22, 2017 12:47 am

Re: RepoItem as variable in code module

Post by RekhaG » Wed Dec 13, 2017 11:22 pm

Hi Pavel,

Thank you so much for helping me out here. I am pretty new ranorex and designing the automation framework as well. So i just started to design the automation framework and here are my thoughts in building it. Please suggest what you think could be ideal in building the framework.

The idea is to have the code modules for all the common UI controls in one project and use these code modules to build the test suite/test cases in another project by passing the necessary parameters to build a particular test case. Attached is the highlevel document to describe wht consists in each project under the solution

Thanks,
Rekha
You do not have the required permissions to view the files attached to this post.

RekhaG
Posts: 17
Joined: Fri Sep 22, 2017 12:47 am

Re: RepoItem as variable in code module

Post by RekhaG » Wed Dec 13, 2017 11:24 pm

another doc attached
You do not have the required permissions to view the files attached to this post.

Vaughan.Douglas
Posts: 254
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Re: RepoItem as variable in code module

Post by Vaughan.Douglas » Thu Dec 14, 2017 1:45 pm

It sounds like you want to parameterise your object names as strings along with the values. A couple of us discussed something similar here. I think that will get you what you're looking for, but maybe take a step back a bit on your design. It seems like you might be over engineering a solution and overlooking some of the major strengths a tool like Ranorex provides.

One test solution can have many projects each with their own test suite. You can add a (or many) Test Suite Module Libraries which will hold your modules for use in other projects (and contains no actual test suite). Remember Ranorex is backed by DotNet, so anything you can do in C# or VB.Net you can also do in Ranorex.

The next thing I might suggest is to build and organize your automation from the UI -> code as opposed to code -> UI. I prefer some variation on the page object model, but I've also organized by workflow (how information/tasks move through the system) and business flow (how users interact with the system). Remember Ranorex is a functional testing tool developed to interact with a GUI.

It's not that you can't do what you've laid out, I wouldn't have that code sample to provide in the link above if I hadn't tried something similar. I would encourage you to see if you can accomplish your task using the means and methods provided in the tool you've just paid to license. It may not be as elegant, but it will probably be easier to maintain.
Doug Vaughan

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

Re: RepoItem as variable in code module

Post by odklizec » Thu Dec 14, 2017 2:23 pm

Hi,

Absolutely agree with Doug here. In my opinion, you are making the things much more complicated than necessary. I now understand that you are trying to create your own "general" framework, that would work across the company and projects? Well, I think it's huge project and you may eventually find yourself deep in the s.... (mud) ;)

I personally would suggest to use existing Ranorex workflow and tool, rely mainly on Ranorex recordings with existing actions and only use user code and code modules when absolutely necessary. It's makes sense to create a library with common methods and pass the repo elements into methods using adapter or repo item info elements. So you can share such library in multiple projects. But I would keep it as simple as possible. Definitely not creating a method for each single input or button.

The more code you write yourself, the biggest chance there will fail something. Ranorex framework is thoroughly tested between versions and even then, there are bugs introduced here or there. So why not to use what's already tested and proved functional? I think you will save yourself a lot of time and nerves ;)
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

RekhaG
Posts: 17
Joined: Fri Sep 22, 2017 12:47 am

Re: RepoItem as variable in code module

Post by RekhaG » Mon Dec 18, 2017 9:15 pm

Hi Doug/Pavel,

Thank you for your valuable inputs. Just wanted to reconfirm that following approach(shown in the pic attached) would be ideal when using Ranorex studio. Please suggest

Thanks,
Rekha
You do not have the required permissions to view the files attached to this post.

Vaughan.Douglas
Posts: 254
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Re: RepoItem as variable in code module

Post by Vaughan.Douglas » Tue Dec 19, 2017 7:11 pm

RekhaG wrote:Hi Doug/Pavel,

Thank you for your valuable inputs. Just wanted to reconfirm that following approach(shown in the pic attached) would be ideal when using Ranorex studio. Please suggest

Thanks,
Rekha
Sure, that would work. You could also combine the two library projects into a single project (if you're using VB .net you could run into trouble with a shared object repository).

In general I think about projects in a solution in terms of test suites. I might have a single solution with a dozen different projects covering different aspects of the AUT. The key is organization. Any resources that are shared among the various projects should originate from a library project. Any modules that are highly specialized and can not serve outside the scope of a specific project should be sourced in that project. This can help keep your libraries a little more organized.

Reusability is key but it can cut both ways. You can create something that is ultimately reusable but is so complex maintaining it becomes problematic. If you're creating something that you intend non-technical resources to work with simplicity may be more valuable than reusability.
Doug Vaughan

RekhaG
Posts: 17
Joined: Fri Sep 22, 2017 12:47 am

Re: RepoItem as variable in code module

Post by RekhaG » Tue Dec 19, 2017 7:15 pm

Thanks Doug! I code using C# :)