Get itemInfos of list of tags?

Ask general questions here.
mrt
Posts: 88
Joined: Mon Mar 16, 2020 11:31 am

Get itemInfos of list of tags?

Post by mrt » Wed Mar 31, 2021 9:39 am

Dear all,

I want to check a list of icons.

The repository item gets a list of ITag elements with some Path like:

Code: Select all

.//i[@class~'material-icons' and @innertext~'circle']
2021-03-31 10_42_02-Window.png
2021-03-31 10_42_02-Window.png (25.01 KiB) Viewed 107 times
My User Code which works is:

Code: Select all

public void ValidateMaterialIcons(RepoItemInfo iTagInfo)
{
    IList<ITag> circleIconList = itagInfo.CreateAdapters<ITag>();
        	
    // check all icons if they are green (=check_circle symbol)
    foreach (ITag circleIcon in circleIconList)
    {
        Report.Log(ReportLevel.Info, "Validation", "Validate material icon", itagInfo);
        Validate.AreEqual(circleIcon.InnerText,"check_circle");
    }
}
So I create a list of adapters out of the RepoItemInfo and loop through all adapters then.
But I am not satisfied with the report output of the validation.

Instead of checking some InnerText I want to check if the Class Attribute contains a certain value 'color-green'.
This led me to Validate.AttributeContains(), but this only accepts a RepoItemInfo and not the Element (Adapter) itself.
As far as I know, it is not possible to get the RepoItemInfo from an Adapter (only the other way round).

How can I get a list of all itemInfos, so I can loop through them and use Validate.AttributeContains?

Thank you, BR

User avatar
Mike K
Certified Professional
Certified Professional
Posts: 28
Joined: Wed Jun 28, 2017 5:58 pm

Re: Get itemInfos of list of tags?

Post by Mike K » Wed Mar 31, 2021 12:10 pm

Hi,

There is not an option to convert Adapter to RepoItemInfo. It only goes in one direction. In this case where you create a collection of Adapters try using a different approach to Validation where you write the Try/Catch for Pass/Failure on the adapter like in the example below.

try{
if (MyAdapter.Element.GetAttributeValueText("InnerText").Equals("Success!"))
{
Report.Success("All good, it works!");
}
else
{
Report.Failure("Boo! It didn't work :(");
}
catch(Exception ex){
Report.Error("Something else went wrong!");
}

Hope this helps!

mrt
Posts: 88
Joined: Mon Mar 16, 2020 11:31 am

Re: Get itemInfos of list of tags?

Post by mrt » Wed Mar 31, 2021 1:21 pm

Thanks for your reply.

I will use your manual solution until I find something better. :)

btw: you are missing a closing bracket before the catch-block, but I got the message. ;)

dhale
Posts: 49
Joined: Thu Feb 27, 2014 7:33 pm

Re: Get itemInfos of list of tags?

Post by dhale » Wed Mar 31, 2021 4:02 pm

https://www.ranorex.com/Documentation/R ... ains_3.htm
I see several methods that take an element for Validate.AttributeContains