How to write a variable into a file?

梦想的初衷 提交于 2019-11-29 15:45:06

问题


I would like to store ${Username} value in an output file:

E.g. If ${Username} equals 0401190926729000, this value will be stored in a file.


回答1:


Here is an proposal:

*** 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}



回答2:


linux: Run echo "${Username}" > /tmp/foo



来源:https://stackoverflow.com/questions/29397198/how-to-write-a-variable-into-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!