无法在RobotFram中写入现有文本文件

2024-03-28 21:47:02 发布

您现在位置:Python中文网/ 问答频道 /正文

无法在RobotFramework中写入现有文本文件。 我的目标是从for循环中获取输出并将值写入文本文件,目前我能够创建文本文件并从for循环打印输出值,但无法将值写入文本文件。在

我所做的:

*** Settings ***
Library           OperatingSystem

*** Variables ***
${PATH}           ${CURDIR}/write_one_to_five.txt

*** Test Cases ***
For_Loop
    Create File    ${PATH}    # Text file created at current directory
    : FOR    ${i}    IN RANGE    1    6
    \    Log    ${i}
    File Should Exist    ${PATH}    ${i}
    Log    Exited

Tags: pathlog目标forsettingslibraryvariablesfile
1条回答
网友
1楼 · 发布于 2024-03-28 21:47:02

您可以使用来自操作系统库的关键字附加到文件http://robotframework.org/robotframework/latest/libraries/OperatingSystem.html

使用Append To File关键字对代码进行了一些小的修改,它就成功了!!在

*** Settings ***
Library           OperatingSystem

*** Variables ***
${PATH}           ${CURDIR}/write_one_to_five.txt

*** Test Cases ***
For_Loop
    Create File    ${PATH}    # Text file created at current directory
    : FOR    ${i}    IN RANGE    1  6
    \    log to console  ${i}
    \    ${b}=  Convert To String  ${i}     #conversion was required as it was throwing encoding error for integer
    \    Append To File  write_one_to_five.txt  ${b}
    #File Should Exist    ${PATH}    ${i}      #This was causing error to me, hence commented
    Log    Exited

相关问题 更多 >