Forum Discussion

wilkinc's avatar
wilkinc
Occasional Contributor
9 years ago

FindAll method

I'm using TestLeft and I'd like to find all the children of a particular object which match a pattern. I can't see a way of doing this, if I use Find<> it only returns one object and if I just use object.Children, I can't filter it with a pattern.

Is there a way to do this?

  • IgorM's avatar
    IgorM
    New Contributor

    As a workaround CallMethod of IObject class might be used. Here is an example:

     

            internal List<ICheckBox> MenuItems
            { get { return NavigationTargetsContainer.CallMethod<IEnumerable<object>>("FindAll", "ClrFullClassName", "System.Windows.Controls.CheckBox", 5)
                                                                                        .Select(obj => ((IObject)obj).Cast<ICheckBox>()).ToList(); } }

      But I totally agree, the special signature of FindAll method is absolutely necessary.

  • Hello wilkinc,

     

    It seems that Testleft does not support this method yet but since you've found the container of the child objects that you are looking for, you could implement something like this.

     

    suppose you have your containter called myContainer.

     

    Class_of_the_child myChildObject = null;

     

    do{

      try{

        myChildObject = myContainer.Find<Class_of_the_child >(new YOUR_TECHNOLOGY_PATTERN()

       {

          my_search_criteria1 = search_criteria_param1,

          my_search_criteria2 = search_criteria_param2

        },50);

      }catch{

      //Do whatever error handling you wish. There is no need, the Find method returns null the the object is not found.

      }

      //Do whatever you want with the child. You may put them all into an array if you wish

    while (myChildObject != null)

     

    Best regards,

     

    Leandro de Araújo Souza

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi all,

     

    FindAll is now available in TestLeft 2.0.