Page 1 of 1

using normal varaible in XPath

Posted: Wed Dec 18, 2019 7:09 am
by prasoon.jmit
I have a user code and for user code I am not able to define repository variable. Can I use normal variable inside XPath as @helptext?

Re: using normal varaible in XPath

Posted: Wed Dec 18, 2019 8:17 am
by odklizec
Hi,

If you are hardcoding xpaths in user code (in Recording module), you must apply the variable like this (where cellCSVValue is the variable):

Code: Select all

var spanItem = selectPopUpItem.FindSingle<Ranorex.SpanTag>(".//span[@class='mat-option' and @innertext~'" + cellCSVValue + "']", Duration.FromMilliseconds(15000));

Re: using normal varaible in XPath

Posted: Wed Dec 18, 2019 2:39 pm
by prasoon.jmit
Hi,

Thanks for quick response.

My XPath is like "element[@automationid='Test']/?/?/element[@automationid='Cell_User' and @helptext=$varReadOnlyWorkspaceName]"


Can I Use $varReadOnlyWorkspaceName as normal variable in place of repository variable? If yes, than what is the use of Repository variable?

Re: using normal varaible in XPath

Posted: Wed Dec 18, 2019 2:45 pm
by odklizec
Hi,

I'm afraid, I don't quite understand what you are trying to achieve? The xpath you posted in how you have it stored in repo, right? Now what exactly you would like to do with it?

Re: using normal varaible in XPath

Posted: Wed Dec 18, 2019 2:56 pm
by prasoon.jmit
Hi,

Yes the XPath is stored in Repository.

I have one recording e.g. abc.rxrec. In Recording I have UserCode(Name of method is SelectUser), inside userCode I am accessing the repository item like repo.Cell.Click() (cell is the repository item whose path I have shared in first post). I am planning to use abc.rxrec in multiple projects, so I am thing to make variable inside XPath as bindable so that I can reuse the code.

That's the reason I want to know can I make variable $varReadOnlyWorkspaceName as normal variable and bind it with variable at "SmartFolder" level?

Re: using normal varaible in XPath

Posted: Wed Dec 18, 2019 3:22 pm
by odklizec
Hi,

$varReadOnlyWorkspaceName is normal module variable, so yes, you can bind it to TestCase or SmartFolder data connector or even TC/SF parameter.

Once there is created a module variable (either in action table or repository) and the variable is applied in action table or repository element and the repo element is used in recording module, you should see "unbound variable" in TestSuite, in which the recording module is used. Then you simply bind the variable to TC/SF data connector. The module variable is automatically available also in user code of given recording module.
RepoVars.png

Re: using normal varaible in XPath

Posted: Wed Dec 18, 2019 3:30 pm
by prasoon.jmit
Hi,

Thanks a lot for detailed explanation. Most of the things are clear. Just one confusion $testVar as I can see in screenshot is the "Repository Variable", can I use variable which is normal variable not a repository variable?

Re: using normal varaible in XPath

Posted: Wed Dec 18, 2019 3:35 pm
by odklizec
If you mean a recording variable (created in action table via 'Variables' editor), then yes. If you mean a variable created directly in user code, then no. You must create a Recording variable, which is the only way, how to bind module variables with data connectors/parameters.

Re: using normal varaible in XPath

Posted: Wed Dec 18, 2019 4:15 pm
by prasoon.jmit
Hi,

Thanks a lot. This cleared my doubt .

So what is the advantage of repository variable, if we can achieve same thing using recording variable?

Re: using normal varaible in XPath

Posted: Thu Dec 19, 2019 8:26 am
by odklizec
Hi,

You are welcome.

As for the repository variables, for me, they are the same as recording variables. Once a repository variable is applied in repo element, which is used in recording module, then there is added a new variable also to the list of recording module variables. The only difference is that you don't see all repository variables in the list of recording module variables, but only those, which are actually used in recording module (repo elements with associated repo variables).