Robot Framework 使用 csv 和 for 循环运行多个测试用例
我有一个 csv
文件,其中包含 TestcaseID、Testcase Description、Tag 和测试用例的输入,如下所示
I have a csv
file which contains TestcaseID,Testcase Description,Tag and input to the testcase like below
TUNG001,sample1,sampletag1,01
TUNG002,sample2,sampletag2,02
我想遍历这个文件并获取每一行并使用一个通用函数启动一个测试用例(这将是 TestcaseID).经过研究,我发现这个功能在Robot Framework中没有实现.
I want to iterate through this file and fetch each row and start a test case(which will be TestcaseID) using a common function. After researching, I found out that this feature is not implemented in Robot Framework.
请有人建议我如何实现这一目标.
Someone please suggest how I can achieve this.
这里是您可以这样做的方法,下面是更好的方法.
Here's how you COULD do this, below this is are better ways to do it.
- 使用操作系统读取整个文件
GetFile
- 由于每一行都有一个新的测试用例,因此使用 String 关键字在换行符上拆分文件内容
分行
- 使用字符串关键字
拆分字符串
将行拆分为测试用例和输入. - 使用操作系统
运行
在 for 循环中执行每个测试.
您应该使用资源和变量文件来定义每个测试用例的输入,然后以文件作为输入执行整个测试套件(或指定的测试用例).这基本上可以免费为您完成所有这些工作.
Instead of doing that way, you should instead use resource and variable files to define the input for each of the testcases, and then just execute the entire test suite (or specified test cases) with the file as input. This will essentially do all of that work for you for free.