循环遍历 RobotFramework 中的文件内容 [英] Looping through the content of a file in RobotFramework

查看:111
本文介绍了循环遍历 RobotFramework 中的文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Robot Framework 中循环遍历文件的内容?

How can I loop through the contents of a file within Robot Framework?

我的文件内容是这样的:

My file contents would be like this:

1001
1002
1003
1004

1001
1002
1003
1004

我想一一读取内容,将其赋值给一个变量,然后对其进行一些操作.

I want to read the contents one by one, assign it to a variable and then do some operations with it.

推荐答案

Robotframework 有几个内置库,可以添加很多功能.您可以用于此任务的两个是 OperatingSystem 库和 <一个 href="http://robotframework.googlecode.com/hg/doc/libraries/String.html" rel="noreferrer">String 库.

Robotframework has several built-in libraries that add a lot of functionality. Two that you can use for this task are the OperatingSystem library and the String library.

您可以使用关键字获取文件来自操作系统库来读取文件,您可以使用 字符串库中的 Split to Lines 关键字将文件内容转换为行列表.然后只需使用 for 循环.

You can use the keyword Get File from the OperatingSystem library to read the file, and you can use the Split to Lines keyword from the String library to convert the file contents to a list of lines. Then it's just a matter of looping over the lines using a for loop.

例如:

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

这篇关于循环遍历 RobotFramework 中的文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