如何将变量写入文件?

mia*_*mia 2 robotframework

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

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

Lau*_*iel 10

这是一个提议:

*** 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}
Run Code Online (Sandbox Code Playgroud)