Forum Discussion

maxtester's avatar
maxtester
Contributor
7 years ago

Find instead of NameMapping and refreshing of objects

Hi all,

 

I have one problem with refreshin of objects. 

In my project I don't want to use the name mapping anymore. Therefore I have to find the objects that I want to use programaticaly. So far so good. I have created a function that finds an object by propertyName and propertyValue. The next thing to to would be to wait until a property appears. Should be very simple: Make a loop and chekc if property appears.

To this function I would like to pass a path from the object tree. The problem is, that it doesn't work, because the passed object does not refresh within the function --> call by value. How canI realize this problem, and refresh the object or the object- tree within the function?

7 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Can you post the code you're using?

     

    Also... why not use NameMapping?  Honestly, seems like re-inventing the wheel.

    • maxtester's avatar
      maxtester
      Contributor

      The code that I' using.

       

      The object that I want to wait for is for example a gui- object:

       

      CheckIfApplicationStarted("AWTComponentName","Whatever",Sys.Process("java").SwingObject.AndSoOn.AndSoOn)

       

       

      function CheckIfApplicationStarted(str_PropertyName,str_PropertyValue,obj_BaseObject,int_TimeoutInSeconds){
        try{
          var obj_Result = Utils.CreateStubObject();
          var int_TimeoutForRetrys = 10
          if(int_TimeoutInSeconds != undefined){
            int_TimeoutForRetrys = int_TimeoutInSeconds
          } 
          for(var i = 0 ; i< int_TimeoutForRetrys; i++){
            obj_BaseObject.Refresh()
            obj_Result = FindObjectInBaseObject(str_PropertyName,str_PropertyValue,obj_BaseObject,2)
            if(obj_Result.Exists){
              Log.Message("Propertyvalue '" +str_PropertyValue+ "' for property in object '" +str_PropertyName+ "' found")
              return obj_Result
            }
            else{
              Log.Message("Wait for object...")
            }
            Delay(1000)
          }
          return obj_Result
        }
        catch(e){
          Log.Error("Error while check property: " +e.message)   
        } 
      }

       

       

      function FindObjectInBaseObject(str_PropertyName,str_PropertyValue,obj_BaseObject,int_Depth){
        var obj = Utils.CreateStubObject();
        var int_SearchDepth = 50
        if(int_Depth != undefined){
          int_SearchDepth = int_Depth
        } 
        try{
        if(str_PropertyName === undefined || str_PropertyValue === undefined){
          Log.Message("No property value or propertyname passed")
          return obj
        }
          var obj = obj_BaseObject.Find(str_PropertyName,str_PropertyValue,int_SearchDepth)
          if(obj.Exists){
            Log.Message("Found object: " +obj.Name)
          }
          else{
            Log.Message("No object found with the propertyname '" +str_PropertyName+ " and the property value '" +str_PropertyValue+ "'")
          }
        }
        catch(e){
          Log.Error("Error while trying to find object: " +e.Message)   
        }
        return obj
      }

       

    • maxtester's avatar
      maxtester
      Contributor

      I don't want to use NameMapping anymore. I have about 7 Projects in my ProjectSuit and the NameMapping becomes bigger and bigger. We have aklready about 2000 objects and in some cases a performance issue. It's not like re-inventig the wheel but using another method

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Have you looked into using the "WaitProperty" method?  Once you find the object and verify it exists, you can use WaitProperty method on that object to wait for a property of the object to match an indicated value.