Passing a variable as a parameter

Ask general questions here.
usov
Posts: 17
Joined: Mon Dec 04, 2017 11:13 am

Passing a variable as a parameter

Post by usov » Wed Jun 20, 2018 3:42 pm

Hello!
There are variables in the repository:
repo.Text and repo.TextInput
RXPath repo.TEST.ButtonInfo = /form[@name='program']//button[@name=$Text]
RXPath repo.TEST.InputInfo = /form[@name='program']//input[@name=$TextInput]

Tell me please, can I make a method that takes a variable and RepoItemInfo and inserts it into the RepoItemInfo ?

Get something like this

Code: Select all

       

       public static void WaitingElements(RepoItemInfo info,string param,string name)
        {
          param = text;
          info.WaitForExists(3000);
        }

            /* RXPath repo.TEST.ButtonInfo  = /form[@name='program']//button[@name=$Text]*/
            WaitingElements(repo.TEST.ButtonInfo,repo.Text,"Search");
            
            /* RXPath repo.TEST.InputInfo  = /form[@name='program']//input[@name=$TextInput]*/
            WaitingElements(repo.TEST.InputInfo,repo.TextInput,"Name");



User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Passing a variable as a parameter

Post by Support Team » Wed Jun 20, 2018 9:49 pm

Hi Usov,

As long as I understand what you are trying to achieve correctly, the following should work: Set the variable before performing the action on the object like so:

MyRepo.Instance.FormRun.SelfInfo = "/form[@title=$varTitle]"

Code: Select all

SampleMethod(MyRepo.Instance.FormRun.SelfInfo, "Run");

public static void SampleMethod(RepoItemInfo repoItem, string title)
{
	MyRepo.Instance.varTitle = title;
	repoItem.WaitForExists(3000);
}
I hope this helps!

Cheers,
Ned
.
Image

usov
Posts: 17
Joined: Mon Dec 04, 2017 11:13 am

Re: Passing a variable as a parameter

Post by usov » Thu Jun 21, 2018 11:36 am

I already use the code you suggested.
But my question is a little different....
If I use different variables in different RepoItemInfo how do I pass the names of the variables themselves to the method?

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

Re: Passing a variable as a parameter

Post by odklizec » Thu Jun 21, 2018 11:44 am

Hi,

There is no way to pass the name of variable to method. What you can do, is to create a single repo item for both elements with the same variable name, e.g. like this:
RXPath repo.TEST.ElementInfo = /form[@name='program']//*[@name=$Text]

Eventually, you can create a method, with two parameters (one for each variable).
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

usov
Posts: 17
Joined: Mon Dec 04, 2017 11:13 am

Re: Passing a variable as a parameter

Post by usov » Thu Jun 21, 2018 12:31 pm

I'm understood, thank you