How to use multiple repo itemInfo for the same method?

Best practices, code snippets for common functionality, examples, and guidelines.
oli129
Posts: 7
Joined: Wed Nov 06, 2019 1:36 pm

How to use multiple repo itemInfo for the same method?

Post by oli129 » Thu Feb 27, 2020 9:10 pm

Dear All!

I have a method, where I specify a repoitemInfo and a string, so when a popup shows up it reads the repoitemInfo if it exists and then it validates its text attribute.

However, I have forms with different control names but with the same textfield, so my repo looks like the following:

repo.popups.message.textFieldInfo
repo.popups.question.textFieldInfo

I would like to validate the string on their text attributes, however I am unsure, which of the popups will show up in a given test case.

What I load into the repoitemInfo is the repo.popups.message or .question. So the main popup window.

Is there a way to use a variable on this repo path, so that it would dynamically switch between the two itemInfos?

Code: Select all

public static void PopupCheck(repoItemInfo popupMsg, string strVal)
{
Validate.AttributeEquals(repo.popups.message.textFieldInfo, “Text”, strVal);
}
This code only checks the textfield on the message popup but if the question popup shows up, it would simply fail.

So, is there a way to use a dynamic parameter for the Validate.AttributeEquals(variable, “Text”, strVal)?

Something like:
repo.popups.variable.textFieldInfo

I tried to get the full path of the popupMsg repoitemInfo, like this: popupMsg.FullName to get this: repo.popups.message, and then add the info part at the end, but it won’t convert string to textinfo, obviously.

Thank you very much for any advice or help!

Best Regards,
Oliver

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

Re: How to use multiple repo itemInfo for the same method?

Post by odklizec » Fri Feb 28, 2020 9:09 am

Hi,

I think the only (and best) way to achieve what you want, is to define another repoiteminfo parameter in your method...

Code: Select all

public static void PopupCheck(repoItemInfo popupMsg, repoItemInfo textField,  string strVal)
{
    Validate.AttributeEquals(textField, “Text”, strVal);
}
There is no way to use variable while referencing repo element in code, like this... "repo.popups.variable.textFieldInfo

The only other option would be to use directly xpath in code (using Find method), where you can define a variable. Something like this:

Code: Select all

var elementToValidate = repoElementLBL.CreateAdapter<Ranorex.Unknown>(false).FindSingle(".//tag[@data-property-name='"+varOfYourChoice+"']");
Validate.AttributeEquals(elementToValidate, “Text”, strVal);
But I still prefer to use repository elements, referenced via method parameters. It's simply best and cleanest way. I don't like hardcoded xpaths or repo elements in my solutions. This is what the repository and repoItemInfo parameters are for.
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

oli129
Posts: 7
Joined: Wed Nov 06, 2019 1:36 pm

Re: How to use multiple repo itemInfo for the same method?

Post by oli129 » Sat Feb 29, 2020 10:38 am

Hi!

Thank you very much for the valuable information and for the quick help! Greatly appreciated! I am just going to stick to extending the method with a plus repoiteminfo parameter, that way it stays clean!

Regards,
Oliver