如何将变量写入文件?

How to write a variable into a file?

我想在输出文件中存储 ${Username} 值:

例如如果 ${Username} 等于 0401190926729000,则此值将存储在文件中。

这是一个提议:

*** Settings ***
Library  OperatingSystem
Library  String

*** test cases ***
write_variable_in_file
  ${Username} =  Generate Random String  1  abc
  log to console   ${Username}
  run keyword if  '${Username}' == 'a'   write_variable_in_file  ${Username}

*** Keywords ***
write_variable_in_file
  [Arguments]  ${variable}
  Create File  ${EXECDIR}/file_with_variable.txt  ${variable}