Search code examples
c#hp-uftuft-api

UFT API Test: How to read the User Variables and System Variables in custom code


I want to read the User Variables and System Variables in custom code of my UFT API test. How can I do the same.

enter image description here


Solution

  • It's pretty straight forward, just insert this code in your custom code activity and it will take care of it.

    Just replace the variable names that you want to capture.

    string systemVar = System.Environment.GetEnvironmentVariable("JAVA_HOME");
    CodeActivity4.Report("systemVar", systemVar);
    
    string userVar = this.CodeActivity4.Input.myVar;
    CodeActivity4.Report("userVar", userVar);
    
    string testVar = this.Context.TestProfile.GetVariableValue("TestName");
    CodeActivity4.Report("testVar", testVar);
    

    Here here is the result:

    enter image description here