Good afternoon all,
I am currently working on an integrated testing portal using MVC.Net.
I am attempting to migrate a VB custom communication script to a C# service. I have successfully migrated a number of newer QTP scripts, however have got stuck on a couple of legacy scripts that the comapny requires.
The QTP script itself loads ok up to the point where a custom param is set using the following VB lines of code:
Set oParameters = oQTPApplication.Test.ParameterDefinitions.GetParameters()
oParameters.Item("sEnvironment").Value = sEnvironmentForDataTable
Once the code runs through the various other set ups (after successfully opening and connecting to QTP, and hits the converted lines:
Method 1:
var parameters = this.Connection.Test.ParameterDefinitions.GetParameters();
parameters["sEnvironment"].Value = this.Test.TestEnvironment;
Method 2:
this.Connection.Test.ParameterDefinitions["sEnvironment"].DefaultValue = this.Test.TestEnvironment;
Both throw the exception:
System.Runtime.InteropServices.COMException
Element not found. (Exception from HRESULT: 0x8002802B (TYPE_E_ELEMENTNOTFOUND))
At System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData) At QTObjectModelLib.ParameterDefinitions.get_Item(Object Position) At TestLayer.Tests.Utilities.Qtp5Connection.SetTestSpecificParams()
It seems that the interface is attempting to find the specified parameter, however in this case I already know it doesnt exist and wish it to add the param. to be used within the script but for the life of me - I cant find a way of adding a custom param in C#. I assum this was working as the VB works...
Any help would be much appretiated.
I have continued working on the problem since I posted and have found a solution.
You do indeed use Method 1 however you need to ensure that the intended script has been opened. I am assuming that the QTP script that you are connecting to needs to be set up to recieve the param.
So here are the following steps that I have taken in code to achieve this:
I hope that this will be of some use to someone else in this situation.
User contributions licensed under CC BY-SA 3.0