Forum Discussion

googleid_118035's avatar
googleid_118035
Contributor
11 years ago

What is the best approach for scripting with name mapping or without name mapping?

Hi,



I just whant to clarify that I am using system full path which mapped to an object and not using name mapping option at all.



Some time my scripts get fail due to object identification issue.

Does its a best appraoch or need to use the name mapping in order to create scripts, which not falling.




..............

Thanks

Dev

  • I set-up a script that acts as an "object repository" and define all the objects as functions, like this:

    var testBrowserType = "iexplore";

    function mpPortal_Link_FAQs(){return WaitForAndReturnTheObject(Sys.Browser(testBrowserType).Page("*"), new Array("ObjectType", "innerText"), new Array("*Link*", "*FAQs*"), 99);}


    //wait 5 seconds if page and object load time doesn't sync properly with page.Wait()

    var objWaitTime = 5;

    function WaitForAndReturnTheObject(page, attribs, vals, depth, waitTime)

    {

    var object;

    var theWait = 0;

    if(waitTime != null)

      theWait = waitTime;

    else

      theWait = objWaitTime;

    for(var i = 0; i <= theWait; i++)

    {

    object = page.Find(attribs, vals, depth); 

    if(object.Exists)

    {

      return object;

    }

    else

      if(theWait > 0) Delay(1000); 

    }//end for



    try

    {

    Log.Error("Object not found! " + attribs[0] + ": " + vals[0]);// + ", " + attribs[1] + ": " + vals[1]);

    }

    catch(e){}



    return object;

    }  //end WaitForAndReturnPageObject(page, attribs, vals)


  • amathews's avatar
    amathews
    Occasional Contributor
    I set-up a script that acts as an "object repository" and define all the objects as functions, like this:

    var testBrowserType = "iexplore";

    function mpPortal_Link_FAQs(){return WaitForAndReturnTheObject(Sys.Browser(testBrowserType).Page("*"), new Array("ObjectType", "innerText"), new Array("*Link*", "*FAQs*"), 99);}


    //wait 5 seconds if page and object load time doesn't sync properly with page.Wait()

    var objWaitTime = 5;

    function WaitForAndReturnTheObject(page, attribs, vals, depth, waitTime)

    {

    var object;

    var theWait = 0;

    if(waitTime != null)

      theWait = waitTime;

    else

      theWait = objWaitTime;

    for(var i = 0; i <= theWait; i++)

    {

    object = page.Find(attribs, vals, depth); 

    if(object.Exists)

    {

      return object;

    }

    else

      if(theWait > 0) Delay(1000); 

    }//end for



    try

    {

    Log.Error("Object not found! " + attribs[0] + ": " + vals[0]);// + ", " + attribs[1] + ": " + vals[1]);

    }

    catch(e){}



    return object;

    }  //end WaitForAndReturnPageObject(page, attribs, vals)


  • This has been a great discussion on name mapping experiences, practices and pitfalls. It would be useful to more know about the types of applications being tested and the most reliable way to approach each type. Our applications under test use Java SWT and this presents a number of challenges since map able objects rarely contain useful properties for creating aliases. As an example, if there are 10 text boxes on a screen, they will be given the names SWTObject("Text", "", 1) ... SWTObject("Text", "", 10) and it's up to the user to assign the aliases. Then, if on the next application release another text box is inserted between ("Text", "", 1) and ("Text", "", 2), all text boxes from #2 onward will have aliases corresponding to the wrong text box. This is true for most SWT editable controls and it limits the use of TestComplete's aliases.



    As a workaround, a mapping system has been built that first attempts to associate controls with the nearest horizontal or vertical label. The best matching information is saved in a custom application map stored as XML and this map used when running the test scripts. It's not always possible to find a valid label/control match, so a variety of other methods are also be used. In cases where controls such as text boxes are arranged as grids, row labels and column labels are used to locate the text box at the screen location intersection. TextObjects have been very useful for identifying dynamically generated objects such as composites within expand bars. In rare cases, the Java data field has been used along with several other mapping functions.



    Like many other posts, in some cases we've moved to using one of the variants of the find method to dynamically reference objects. It has proved to be the most stable. Also, each situation is different, so the solution with the best reliability and performance is used. What works well in one application may not be suitable in the next.



    So, in our case, the aliases provided in TestComplete were not as reliable as desired and a custom mapping system was developed. I'm definitely interested in hearing comments from any Java SWT testers out there.

  • That's the core of the problem, in Java SWT the identifying information the developer provides for most editable controls is not availble via the Java Runtime and TestComplete. What is available, is the type of object and an index.
  • amathews's avatar
    amathews
    Occasional Contributor


    thePanel = parentPanel.FindAllChildren(new Array("ObjectType", "innerText"), new Array("Panel", "*" + textBoxIdentifier + "*"), 9999);

      thePanel = new VBArray(thePanel).toArray();

      foundRightPanel = false;

    //Text directly preceding textbox with ONLY spaces and no text

    //before it in the same panel

      re = new RegExp("^\\s*" + textBoxIdentifier);

      len = thePanel.length;

      panel = null;

      for(var i = 0; i < len && !foundRightPanel; i++)

      {

      if(aqObject.IsSupported(thePanel[thePanel.length - i - 1], "innerText"))

      if(re.test(thePanel[thePanel.length - i - 1].innerText))

        {

         panel = thePanel[thePanel.length - i - 1];

         foundRightPanel = true;

        }

      }



      theTextbox = thePanel.Find("ObjectType", "TextBox", 9999);


  • leandropoblet's avatar
    leandropoblet
    Frequent Contributor
    I'm currently testing a WPF based application.



    I use a combination of both methods: whenever I can use NameMappings I do, whenever I can't I use a function I made which receives the parent object (usually mapped name), property/ies and value/s and it handles zero, one and many objects found.



    So I use as much as I can the NameMappings.



    Cheers,

    Leandro