Issue using Excel and variables in name mapping

Originally posted by nastester on February 13, 2025

I am using variables in name mapping objects to pull data from an Excel sheet and then verify with Property Checkpoints.

It is working fine for the first 3 rows in my sheet. But on the fourth row I am getting an error for the address. The previous 3 addresses worked fine. The local variable was updated and checkpoint passed. Also the first four checkpoints for this fourth row of data worked fine, it just fails on the address.

I cannot figure out why this fourth one is failing. Any ideas? Lots of info/screenshots below that will hopefully help.

Name Mapping object using variable:

Project level variable:

Excel sheet with address data:

function ReadManifestData()
{
  // Get the sheet of the Excel file
  var excelFile = Excel.Open(Project.ConfigPath + "Datasheet.xlsx");
  var excelSheet = excelFile.SheetByTitle("ViewData");

  // Read data from the Excel file
  var RowIndex = KeywordTests.CheckManifestScreen.Variables.RowIndex_KW;
  var Order_Num = excelSheet.Cell("A", RowIndex).Value;
  var HIN_Num = excelSheet.Cell("B", RowIndex).Value;
  var TrackNum  = excelSheet.Cell("C", RowIndex).Value;
  var Forecasted  = excelSheet.Cell("D", RowIndex).Value;
  var Street_Addr   = excelSheet.Cell("E", RowIndex).Value;
  var ServiceLevel = excelSheet.Cell("F", RowIndex).Value;
  var Commit_Time = excelSheet.Cell("G", RowIndex).Value;
  var Cons_Name = excelSheet.Cell("H", RowIndex).Value;
  var Floor_Num = excelSheet.Cell("I", RowIndex).Value;
  var Postal_Code = excelSheet.Cell("J", RowIndex).Value;
  var City_Name = excelSheet.Cell("K", RowIndex).Value;
  var State_Name = excelSheet.Cell("L", RowIndex).Value;
  var Country_Code = excelSheet.Cell("M", RowIndex).Value;
  var Urbanization = excelSheet.Cell("N", RowIndex).Value;
 
 Project.Variables.Order_Num_KW = Order_Num;
 Project.Variables.HIN_Num_KW = HIN_Num;
 Project.Variables.TrackNum_KW = TrackNum;
 Project.Variables.Forecasted_KW = Forecasted;
 Project.Variables.StreetAddr_KW = Street_Addr;
 Project.Variables.ServiceLevel_KW = ServiceLevel;
 Project.Variables.Commit_Time_KW = Commit_Time;
 Project.Variables.ConsName_KW = Cons_Name;
 Project.Variables.Floor_Num_KW = Floor_Num;
 Project.Variables.Postal_Code_KW = Postal_Code;
 Project.Variables.City_Name_KW = City_Name;
 Project.Variables.State_Name_KW = State_Name;
 Project.Variables.Country_Code_KW = Country_Code;
 Project.Variables.Urbanization_KW = Urbanization;

}

Keyword test:

Log:

Originally posted by scot1967 on February 13, 2025

This looks like a problem with the browser page object name mapping. I would begin by ensuing the target object is mapped correctly and uniquely.

I also noticed you are using a value ‘0’ (which should work) instead of the cmpEqual constant in the failing checkpoint. Probably not an issue.

Originally posted by nastester on February 13, 2025

What is that 0 even for?
I see what you’re talking about:
Aliases.browser.pageIcoms.panelStAdd, “contentText”, 0, Project.Variables.StreetAddr_KW, true

But I also see that for all the other checkpoints when I click into the row.

I think you’re right that something is not right with the object mapping but not sure how to troubleshoot further. Especially since it works fine for my first three rows and it “looks” correct compared to all my other mapped objects

Originally posted by nastester on February 13, 2025

I do see this when trying to edit the object in namemapping. Don’t get that for any of the other objects I am using.

Other objects:

Originally posted by scot1967 on February 13, 2025

You can use a constant like ‘cmpEqual’ or the value that constant represents, 0 in this case.

Constant Value Description
cmpEqual 0 Check whether the Property value equals Value.
cmpNotEqual 1 Check whether the Property value is not equal to Value.
cmpGreater 2 Check whether the Property value is greater than Value.
cmpLess 3 Check whether the Property value is less than Value.
cmpGreaterOrEqual 4 Check whether the Property value is greater or equal to Value.
cmpLessOrEqual 5 Check whether the Property value is less or equal to Value.
cmpContains 6 Check whether the Property value contains Value.
cmpNotContains 7 Check if the Property value does not contain Value.
cmpStartsWith 8 Check whether the Property value starts with Value.
cmpNotStartsWith 9 Check if the Property value does not start with Value.
cmpEndsWith 10 Check whether the Property value ends with Value.
cmpNotEndsWith 11 Check if the Property value does not end with Value.
cmpMatches 12 Check whether the Property value matches the regular expression specified by Value.
cmpNotMatches 13 Check if the Property value does not match the regular expression specified by Value.
cmpIn 14 Check if Value contains the Property value. (Similar to cmpContains, but the other way round.)
cmpNotIn 15 Check if Value does not contain the Property value. (Similar to cmpNotContains, but the other way round.)

