Forum Discussion

kaiiii's avatar
kaiiii
Regular Contributor
5 years ago

store all name mapping objects in a page and then use in scripts.

I want to store all webelement objects in a page and then want to use.

like

 

Set a = Aliases..........element path in object tree..............

Set b = Aliases..........element path in object tree..............

Set c = Aliases..........element path in object tree..............

Set d = Aliases..........element path in object tree..............

 

how can I do the same. I want to do this because it will help to call just object anywhere in scripts so there is not need to write full mappedpath in the code when a single element occur on different different journies.

Or is there any better way. Kindly share

 

6 Replies

  • Mr_Bro's avatar
    Mr_Bro
    Champion Level 0

    Hi kaiiii ,

    please save the object names in seperate Unit file and use the required objecs werevere required by refering to that unit.

    please find the below exampe:

    unit1:-

    unit2:-

    • kaiiii's avatar
      kaiiii
      Regular Contributor

      Hi Mr_Bro ,

      Thanks for reply.

      I had done this before . it's not working.

      we can call unit in one to another but what i am facing here

      we are creating only objects not any function and not able to to call that object in another unit

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Note, BTW, that you can use Aliases to shorten your object names however you want to.

         

        The following object:

         

        NameMapping.Sys.browser.myPage.panel0.panel0.panel1.panel0.table0.cell1

         

        will, by default, create an Alias like

         

        Aliases.browser.myPage.panel0.panel0.panel1.panel0.table0.cell1

         

        However, those other panels aren't needed for the actual object you want.  So, you can, in your NameMapping editor, highlight those panels, right click, and select "Exclude Items" and you'll end up with an alias like

         

        Aliases.browser.myPage.table0.cell1

         

        And this is still the same object, found properly.  Aliases are, as the name implies, "renaming" of what is mapped out in NameMapping.  The engine reads the Alias and checks where it is found in the NameMapping tree and then uses that tree to find the object.

         

        You can shorten object names as much as you want.  TECHNICALLY speaking, I could shorten that Alias all the way down to Aliases.cell1 and it will still work so long as the NameMapping tree remains unchanged.

         

        So... rather than trying to assign all the objects as you are doing, a better methodology would be to spend time formatting your Aliases to be more code-friendly.

  • Wamboo's avatar
    Wamboo
    Community Hero

    Hi,


    Save the reference to NameMapping obj in another file -> use it in your unit -> use codeCompletion.


    This is the simplest solution to this.