无法在RobotFramework

时间:2018-11-22 04:50:18

标签: python text-files robotframework

无法在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

1 个答案:

答案 0 :(得分:2)

您可以使用操作系统库 http://robotframework.org/robotframework/latest/libraries/OperatingSystem.html

中的关键字追加到文件

使用追加到文件关键字对代码进行了一些小的修改,就可以了!

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