Forum Discussion

HirendraSingh's avatar
HirendraSingh
Contributor
2 days ago
Solved

TestComplete name mapping to map xpath with ID

Is there any way that TestComplete will map the object automatically with ID instead of other criteria as even though the object has a unique id but most of the time TestComplete maps it automatically with other criteria like value, class, type as below.

 

I want to map with ID then with name if that is available as due to above mapping structure most of the time other button also get mapped under same type or class.

As you can see below xpath with id already there for button display data but it has mapped with value and type which causes object not found issue or performance issues.
//*[@id="ctl00_MainContent_btnShowData_input"]

  • rraghvani's avatar
    rraghvani
    1 day ago

    When generating Name Mapping, TestComplete evaluates attributes based on stability and uniqueness. Here's a stable ID having 120 characters,

    Dynamic looking ID such as "ctl00_btnShowData", TestComplete may decide that it's auto generated or may change between runs and therefore not reliable. So it avoids using it, and instead chooses alternative selectors it considers more stable.

    Read Object Identification to get a better insight.

7 Replies

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

    TestComplete engine will identify the object correctly, if the id attribute is specified for the HTML element

    Button has an id attribute named "mybutton"

     

    • HirendraSingh's avatar
      HirendraSingh
      Contributor

      That is for your case why in my case most of the time it is not capturing the id, can you check for multiple objects for which long id is there.

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

        When generating Name Mapping, TestComplete evaluates attributes based on stability and uniqueness. Here's a stable ID having 120 characters,

        Dynamic looking ID such as "ctl00_btnShowData", TestComplete may decide that it's auto generated or may change between runs and therefore not reliable. So it avoids using it, and instead chooses alternative selectors it considers more stable.

        Read Object Identification to get a better insight.

  • eykxas's avatar
    eykxas
    Regular Contributor

    Hi !

    TestComplete automatically manages the XPaths used, but you can edit manually the value in the NameMapping.

    In my own project I created my own mini framework to completely avoid the NameMapping. I think it could be more efficient if you do the same.

    • HirendraSingh's avatar
      HirendraSingh
      Contributor

      I am also editing the xpath manually most of the time that is why I am asking this question that if there is any way we can directly map ids first. Also can you give me some example how do you created the mini framework as I am having multiple projects and multiple team members to manage automation, so that will be helpful. 

    • MW_Didata's avatar
      MW_Didata
      Super Contributor

      Unrelated to OPs question but can you tell me more how you did this.
      I do use namemapping in my browser tests but it doesn't really work well.

      • eykxas's avatar
        eykxas
        Regular Contributor

        I created a mini architecture to do basically the same thing as NameMapping, but more efficiently and faster. The heart of this architecture is a collection of  "locators". Each locator.js file (ex : admin.js, homePage.js) has this structure :

        const registry = require("registry");
        
        const LOCATORS = {
          
          "ADMIN.PANEL.EMAIL": [
            "xpath",
            "//app-admin//div[contains(., 'Administration settings')]//input[@id=(//label[.='Email']/@for)]"
          ],
        
        "ADMIN.PANEL.PASSWORD": [
            "xpath",
            "//app-admin//div[contains(., 'Administration settings')]//input[@id=(//label[.='PASSWORD']/@for)]"
          ],
        
        "ADMIN.PANEL.SUBMIT": [
            "xpath",
            "//app-admin//div[contains(., 'Administration settings')]//button[contains(., 'Save')]"
          ],
        };
        
        registry.register("ADMIN", LOCATORS);
        
        module.exports = LOCATORS;



        then, a resolution engine check if the key exist (ADMIN.PANEL.EMAIL). if yes, it check its "mode" (xpath, or css, or anything we want.) and get the associated xpath, to be used in the standard functions (click, set etc...)