Forum Discussion

kcurteman's avatar
kcurteman
Occasional Contributor
7 years ago

How to check for objects that did not exist at test start

I have a test that creates new items on our website. This consists of multiple parts that each create pieces of what will come together at the end as a fully functional program.

 

One of the steps creates savings information for another piece created earlier in the tests. To do this, TestComplete has to click an add button, then find the new item in a table. Unfortunately this is where i am having issues. With each new version we run this test and it cannot identify the checkbox next to the new name without me manually adding the checkbox into the namemapping before running.

 

Then after the checkbox is enabled and the dialog is closed, the new item is added to an existing list and i have to identify an edit button next to the new item. Same issue as these do not exist before test execution.

 

Is there a way to identify these newly created items during test execution? or a way to parameterize/variableize the namemapping for the checkbox/edit button?

4 Replies

  • NisHera's avatar
    NisHera
    Valued Contributor

    In automation we run previously identified UI objects in a given order.

    So that manual repetitive work are assigned to a machine.

     

    If those objects are "Brand new", TC do not have a capacity to identify.

     

    But if this new object has particulate pre-determined unique properties,

    you can program with wild cards, loops and conditions to handle those. 

     

    If you can elaborate more we may able to help 

     

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      You might want to also look into Find and FindChild methods.  Supposedly, you know what the object is that you are adding (caption, text content, etc).  So, taking the parent object, you could call the "FindChild" method, passing in the properties and property values.  This method will return the object you want.

       

      I would not recommend attempting to map any of these dynamically added objects.  This is generally a rule of thumb that I apply.  If objects/components etc are added on the fly and created within the application (like new rows in a table, new icons in a panel, etc), I use Find methods to interact with them.

       

      Something else I would recommend is a "clean up" process at the end of your test run or a "reset" process at the beginning.  Your application is going to get "full" of all these created items and objects each time you run the tests. Once you complete a test, if you're finished with an object, if you have the ability to, I would remove/delete the item so that future test runs will not be "polluted" by extraneous test artifacts.  Alternatively, you could do a database restore or some other "reset" process before you test starts to get your application to a "baseline" state so that, when you start your tests, they always start with the same basic data.  

    • kcurteman's avatar
      kcurteman
      Occasional Contributor

      Once the item is created, it needs to be added to a schedule. We do this by going to the schedule and clicking the Add button. A Dialog opens and in it is a table with 2 columns; one with checkboxes and one with the item names.

       

      The list includes all items that are available but not added to the schedule (either because they are new or exist on a different schedule)

       

      I need to find the checkbox in the first column that is next to the Cell with the newly created item's name.

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Yup, definitely use a Find on the table itself.  Once you find the cell with the created items name, you then go to the Cell with that same row and one column over and access the child object of the cell.  We do something similar in our stuff.

         

        function findRow(tableObject, stringSearch, searchColumn) {
            var cellFound = Utils.CreateStubObject();
            if ((searchColumn == 999) || (searchColumn == undefined)) {
                cellFound = tableObject.FindChild('innerText', aqConvert.VarToStr(stringSearch) + '*', 0, true);
            }
            else {
                for (var i = 1; i < tableObject.RowCount; i ++) {
                    if (aqString.Trim(tableObject.Cell(i, searchColumn).innerText) == aqString.Trim(aqConvert.VarToStr(stringSearch)) ) {
                        cellFound = tableObject.Cell(i, searchColumn);
                        break;
                    } 
                
                } 
            }
            if (cellFound.Exists) {
                return cellFound.RowIndex;
            }
            else {
                throw Error ('Unable to find the cell with string ' + stringSearch);
            }
        }