Page 1 of 1

How to use multiple repo itemInfo for the same method?

Posted: Thu Feb 27, 2020 9:10 pm
by oli129
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

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

Posted: Fri Feb 28, 2020 9:09 am
by odklizec
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.

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

Posted: Sat Feb 29, 2020 10:38 am
by oli129
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