Ask a Question

Anyone have some really good material for name mapping?

SOLVED
jthompson1
Contributor

Anyone have some really good material for name mapping?

I'm wondering if someone can relate and has gone through what im about to explain but they found a really good write up that educated them about name mapping. I've already gone over the material provided by default from testcomplete (object tree model...breadth vs depth, naming aliases etc... ) and I still struggle with name mapping. It's frustrating because I am spending more time trying to make the **bleep** software recognize objects on the webpage more than anything. I'll record and do playback and it just loses it's **bleep** mind saying it cannot find the object, and i'm sometimes spending a whole day on one test case trying to find some compromise where I can complete the test automation because testcomplete cannot recognize objects it previously added to name mapping. It's very frustrating and I just wish I could use the software the way it's advertised. I sometimes just ignore the built in name mapping all together and resort to using XPath and Jscript to find objects on a screen... which feels more like a compromise because I'd much rather use the built in testcomplete name mapping to make life easier.  

7 REPLIES 7
vinniew
Staff

The name mapping guides are in itself quite useful as they show you how to do things like add items, maintain items.

 

I see you mentioning using xpath solves your issue, You know you can use xpath selectors in the name mapping? 

 

To do this enable xpath and css for web objects. 

 

In an existing project 

 

Click on tools On the Open Applications > Web Testing > General page of the existing project’s Properties page.

 

Or open a new project all together and enable it. 

 

Going forward as you record new items, in the the namemapping it will reference the same alias but instead of using object properties it will use xpath and css selectors 

 

You can remove or add in what ever selectors you want, and as many as you want. 

 

That way testcomplete will try to find what ever selectors you reference in the name mapping in the order you list them. 

This is a useful alternative method for web apps. 

 

This also allows you to scale your web tests using Smartbears Device Cloud, (simply using that web test against a local browser,  connects to the device cloud CBT with thousands of real browser configurations on multiple platforms like IOS,Android, MAC and Windows and run them on those configuration) 

See 

https://support.smartbear.com/testcomplete/docs/app-testing/web/cross-platform/index.html

 

If you dont want to use Device cloud you can still enable that mode for scaling down the line in the future or even leveraging using Xpath and Css selectors  

See On the https://support.smartbear.com/testcomplete/docs/testing-with/object-identification/name-mapping/xpat...

 

 

is it risky to change to xpath and css with existing project? There are some elements that actually do work with my current name mapping. 

I wouldnt say its risky. the old mapping will still exist.

and it can be turned on and off(Switched), and as long as the old criteria works and is in the name map then thats ok. 

Essentially by enabling your telling TC what to reference in the namemap as you record. So only going forward and creating new tests are you using Xpath nd CSS in the name map.

 

As for maintaining both in a single project, it is doable but I can also see how testers may prefer just the one approach per project.

perhaps open a separate project and see how it works for you and this app under test.

It might help your decision to determine how best to move forward  

 

 

 

Thanks ill run another project with just xpath and css and see how it works.

Hi,

 

Most of modern web applications are awful from automation point of view because they do not bother about testability and do not provide unique and stable identifiers for web objects. With this in mind, it is highly recommended not to rely on default NameMapping algorithms during recording, but manually NameMap/Alias all web elements that are required for your test before recording and only then do recording.

Preliminary NameMapping and general investigation of the tested application in the Object Browser should give you an understanding what properties of web elements can be used for mapping and what cannot. Whether these properties stable and unique so they can be used as they are or, because of their dynamic/not stable nature you should combine different approaches to get stable mapping. For example, you may consider to map just a container object and then use, say, .FindChild() calls to find required web element. Or use .FindAllChildren() and iterate through the obtained resultset to get the element you are looking for. Consider 'Required Children' functionality of NameMapping - sometimes it is quite handy and useful. Do not overuse Extended Find property of NameMapping but use it only when necessary. Do not forget that NameMapping allows complex conditional search criteria and regular expressions - really helps sometimes.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

As @AlexKaras  said, apps developper are more and more miseducated about maintenability and they rarely do it the right thing (add an unique id property with understandable value which doesn't change on time/techno but which is related only on a functional thing). Rather that, id are autogenerated ones and we can't rely on.

 

So how to manage that ? The Alex's way is a good one but if you dare you can even go farther and use only find/findChild approach. I use this method since a long time and no application resist to me 😉

The important thing is to explain what is the cost of missing correct id (test, documentation, refactoring, reversibility, onboarding, ..) thus driving the managers to force apps developpers to add it (money has always the last word).

 

The scripting approach is oftenly seen as a costly and less sustainable. I don't think so if you do good scripting job. Simply don't make the same errors than apps developpers 😁

 

A sample of a find approach based on smart developpers  who added unique id:

(qa.XXX methods are from my framework, qa.system.findIt is based upon findChild and qa.web.findIt is based upon XPath). This extract is to manage an insurance subscription,here the Customer Activity screen.

 

     saisieActivite:function(Activite) {
        let trace = this.methodStart("saisieActivite(" + Activite + " ) - Saisie du formulaire Activité");
        try { 
          let container = qa.system.findIt(qa.system.currentBrowser.currentPage, "ObjectIdentifier", 'contactInformationform', qa.system.time.longer, 15, true, true);
          let recherche = Activite.split(";");
          let fields;
          let dummy;
          for (let i = 0; i < recherche.length; i++) {
            if (recherche[i] != "") {
              fields = recherche[i].split("=");
              switch (fields[0]) {
                case "surname" :
                case "contractorFirstName" :
                case "birthDate" :
                case "homeNumber" :
                case "zipCode" :
                  dummy = qa.system.findIt(container, "ObjectIdentifier", fields[0], 0, 10, true, true);
                  this.input(dummy, fields[1], "1");
                  break;
                case "streetName" :
                  dummy = qa.system.findIt(container, ["ObjectIdentifier", "ObjectType"], ['streetName','TextBox'], qa.system.time.second, 10); 
                  this.input(dummy, fields[1]);
                  break;
                case "city" :
                  // Sélection de ville sur CP, attendre le remplissage de la liste des villes
                  aqUtils.Delay(qa.system.time.seconds);
                  // Dans le cas où on a plusieurs villes correspondantes et que la sélection n'est pas automatique
                  let select = qa.web.findIt('name', "city", "SELECT");                  
                  if (aqString.Compare(select[0].wText,"--Choisissez",true)==0){
                    qa.web.selectValueInHTMLCombo(fields[0], select[0].wItem(1));
                  }
                  break;
                case "activity" :
                case "steed" :
                case "title" :
                case "amddressType" :
                  qa.web.selectValueInHTMLCombo(fields[0], fields[1]);
                  break;
                default :
                  throw Error("Saisie activité, champ '" + fields[0] + "' non géré/incorrect !");         
              }
            }
          }
          this.etapeSuivante();
        } 
        catch(e) {
          errorString = qa.system.logExceptionByLevel(e, trace);
        }
        finally {
          return this.methodStop(true);
        }
      },

 

And thus, testing this peculiar page is a call of saisieActivite(TestData), like saisieActivite("title=M.;surname=Bob;birthDate=30/12/1971;zipCode=75000;city=Paris")

 

Un sourire et ça repart

Ok I've played around after enabling the Xpath and CSS option for half a day here, and it seems to be a game changer. I am having a much easier time with name mapping, and i ran other tests that were previously running ok and it does not appear to have damaged those tests built on the older settings. This is so far working out really good for me. Thank you.

cancel
Showing results for 
Search instead for 
Did you mean: