Micro Focus QTP (UFT) Forums
C# Environment property using QTP API - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: C# Environment property using QTP API (/Thread-C-Environment-property-using-QTP-API)



C# Environment property using QTP API - asuteau - 08-03-2012

Hello,

I'm currently working on converting a tool from VBS to C# which intends to launch automatically QTP scripts stored on QC.
In the VBS tool, we're using user-defined environment variables to pass parameters to QTP scripts. I'm trying to do the same using C# but I don't know how to use the Test.Environment property since it's of "object" type. Indeed, using auto-completion in Visual Studio, no method or property is suggested.

In VBS, I have the following code:
Code:
Set qtApp = CreateObject("QuickTest.Application")
qtApp.Open SCRIPT_PATH, true, true
qtApp.Test.Environment.Value("My_Param") = 5

In C#, here is the equivalent:
Code:
Application qtpApp = new Application();
qtpApp.Open(SCRIPT_PATH, false, true);
Console.WriteLine(">>> Environment: {0}", qtpApp.Test.Environment.ToString());    // Returns "System._COMObject"

I would really appreciate if someone could give me a hint to solve this issue.

Best regards,
--
Aymeric