循环遍历RobotFramework中的文件内容

chi*_*upt 4 robotframework

如何在Robot Framework中循环浏览文件的内容?

我的文件内容如下:

1001
1002
1003
1004

我想逐个阅读内容,将其分配给变量然后用它做一些操作.

Bry*_*ley 13

Robotframework有几个内置库,可以添加很多功能.可用于此任务的两个是OperatingSystem库和String库.

您可以使用OperatingSystem库中的关键字Get File来读取文件,并且可以使用String库中的Split to Lines关键字将文件内容转换为行列表.然后,这只是使用for循环遍历行的问题.

例如:

*** Settings ***
| Library | OperatingSystem
| Library | String

*** Test Cases ***
| Example of looping over the lines in a file
| | ${contents}= | Get File | data.txt
| | @{lines}= | Split to lines | ${contents}
| | :FOR | ${line} | IN | @{lines}
| | | log | ${line} | WARN
Run Code Online (Sandbox Code Playgroud)


Mar*_*lea 0

下面列出了如何在 Robot Framework 测试用例中使用 FOR 和 While 循环的不同示例。

http://robotframework.googlecode.com/svn/tags/robotframework-2.5.3/atest/testdata/running/for.txt