Originally posted by scot1967 on February 13, 2025

I think you’re right that something is not right with the object mapping but not sure how to troubleshoot further. Especially it works fine for my first three rows and it “looks” correct compared to all my other mapped objects

I sometimes use this trick. You may not be into scripting but you can start a script recording click on your target object and then stop the recording and TestComplete will show you a script with a complete path to the object. It may also add an alias to your namemap depending on how your project is setup.

Originally posted by scot1967 on February 13, 2025

You have probably seen this page but it may be worth a deep dive here to really understand what the namemap is an how it works.

https://support.smartbear.com/testcomplete/docs/testing-with/object-identification/name-mapping/index.html

Originally posted by rraghvani on February 13, 2025

The first thing that I would usually check, is to ensure that the cell is of the correct type i.e. the format of the cell (General, Text, etc).

Use Log.Message to output the values of the variables. This should give you an indication that the cells are correctly being read.

Has the page changed, if testing web app? Does panelStAdd actually exists? Or does it become enabled after entering something else?

Originally posted by nastester on February 13, 2025

Will try that that but also uncovered this when adding in more logging.
So it’s not getting the value for that fourth row at all for some reason.

Originally posted by scot1967 on February 13, 2025

I too have seen Excel formatting issues like this. This usually results in a checkpoint failure not a namemap error.

It looks like button51c is clicked prior to looping through the app objects to compare them to each Excel row cell. There is also a ‘Click’ and SetText for each row within the loop.

What is going on there?

Originally posted by Hassan_Ballan on February 13, 2025

Your first three values are identical, the forth is different.
You are using a parametrized NameMapping and the value changed; therefore, it does not find the target object as the log message states.

Each time you set value to the NameMapping variable you need to refresh the mapping info for it to take effect. Otherwise, the cache value takes over.

https://support.smartbear.com/testcomplete/docs/testing-with/object-identification/name-mapping/how-to/refresh-cache.html

Originally posted by scot1967 on February 13, 2025

This image indicates an issue with the namemap accessing panelStAdd. In your loop there is a click and a text entry action that seems to indicate adding text to a filter in the page.

Originally posted by nastester on February 13, 2025

The first three aren’t identical though. The numbers of street address are different

Originally posted by Hassan_Ballan on February 13, 2025

You are right, did not pay attention.

Still you need to use the refresh mapping info method as I described, try it out https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/refreshmappinginfo-method.html does it still fail?

Originally posted by nastester on February 13, 2025

All, thank you for your responses. I finally uncovered the issue. The issue was some of the data the mock API is returning had spaces in the address field (which was truncated by table so not noticeable when looking at the UI). The data from the UI was copied into the spreadsheet so it didn’t have the space. I still don’t know why TC didn’t log the ER/AR and show that they didn’t match but when I updated the mock data to not have spaces, everything worked.

Originally posted by rraghvani on February 14, 2025

I thought you were reading the spreadsheet and populating the UI?

What’s ER/AR?

Originally posted by nastester on February 14, 2025

Expected result/actual result.

And no, the test is verifying that the data table on the UI is displaying the expected data from the API in the right location. It isn’t inputting any data.

Originally posted by scot1967 on February 14, 2025

It seems you are using the actual street address (which is dynamic) as matching data in your name map based on a keyword test parameter or project variable. “//div[.=‘%StreetAddr_KW%’]” This could make your test brittle as it is based on the format of the address. A better alternative would be to map the web control using another static property and compare the value of that control if possible. This should prevent name mapping errors unless the web page itself is altered by dev.

Originally posted by scot1967 on February 14, 2025

The use of dynamic data in a name map also makes is necessary to refresh the namemap and object instance (effectively remapping the object) prior to each call to the mapped object to make the comparison. This will slow your test down considerably.

Originally posted by nastester on February 14, 2025

I don’t think I follow you. Could you elaborate a bit because I am genuinely curious if there is a better way to do what I am trying to accomplish.

This is what I am doing:

  • The cells in the first row of the data table are mapped and the xpath is updated to read from a Project Level variable
  • A script pulls data from Excel which is storing the data in the table and it assign the columns to the corresponding Project Level variable
  • A Keyword test performs the necessary UI actions including searching the table to filter it to one row of data
  • The Keyword test then compares the current value of the UI object to the Project level variable (which is coming from Excel)

I’m sure there is a better way to do this. This is my first time using TC in this way. But it does work for multiple rows of data in my sheet.