Forum Discussion

lachapan's avatar
lachapan
Occasional Contributor
7 years ago
Solved

Is there a document that provides developers with best practices for testers to ID objects using TC?

Our developers have asked us if there is a document or white paper of guidelines of things developers can do to make it easier to identify objects using TestComplete. We know the obvious one of IdStr but sometimes, especially with ReactJS and Kendo grids, it is all dynamic or partially dynamic (where we hook to a parent).

 

Our developers have asked me if there are documented best practices. I've search through the help and couldn't see one, but maybe somebody knows of a doc?

 

Thanks,

Andy

  • Andy,

     

    It is really good if it is possible to ask Development for the things that you need and they consider your requests.

    Two more nice ideas that were mentioned in the article for Robot :

    a) Error(s) on the page must be displayed via the same object with the same ID and this ID must be the same across all pages of the tested application. If it is really needed to display more than one error object on the page, than those objects must have IDs with the same prefix. The above will make it really simple for you to check in test code whether or not an error was displayed: just check if page.FindAllChildren("id", "error*", <depth>) returns something (and whether or not found objects are visible depending on the tested application). No need for the code like (pseudocode):

    if (page.url.contains("order") and page.find(errorObjectForOrder))

    else if (page.url.contains("checkout") and page.find(someOtherErrorObjectForCheckout))

    else if(...)

     

    b) If you need to check data in a (web) table, it is really cool if every cell of the table has compound id consisting of common prefix (e.g. <tableName>_<ColumnName>_ ) and a suffix that describes data in the given cell. This is especially handy and useful if the cell contains non-textual data that must be verified.

    For example, consider a two-column table that displays the name of a car and car's image. How can you check that, say, for two rows, one for BMW and another for Fiat, images correspond to names?

    But if the cells have IDs like this:

    Cars_BMW_Name | Cars_BMW_BMW_imageSmall60x80.jpg

    Cars_Fiat_Name | Cars_Fiat_FiatscreenshotFromShow.png

    then you definitely will be able to create more simple and reliable test code.

3 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi Andy,

     

    I never met such a document with TestComplete been in the primary focus. But long ago I've met a similar document for Rational Robot (it was titled something like "Making (web?) applications testable with Robot") and its content was pretty applicable to TestComplete.

    The most fast and reliable way to identify objects for TestComplete is when objects have assigned ID property.

    All other identification approaches (like those mentioned here http://support.smartbear.com/testcomplete/docs/testing-with/object-identification/name-mapping/overview.html#object-identification-criteria, as well as the possibility to search by XPath or CSS selector) are rather supplementary ones that make it possible to automate applications that do not have IDs assigned to its internal objects.

    So, I would say that you *must* do whatever possible to establish a rule (or requirement) to make all objects to have stable assigned IDs. (Or, at least, IDs must be assigned to the key UI elements that can be used as an anchors for subsequent objects search - e.g. menu panel, left navigational panel, main area for the documents, etc.).

    Without IDs assigned, there are still high chances that you will be able to automate such application, but you will spend enormous time to make test code quickly and reliably search for objects and to support this code. In the worst case you will resort to search for objects by caption text. I believe there is no need to tell you about reliability, performance and localization of such test code.

     

    P.S. I understand that because of this or that reasons developers may prefer things like ReactJS, Angular or Kendo. But I think that if the given library cannot provide IDs for created objects, then for us, been a testers and, actually, end-users, the given library is a tool that do not provide required result and thus it must be thoroughly considered whether or not should it be used. At least, the management must be warned that it will be much more difficult to create an automation code (in terms of your performance and code reliability) if tested objects do not have unique and stable identifiers. And note, that the things like class name or custom attributes that some libraries use (React, Angular, ...) are far less than ideal for fast and reliable objects identification.

    • lachapan's avatar
      lachapan
      Occasional Contributor

      Thanks Alex, yeah it's a point we constantly try to make with Developers. We are starting to make inroads with our Development teams.

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Andy,

         

        It is really good if it is possible to ask Development for the things that you need and they consider your requests.

        Two more nice ideas that were mentioned in the article for Robot :

        a) Error(s) on the page must be displayed via the same object with the same ID and this ID must be the same across all pages of the tested application. If it is really needed to display more than one error object on the page, than those objects must have IDs with the same prefix. The above will make it really simple for you to check in test code whether or not an error was displayed: just check if page.FindAllChildren("id", "error*", <depth>) returns something (and whether or not found objects are visible depending on the tested application). No need for the code like (pseudocode):

        if (page.url.contains("order") and page.find(errorObjectForOrder))

        else if (page.url.contains("checkout") and page.find(someOtherErrorObjectForCheckout))

        else if(...)

         

        b) If you need to check data in a (web) table, it is really cool if every cell of the table has compound id consisting of common prefix (e.g. <tableName>_<ColumnName>_ ) and a suffix that describes data in the given cell. This is especially handy and useful if the cell contains non-textual data that must be verified.

        For example, consider a two-column table that displays the name of a car and car's image. How can you check that, say, for two rows, one for BMW and another for Fiat, images correspond to names?

        But if the cells have IDs like this:

        Cars_BMW_Name | Cars_BMW_BMW_imageSmall60x80.jpg

        Cars_Fiat_Name | Cars_Fiat_FiatscreenshotFromShow.png

        then you definitely will be able to create more simple and reliable test code.