Having played around with this for a while, there's one gotcha you have to be aware of when using this method. TC caches.
If you have a Keyword test that calls a script, which sets the project variable, followed by a second keywords test that sets the variable, it will work fine. If you have one script that changes the variable in the middle, it wont work. I sent details to support, so just copying and pasting:
function SetComboText(ObjectIdentifierString, Text) {
Project.Variables.MetaObjectIdentifier=ObjectIdentifierString;
browser.MetaCombobox.SetText(Text);
}
My keyword test calls the script with the ObjectIdentifier for Combobox1 and it sets the text for ComboBox1 correctly.
My second keyword test calls the script with ObjectIdentifier for ComboBox2 and it set the text for ComboBox2correctly.
Now, for keyword test 3 I use the following script:
function SetComboboxestext(Combo1Text,Combo2Text)
{
SetComboText(Combobox1ObjectIdentifierString,Combo1Text); //I know what the ObjectIdentifier is and it's static. This sets the text of combobox1
SetComboText(Combobox2ObjectIdentifierString,Combo1Text); //I also know what the ObjectIdentifier is and it's static. This ALSO sets the text for combobox 1
}
In other words, if I set the project variable a second time in the same script it doesn't pick this up. I have put a breakpoint in after setting the project variable for the second time. If I find the actual combobox2 in object browser, it has the MappedName of browser.MetaCombobox and combobox1 has a blank as MappedName, so obviously it picked up on the change. My script watch however tells me that Aliases.browser.MetaCombobox.ObjectIdentifier is Combobox1ObjectIdentifierString. What happens then is that the text of Combobox1 gets set again with combo2text....
Response from Support, which I tested and works :
-----------------------------------------------------------------------------
This happens because TC holds a cached reference to the first object. Since the object's state doesn't change, TC doesn't try to reobtain it and keeps using the first combo box. Going to the Object Browser refreshes the object tree and resets cached objects. Call Refresh in the SetComboText function:
function SetComboText(ObjectIdentifierString, Text)
{
Project.Variables.MetaObjectIdentifier=ObjectIdentifierString;
Aliases.browser.Refresh();
Aliases.browser.MetaCombobox.RefreshMappingInfo();
Aliases.browser.MetaCombobox.SetText(Text);
}
-----------------------------------------------------------------------------------------------