Forum Discussion

iamraj09's avatar
iamraj09
Contributor
10 years ago
Solved

Can we replace whole object chain with single word?

Hello Everyone,   Right now I am working on performance test cases for a huge task which includes lot of objects, if I take the object chain for each and every object the script is becoming very me...
  • joe_2's avatar
    joe_2
    10 years ago

    Well, I did it again... tried to tab indent something and closed the comment window instead.  I really hate this interface sometimes.

    Anyway, If you get two responses from me, that's why...

     

    So, what I saw looking at your example is that you were trying to Findchild an object named 

    WPFObject("Button", "New project", 1) this is the NAME of the object

     

    So your findchild line needs to be 

    Sys.Process("MyProcess").FindChild("Name", "WPFObject(""Button"", ""New project"", 1)",10).ClickButton();

    (understanding that the double quotes "" are the VBScript way of including quotes in a string value... The blue text is all one value.  If your scripting language does it another way then you'd need to change that... maybe to something like (.\"Button.\", where the .\ means the next character is part of the value you're specifying, and not meant to close the quote) 

     

    Or, you could shorten it a bit by using wildcards and just have

    Sys.Process("MyProcess").FindChild("Name", "*New project*", 10).ClickButton();

    which also does away with having to include the double quotes. 

     

    I usually use 'Name', 'ButtonText', 'Caption', or 'Value' as the property to search.You can see a complete list of available properties for a given object by looking at it in the object browser.  Pick any property that will positively identify the object you want out of all the other objects, and use that.  But keep in mind that some things, like an object's 'Handle' may seem unique, but they change every time the object is created.  Other properties like 'BackColor' are useless because they aren't unique to the desired object.

  • finae's avatar
    finae
    9 years ago

    Another way to find the object is to create an array of properties and values that identify it specifically.

    ex:

     

     

    function GetObj(parent,propName,propValue,layer)
         set GetObj=parent.Findchild(propName,propValue,layer)
    end function
    
    sub test
       propName=Array("NativeCLRobject.Name","Index")
       propValue=Array("TheNativeCLRObj.NameValue",idx)
    
       set okButton=GetObj(Sys.process("myprocess").findchild("nativeClrobject.name","thisparent",2),propName,propValue,5)
    
      okButton.ClickButton
    end sub

    then just use the GetObj function withouth have to type so much

     

    better yet you can create a function to return the process

     

     

    private function App
       set app=sys.process("myProcess")
    end function
    function MainWindow
       set MainWndow=  App.FindChild("nativeclrobject.name","MainWindow",3)
    end function
    function GetObj(parent,propName,propValue,layer)
         if parent is null then
               set GetObj=null
         else
              set GetObj=parent.Findchild(propName,propValue,layer)
        end if
    end function
    
    sub Test
       set OKButton=GetObj(GetObj(MainWindow,"nativeclrobject.name","thisparent",parentlayer),propName,propvalue,layerValue)
      if Not isnull(OKButton) and OKButton.exists then
             okbutton.clickbutton
      end if
    end sub

     

     

    also dont forget that you can get the parent window of the object you want to interact with by using the GetObj to return the parent window, but care on this as it does not check if it finds teh object or not and assume.

     

    This is just a quick edit but i think it should work, the last if statement might be redundent but if the GetObj did return an object that does not exist then its not null

     

  • Colin_McCrae's avatar
    Colin_McCrae
    9 years ago

    Why leave all the unwanted parts in the Alias map?

     

    I map objects, but either don't automatically create alias objects, or delete the alias version. Then just alias map the parts you're interested in. Makes it much neater.

     

    So for example:

     

    Object map:

     

    Calc

    > Calc Container

    >> Calc Panel

    >>> Calc Button Cluster

    >>>> Calc Button 3

     

    In the Alias map, I would only have:

     

    Calc

    > Calc Button 3

     

    All the intermediate parts, which are required but I'm not interested in, would be left out.

     

    Keeps the Alias map/tree much neater and makes your code complete for mapped Alias object much more concise. Think of the object map as the novel, and the Alias map as an abbreviated summary of it. You can also use multiple copies of single objects to create the illusion of separation in the Alias map. I do this a lot with web pages, tabs within pages etc. Give the multiple Alias copies different names and it makes the Alias map a much closer match for how you see the application in terms of the parts you actually use during the test.

     

    I tend to only map object to a fairly high level. Then use helper functions to locate the more detailed objects on the fly during run time. I can see why people like a simple function that searches for an ID all the way down from the sys object. But this method is not without it's drawbacks. In a complex app, with a lot of components, searching the entire object tree for an object many layers down can be very slow. Hit exactly this problem with a delphi application the other day. A simple find on the top the level sys object worked, but was very slow. Refined how it searches to make it a little smarter, and it's much faster. It's much like SQL. Simple, bad, SQL will work, but slowly. A smarter query will be way faster ....