With Squish 6.4 we introduced script-based object maps, which provide a more powerful way to manage object names. Script-based object maps will enable you to use native script language concepts to organize the object map, to reduce redundancy and to help with dynamic object lookup. In this article I will show you how you can approach converting your existing text based object maps to this new approach. I will highlight some of the challenges you can expect and explain how you can overcome them.
Conversion Utility
If you open a test suite that you want to convert, you can find the conversion utility inside the test suite settings.
Conversion Dialog
If you open the utility it will give you the option to “Copy & Convert” or to “Convert In-Place”. Copy & Convert will make a copy of the test suite before converting it and is the recommended option, because it will prevent data loss. Convert In-Place will overwrite the existing test suite. Furthermore you have the option to preserve the text-based object map. You can use this option to use the text-based and script-based object map side by side. This can help to ease the transition phase.
Conversion process
Step by Step Conversion
Embrace the challenge
Example: How to fix custom real name handling
dataSet = testData.dataset(dataSetPath); row = 0 for record in dataSet: for column in xrange(0,3): targetValue = testData.field(record, column) realName = "{column='%s' container=':Address Book - MyAddresses.adr.File_QTableWidget' row='%s' type='QModelIndex'}" % (column, row) test.compare(waitForObjectExists(realName).text, targetValue) row = row +1
dataSet = testData.dataset(dataSetPath); row = 0 for record in dataSet: for column in xrange(0,3): targetValue = testData.field(record, column) realName = "{column='%s' container=names.address_Book_MyAddresses_adr_File_QTableWidget row='%s' type='QModelIndex'}" % (column, row) test.compare(waitForObjectExists(realName).text, targetValue) row = row +1To fix this, the dynamic lookup can be moved into the script-based object map and the error prone string replacement can be replaced by simple dictionary operations. This will make the test script much more maintainable. To achieve this we can simply create a function inside the script-based object map and call it from the test script.
def addressTableCell(row, column): return {"column": column, "container": address_Book_MyAddresses_adr_File_QTableWidget, "row": row, "type": "QModelIndex"}
dataSet = testData.dataset(dataSetPath); row = 0 for record in dataSet: for column in xrange(0,3): targetValue = testData.field(record, column) test.compare(waitForObjectExists(names.addressTableCell(row, column)).text, targetValue) row = row +1If you follow this general approach you should be able to already improve your test scripts and object map while migrating to script-based object maps.