Forum Discussion

Lagencie's avatar
Lagencie
Frequent Contributor
8 years ago

Name Mapping on CSS / XPath Selector Basis

Hello Community,

 

I am kind of new to Testcomplete and I am trying to get a small test to work with our AngularJS website.

 

Problem here is, that all the Elements come from outside, so we are not able to add specific classnames / ids or whatever. The only thing how we can keep them unique is by CSS Selector as we get a List of Elements which we could link to Name Mapping Objects for example Textfield1 = .../li[0]... --- Textfield2= .../li[1].... to take the XPATH as an example ignoring the whole path.

 

Is there a way to do this without scripting, to give the name mapping a variable CSSSelector / XPath to identify the item during runtime

 

I hope my question is clear - if not just ask and I try to explain further :)

5 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    AngularJS web apps should be easily testable via TestComplete.  You shouldn't have to do anything fancy.

    When you use the Object Spy to examine one of your elements, do you have something that indicates Object Type and/or ObjectIdentifier?  Also, if you expand the property list to include the Advanced list (should be a link at the top), there are probably a lot of other identifying factors like caption, text, innerText, contentText, etc., that you can use as identifying factors as well.  

     

    Throw up a screenshot of one of your components and the Object Spy properties and we should be able to help with something.

    • AlexKaras's avatar
      AlexKaras
      Champion Level 3

      tristaanogre:
      The problem (as described by @Lagencie and according to what I saw once or twice) is that Angular-based pages do not provide web elements with any id/stable class/etc.

      The page I saw (and that I believe was Angular-based) was an absolute horror: all elements were named in the Object Browser by indexes only.

       

      Lagencie:

      Your best option is to try your best and provide stable identifiers (id/class name/whatever else) at least to some subset of core elements on the page to be able to use these element as a search roots.

      I believe you understand it clearly and will let everyone know that even if it is possible to create NameMapping using XPath (or implement a set of 'locator' functions), this approach will be highly unstable and expensive in support.

      The reason is that XPath like 'second text field within first panel within first div' :

      a) Will break immediately when the page design changes;

      b) Is absolutely not descriptive. As soon as the page design changes and XPath breaks, it is near to impossible to say what exact object it was expected to work with. In almost all cases you will have to get a previous working copy of the page, find the target element, find this element on the new version of the page and correct XPath to match new page design.

       

      Summarizing: While technically TestComplete has no problems to work with such web page(s), you should triple-consider if identifiers can be added to page elements and whether it is reasonable to start automation of such page(s) at all in case identifiers cannot be provided.

      Note: obviously this is not a problem of TestComplete, one will have absolutely the same reliability and support prolems with any other automation tool.