kalldrexx
13 years agoContributor
How can I convert my TC objects in VB.Net to a compatible var type
I have a C# connected application that controls TestComplete/TestExecute. I am looking at hooking into my vast library of helper methods with a VB.Net class (so that less experienced QA developers can use it to write testing code).
Right now in C# I have the following helper method:
This works fine when I interact with it from C#, but when I try to use the following VB.Net code:
This code causes the following exception:
Unable to cast COM object of type 'System.__ComObject' to class type 'AutomatedQA.script.var'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
What is required for me to cast a test complete object into a TestComplete var type?
Right now in C# I have the following helper method:
public class CamaUtils
{
/// <summary>
/// Sets the text of a CustomCama text field
/// </summary>
/// <param name="textfield">Text field's test complete object</param>
/// <param name="value">Value to set the text field to</param>
/// <param name="useTabToExit">If Tab is used to exit the text field. If false this function will NOT remove the cursor from the text field</param>
public static void SetTextFieldValue(var textfield, string value, bool useTabToExit = true)
{
if (textfield == new var(null))
throw new ArgumentNullException("Attempted to set the value of a text field without passing in the text field object");
textfield["SetFocus"]();
textfield["Keys"]("^[Home]!^[End]"); // Clear the current value
textfield["Keys"](TestingUtils.EscapeTestCompleteInputString(value));
if (useTabToExit)
textfield["Keys"]("[Tab]");
}
}
This works fine when I interact with it from C#, but when I try to use the following VB.Net code:
Dim window = Aliases.WinRDE.WaitAliasChild("fmPermitInsert", 1000)
CamaUtils.SetTextFieldValue(window.txtPermitNo, action.Attributes.Item(PERMIT_NUM_PARAM))
This code causes the following exception:
Unable to cast COM object of type 'System.__ComObject' to class type 'AutomatedQA.script.var'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
What is required for me to cast a test complete object into a TestComplete var type?