Forum Discussion

pse's avatar
pse
Occasional Contributor
6 months ago
Solved

Get mapped object based on Alias string?

Hi,

I am trying to create a python function that allows me to find a mapped object based on the MappedName string. Here is my function currently:

def wait_for_mapping_object_to_exist(mapping):
  attempt = 1
  while attempt <= retry:
    try:
      reference_object = None
      reference_object = Aliases.Find("MappedName", mapping, str(mapping).count(".") + 2)
      if not reference_object.Exists:
        raise Exception("Object not detected.")
      return reference_object
    except Exception as e:
      Log.Message(str(e))
      delay_with_retries(1000, "Unable to find object. Waiting for timeout.")
      attempt = attempt + 1
  return None

While doing a "Find" search works well, simply setting a variable to a NameMapping object seems to be the fastest way normally. for example:

reference_object = Aliases.javaw.MainWindow

However, I would like to perform this given the string name of the Alias. That would allow me to pass the alias as a parameter without throwing an error that the parameter does not exist. Ideally, something that looks like this:

def get_mapping_object(alias_str):
  # example: alias_str is equal to a string of "Aliases.javaw.MainWindow"
  reference_object = someLibrary.getMappedObjectFromString(alias_str)
  return reference_object

Is there a built in library for doing this? Would it potentially save me time over a "Find" search? Thanks

 

  • I can't seem to post an image because "Too Many Uploaded Images. You have reached your upload limit of 1,000 images." !

    For example, I have the following hierarchy in my Mapped Objects -

    NameMapping.Sys.browser.pageSmartbearSwagShop.panelPagecontainer.panelShopifySectionFeaturedColle.panelFeaturedItems.panelGoBearGetGoingHoodie.linkGoBearGetGoingHoodie

    and my Aliases hierarchy looks like this,

    Aliases.pageSmartbearSwagShop.linkGoBearGetGoingHoodie

    Use the WaitAliasChild method to delay the test execution until the object specified by its alias (linkGoBearGetGoingHoodie) appears in the system or until the specified time limit is reached

    function main()
    {
        Aliases.pageSmartbearSwagShop.WaitAliasChild("linkGoBearGetGoingHoodie", 30000);    
    }

     

5 Replies

  • pse's avatar
    pse
    Occasional Contributor

    Ok great. One more thing i'm not understanding. Say we have an object "Aliases.javaw.MainWindow.Panel.CommandMenuBar". Would the function work like this?

    Aliases.javaw.WaitAliasChild("MainWindow.Panel.CommandMenuBar", 1000)

    This seems to not be working. I may be misunderstanding the documentation. Thanks

    • rraghvani's avatar
      rraghvani
      Icon for Champion Level 3 rankChampion Level 3

      I can't seem to post an image because "Too Many Uploaded Images. You have reached your upload limit of 1,000 images." !

      For example, I have the following hierarchy in my Mapped Objects -

      NameMapping.Sys.browser.pageSmartbearSwagShop.panelPagecontainer.panelShopifySectionFeaturedColle.panelFeaturedItems.panelGoBearGetGoingHoodie.linkGoBearGetGoingHoodie

      and my Aliases hierarchy looks like this,

      Aliases.pageSmartbearSwagShop.linkGoBearGetGoingHoodie

      Use the WaitAliasChild method to delay the test execution until the object specified by its alias (linkGoBearGetGoingHoodie) appears in the system or until the specified time limit is reached

      function main()
      {
          Aliases.pageSmartbearSwagShop.WaitAliasChild("linkGoBearGetGoingHoodie", 30000);    
      }

       

      • pse's avatar
        pse
        Occasional Contributor

        I see. What would be the equivalent for WaitNamedChild? That may be simpler. I need to be able to traverse further than the immediate child layer below an object