QTP dll library - Parameters

0

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.

c#
.net
vbscript
qtp
asked on Stack Overflow Apr 16, 2012 by Mike Card • edited Jun 20, 2020 by Community

1 Answer

0

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:

  1. Open the QTP connection
  2. Open the QTP script
  3. Set up recovery and resources - inc param(s)
  4. Run the test

I hope that this will be of some use to someone else in this situation.

answered on Stack Overflow Apr 17, 2012 by Mike Card • edited Apr 18, 2012 by Jason Braucht

User contributions licensed under CC BY-SA 3.0