兩種方法:
#py文件中:
from robot.libraries.BuiltIn import BuiltIn #兩個參數:變量名,變量值
BuiltIn().set_global_variable(name, *values)
#RF文件的用戶關鍵字中:
*** Keywords *** globalval set global variable name1 value1
BuiltIn().set_global_variable(name, *values) 這個方法有點坑,只是執行python腳本是要報錯的
執行RobotFramework的用例是沒有問題的,所以如下腳本優化了下:
try: BuiltIn().set_global_variable('${GetToken}',token) except: print('不進入robotframework')