Is possible to create new variable in suite/test set up - Robot Framework?

后端 未结 2 449
死守一世寂寞
死守一世寂寞 2021-01-05 10:56

Is it possible to initialize a variable in a suite or test setup based on the return value of a keyword? I\'ve tried this sort of syntax and it didn\'t work:



        
2条回答
  •  爱一瞬间的悲伤
    2021-01-05 11:22

    To expand on Bryan's answer and add clarification for those of you not specifically interested in creating a suite variable based on the results of a keyword, there are other ways to initialize "global" variables at the start of a Robot Framework test.

    The easiest way is to put them under a Variables header.

    *** Variables ***
    ${this_string}  This String
    ${that_int}     5
    

    An alternative way to do that is to put the same variables in a Resource .txt file. Once it's called under *** Settings ***, the variables can be used freely. Assuming you have your variables in a file called VarList.txt, the following code will initialize them:

    *** Settings ***
    Resource    VarList.txt
    

    Should you be using a Resource file with existing keywords and internal variables, this will also work for that.

    This all assumes you want static variables. Set Suite Variable and Set Global Variable can both be used with keywords like Bryan said. Set Suite Variable works well for scripts with multiple test Suites, while Set Global Variable should be used extra sparingly in that case. In a single-Suite script, however, the differences are all but negligible, though best practice would be to stick with Set Suite Variable unless you really want it to be global, just on the off-chance you decide to add that Suite to a script running multiple Suites.

提交回复
热议问题