Forum Discussion

RegasQA's avatar
RegasQA
New Contributor
5 years ago

CSS selector into namemapping

Hello,

I have not been busy with Testcomplete for a long time and I mainly use Keyword tests because I am not a developer. I cannot write code. Now the developers have made an adjustment so that all my tests suddenly fail. This is because I did not set up my namemapping sufficiently uniquely. My colleagues mainly use the CSS selector to give elements a unique ID. They also want me to use it. To what extent is it possible to include the CSS selector in my name mapping? And if that is not possible, what should the developers do so that I can make elements unique enough?

  • Hi,

     

    I am not sure that CSS selector can be used for Namemepping. (Though you can use the value of the 'class' property as one of the identification criterion for Namemapping.)

    The best thing that your developers can do to improve testability of their application is to introduce stable and unique IDs for every UI element that automated test needs to interact with.

     

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    I am not sure that CSS selector can be used for Namemepping. (Though you can use the value of the 'class' property as one of the identification criterion for Namemapping.)

    The best thing that your developers can do to improve testability of their application is to introduce stable and unique IDs for every UI element that automated test needs to interact with.

     

    • sonya_m's avatar
      sonya_m
      SmartBear Alumni (Retired)

      Thanks Alex! 

       

      RegasQA does this approach work for you? Please let us know :smileyhappy:

  • Tris's avatar
    Tris
    Contributor

    Marked solution is incorrect.

     

    This is a recent feature added in TestComplete v14.50 as I was investigating the use of this. There is a full guide on this which can be found on the support site below.

     

    https://support.smartbear.com/testcomplete/docs/testing-with/object-identification/name-mapping/xpath-expressions-and-css-selectors.html 

     

    Note - I have tried to implement mapping with CSS selectors alongside my existing name mapping which uses attributes and have had inconsistent mapping results.

     

    For example I map a new object, which on the UI is within an existing mapped object and TestComplete maps it correctly as I would expect within the existing object at alias level, but not anywhere close to where I would expect at the mapped object level. 

     

    I contacted SmartBear about this, their suggestion? Delete all my existing mapping and start again if I want to work with CSS locators, hardly a solution, so just be aware of this if you do decide to go down the CSS locator route.

     

    I would suggest if the above is something you would like to do, then up vote the feature request below which would allow us to transition our existing mappings over, rather than deleting and mapping all over again.

     

    https://community.smartbear.com/t5/TestComplete-Feature-Requests/Request-adding-CSS-Selector-to-extended-properties-in-Object/idi-p/205255 

    • AlexKaras's avatar
      AlexKaras
      Champion Level 3

      Hi,

       

      Marked solution is incorrect.

      Reply was correct as of date of writing.

       

      Delete all my existing mapping and start again if I want to work with CSS locators

      This is just because the new cross-platform web mode that you are talking about uses Selenium under the hood. Selenium has no idea about TestComplete's native recognition functionality and thus 'native' and 'cross-platform' NameMappings are incompatible and cannot be mixed.

       

      P.S. Search by CSS is supported in TestComplete via the .FindElement() and .QuerySelectorAll() methods and has the same problems as the search by XPath.

       

      • Tris's avatar
        Tris
        Contributor

        AlexKaras - apologies, I'm from the UK, saw the date as 2nd September 2020, rather than what it is (US date) 9th February 2020.

         

        Still would be nice to see a future update which made the CSS/Xpath locators visible in the old way of mapping so that they could be gracefully switched over. In the software I'm automating it would potentially be worth switching due to the lack of attributes associated to objects, though in recent update of our technologies it seems that they are starting to get better.