将文件内容与变量进行比较

问题描述 投票:0回答:1

我已从 Robot Framework 内部将内容写入文本文件。 如何将刚刚生成的文本文件的内容与变量进行比较?

这就是我创建文本文件的方式 - 使用此关键字的声明:

Write String To File
    ${Mystring}=    Set Variable    justRandomContent
    Create File    P=file=${CURDIR}/data/.txt    ${Mystring}

这就是我尝试执行比较(从测试用例内部)失败的方法:

Write String To File
    Should Be Equal As Strings    ${P}    ${expectedValue}    strip_spaces=True

${expectedValue}
是我想要与文本文件进行比较的变量,它在机器人文件的其他地方声明。

robotframework
1个回答
0
投票

这是对您的代码的修改。

Write String To File
    Set Suite Variable    \${PathToFile}    ${CURDIR}/data/.txt
    ${Mystring}=    Set Variable    justRandomContent
    Create File    ${PathToFile}    ${Mystring}

您的关键字不得与其他关键字重名。您可能应该清理从

${P}
文件中读取的内容,以确保它包含您需要的内容。
String
库中有一些关键字,例如
Get Lines Containing String

Validate String At File
    ${P}=    Get File    ${PathToFile}
    Should Be Equal As Strings    ${P}    ${expectedValue}    strip_spaces=True
© www.soinside.com 2019 - 2024. All rights reserved.