Binding multiple variables to a repository item

Ask general questions here.
grobertsoncte2017
Certified Professional
Certified Professional
Posts: 4
Joined: Thu Aug 17, 2017 9:30 pm

Binding multiple variables to a repository item

Post by grobertsoncte2017 » Thu Aug 17, 2017 9:54 pm

I'm testing a web-based application, and I need to find a button based on the value of an underlying attribute. This is an example of the button's xpath:

//input[@class='btn btn-default' and @tagvalue='Process' and @data-membershipnumberlistcsv='' and @data-agreementnumberlistcsv='12345,54321'

I set the @data-agreementnumberlistcsv attribute to be variable within the repository, so I can pass the appropriate values programmatically to find the correct button, thus:

//input[@class='btn btn-default' and @tagvalue='Process' and @data-membershipnumberlistcsv='' and @data-agreementnumberlistcsv=$strAggAgreeNum

As you can see from the first example, the value of the @data-agreementnumberlistcsv attribute is a comma-delimited list of numbers. But the application I'm testing is inconsistent with how it sets the value of @data-agreementnumberlistcsv; it could be either '12345,54321' or '54321,12345' (for example). To handle each combination, what I hope to do is pass two separate variables to the repository item like this:

//input[@class='btn btn-default' and @tagvalue='Process' and @data-membershipnumberlistcsv='' and @data-agreementnumberlistcsv=$strAggAgreeNum or @data-agreementnumberlistcsv=$strAggAgreeNum2

How do I go about binding this second variable to this repository item?

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

Re: Binding multiple variables to a repository item

Post by odklizec » Fri Aug 18, 2017 1:14 pm

Hi,

If I understand your problem correctly, all you need to do is to create a second column in the data connector, so then you can have both numbers attached to the xpath.

So the data connector should look like this:

Code: Select all

strAggAgreeNum|strAggAgreeNum2
12345,54321   |54321,12345
And then simply connect both variables with appropriate data connector columns. Hope this helps?
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

grobertsoncte2017
Certified Professional
Certified Professional
Posts: 4
Joined: Thu Aug 17, 2017 9:30 pm

Re: Binding multiple variables to a repository item

Post by grobertsoncte2017 » Fri Aug 18, 2017 2:22 pm

Hi Pavel! Thanks for your reply! Unfortunately, I don't think I explained myself very well. I apologize for that and I'll try again.

The following screenshot is of the repo item editor in Ranorex (version 6.2.1) that I think illustrates the crux of my issue - I cannot bind more than one variable to a repo item/attribute.
RanorexRepoEdit2.jpg
First screen shot
RanorexRepoEdit2.jpg (133.54 KiB) Viewed 639 times

When I try to manually construct an "or" condition in the xpath (like this: //input[@class='btn btn-default' and @tagvalue='Process' and @data-membershipnumberlistcsv='' and @data-agreementnumberlistcsv=$strAggAgreeNum or @data-agreementnumberlistcsv=$strAggAgreeNum2), I get the issue illustrated in this screen shot:
RanorexRepoEdit3.jpg
Second screen shot
RanorexRepoEdit3.jpg (108.31 KiB) Viewed 639 times
Is there a way to work around this limitation?

Thanks!

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Binding multiple variables to a repository item

Post by krstcs » Fri Aug 18, 2017 2:25 pm

You can use multiple variables in an xpath attribute, but Ranorex won't do it for you.

Code: Select all

/div[@innertext=$myVar1 + ' ' + $myVar2]
This can be done directly in the XPath edit area of the repo or in Spy. You just won't be able to do it in the drop downs on the bottom right of Spy.

ETA: And as you can see from your last post, the Ranorex UI doesn't support 'or', only 'and', but Ranorex itself works fine with 'or'. I would, however, highly recommend against using 'or' as it can cause serious issues with object identification if not used correctly. You might end up finding the wrong element and not knowing why.
Last edited by krstcs on Fri Aug 18, 2017 2:28 pm, edited 1 time in total.
Shortcuts usually aren't...

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

Re: Binding multiple variables to a repository item

Post by odklizec » Fri Aug 18, 2017 2:28 pm

Hi,

Maybe I'm missing something here, but I believe this error is not a problem at all. It's just not possible to edit such xpath in Spy edit window. But the xpath itself should be OK?

Anyway, I think the things would be much easier if you could post a Ranorex snapshot of the problematic element. 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

grobertsoncte2017
Certified Professional
Certified Professional
Posts: 4
Joined: Thu Aug 17, 2017 9:30 pm

Re: Binding multiple variables to a repository item

Post by grobertsoncte2017 » Fri Aug 18, 2017 3:54 pm

Here's the xpath that I'm using for my repo item:

//input[@class='btn btn-default' and @tagvalue='Process' and @data-membershipnumberlistcsv='' and @data-agreementnumberlistcsv=$strAggAgreeNum or @data-agreementnumberlistcsv=$strAggAgreeNum2

And this is the error that Ranorex throws when I run my test:
RanorexRepoEdit4.jpg
Error Report
RanorexRepoEdit4.jpg (71.84 KiB) Viewed 629 times
As you can see from the above, there is not value for $strAggAgreeNum2 being passed in. Is this because I cannot bind that variable to the repo item via the UI? If so, is there another way to bind the variable?

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

Re: Binding multiple variables to a repository item

Post by odklizec » Fri Aug 18, 2017 5:04 pm

Hi,

There is no need to "bind" variable to repository. If the variable exists, you can enter it to the xpath manually. But are you sure the second variable is actually binded to DATA CONNECTOR? Because from the error it looks as if the variable passed empty string, which is a usual sign of not binded variable (to data connector).
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

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Binding multiple variables to a repository item

Post by krstcs » Fri Aug 18, 2017 5:15 pm

You still can bind the second variable through the test case/suite UI. As long as the repo item is used in a module, that module will show all variables in the binding options. This appears to be an issue of not binding correctly, as Pavel suggested.

Please have a look at the Ranorex Help Center/User Guide (https://www.ranorex.com/help/latest). It will guide you through correctly creating and binding variables with data sources and parameters. You should read all of it as there are many common and fundamental topics that are covered there.

If you have questions after that, then come back and ask here and we'll be glad to help!
Shortcuts usually aren't...

grobertsoncte2017
Certified Professional
Certified Professional
Posts: 4
Joined: Thu Aug 17, 2017 9:30 pm

Re: Binding multiple variables to a repository item

Post by grobertsoncte2017 » Fri Aug 18, 2017 6:37 pm

:) Well, that's a classic example of user error! Sorry to waste your time, and thank you both so very much for your help!