Search code examples
c#hp-uft

How to get Test variable through custom code in HP UFT - ApiTest


I want to set value to the Test Variable using Custom Code. Can you tell me how to do it as i am not able to access the variable from code.

UFT profile variable

I need to access the User Variable URL in my custom code and set the value.

Please help me if you know how to do it using Custom Code.

Thanks, Madhan


Solution

  • Based on your question:
    1. Click on File menu and then Settings, it will open Properties pane.
    2. Click on "+" to add user variable and give a name.
    3. In your custom code, type below code:

      string s = "https://www.google.com/";
      this.Context.TestProfile.SetVariableValue("NameOfYourVariable",s);
    

    To retrieve the value of given variable:

      string ss = this.Context.TestProfile.GetVariableValue("NameOfYourVariable");
      CodeActivity5.Report("Variable is : ", ss); //(This line will print your variable value)