Forum Discussion

vthomeschoolmom's avatar
vthomeschoolmom
Super Contributor
6 years ago
Solved

Using the find method(s) ...not sure what I am doing wrong

My goal is to expose the on screen objects I want exposed in script (and obfuscate the hierarchy in name mapping...). 

 

I have some code:

 

/// This script exposes objects frm the LOGIN PAGE for use in tests.
var pageRoot = Aliases.browser.pageMain;
function lblProductTitle()
{

  var item = pageRoot.Panel("window_header").Panel("header_top").Panel("product_title");
  return item;
  
}

This works fine for this simple object which is named. But I am not understanding the FIND method which I would like to use.

 

Take this example:

function txtUserName()
{
  var item = pageRoot.Panel("window_content").Panel(0).Panel("frame1").Form(0).Panel(0).Panel(0).Panel(0).Panel(0).Panel(0).Textbox("loginstart_username")
  return item;
}

I would LIKE to find the object by name but not have to traverse the DOM. 

 

function txtUserName()
{
  //var item = pageRoot.Panel("window_content").Panel(0).Panel("frame1").Form(0).Panel(0).Panel(0).Panel(0).Panel(0).Panel(0).Textbox("loginstart_username")
  var item = pageRoot.Find("Name", "loginstart_username", 9999, true);
  return item;
}

But the item is returning an empty object. Nothing is found. I am clearly not understanding this method... Can anyone explain what I am misunderstanding? THANKS!

 

  • The "Name" property is not what you think it is.  It's actually, if you look at it in the Object Spy the full name of "TextBox('loginstart_username')".  It's not a recommended property to find for.

     

    What you probably want to do, if you're going to use "Find", is to actually pass in arrays of properties and values.  So, in your example, you would want something like

     

    pageRoot.Find(['ObjectType', 'ObjectIdentifier'],['TextBox', 'loginstart_username'], 9999, true)

     

    Now... that all said....  what you're trying to do, as I see it, is remove all those "Panel.Panel.Panel" references...and you say that you're doing so to obfuscate NameMapping...

     

    ...you probably aren't using the Aliases right in NameMapping then.


    Basically, if I have an object that NameMapping might map like

     

    NameMapping.Sys.Browser.page.panel.panel.panel.table.cell.panel.loginTextBox

     

    The Alias, when you first map it MIGHT look like this.

     

    Aliases.Browser.page.panel.panel.panel.table.cell.panel.loginTextBox

     

    Well, if you edit your Alias, you can drag loginTextBox to be a direct chiild of the page and then "Exclude" all the intermediary stuff.   So, your NameMapping.Sys will still look the same (which is OK... and necessary) but your Alias will look like

     

    Aliases.Browser.page.loginTextBox.

     

    Read up on NameMapping at https://support.smartbear.com/testcomplete/docs/testing-with/object-identification/name-mapping/about.html#aliases-and-mapped-objects

     

    While Find WILL work....  you end up with an overhead that is unnecessary.  Find, actually, consumes more time and processor time than if you're using the NameMapping repository for object identification.  And, with NameMapping, there's less code to maintain and keep track of.  Check it out.

2 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    The "Name" property is not what you think it is.  It's actually, if you look at it in the Object Spy the full name of "TextBox('loginstart_username')".  It's not a recommended property to find for.

     

    What you probably want to do, if you're going to use "Find", is to actually pass in arrays of properties and values.  So, in your example, you would want something like

     

    pageRoot.Find(['ObjectType', 'ObjectIdentifier'],['TextBox', 'loginstart_username'], 9999, true)

     

    Now... that all said....  what you're trying to do, as I see it, is remove all those "Panel.Panel.Panel" references...and you say that you're doing so to obfuscate NameMapping...

     

    ...you probably aren't using the Aliases right in NameMapping then.


    Basically, if I have an object that NameMapping might map like

     

    NameMapping.Sys.Browser.page.panel.panel.panel.table.cell.panel.loginTextBox

     

    The Alias, when you first map it MIGHT look like this.

     

    Aliases.Browser.page.panel.panel.panel.table.cell.panel.loginTextBox

     

    Well, if you edit your Alias, you can drag loginTextBox to be a direct chiild of the page and then "Exclude" all the intermediary stuff.   So, your NameMapping.Sys will still look the same (which is OK... and necessary) but your Alias will look like

     

    Aliases.Browser.page.loginTextBox.

     

    Read up on NameMapping at https://support.smartbear.com/testcomplete/docs/testing-with/object-identification/name-mapping/about.html#aliases-and-mapped-objects

     

    While Find WILL work....  you end up with an overhead that is unnecessary.  Find, actually, consumes more time and processor time than if you're using the NameMapping repository for object identification.  And, with NameMapping, there's less code to maintain and keep track of.  Check it out.

    • vthomeschoolmom's avatar
      vthomeschoolmom
      Super Contributor

      Thanks for the info! I was aware of the alias movement that I could do. I am doing a PoC of both approaches to show the good, the bad and the ugly. I will add performance to the ugly! Thanks again.