Forum Discussion

rajvansh's avatar
rajvansh
New Contributor
11 years ago
Solved

Is it possible to set the Default values and Local values of a project variable by a function call?

Please consider the following scenario:   1.We created a function abc (temp) to retrun a string (say testvalue). 2. We added avariable with Name=Var1, Type=String,  Default Value= abc  ("xyz"), Lo...
  • k_de_boer03's avatar
    11 years ago

    I do something similar using event handlers, I think the following should work:

     

    Create a new event for OnStartTest, this should give you a function like:

    function GeneralEvents_OnStartTest(Sender){
    
    }

     

    In the same file (or elsewhere and import it) you can add your function:

    function abc(){
      return "testvalue";
    }

    Now back in the event handler, you can set your project variables like:

    function GeneralEvents_OnStartTest(Sender){
      Project.Variables.Var1 = abc();
    }

    At the start of every test item, the Var1 value will be set to the return value of abc(); So when you print the value of Var1 in your test item, it should print "testvalue";

     

    I havent reproduced the code locally, but I am fairly confident this works.