0

我熟悉在数据驱动的 Robot Framework 测试中使用模板关键字,并且知道可以使用文本文件和 csv 文件等外部数据源来提供测试数据。但是,我工作的组织希望使用数据库中保存的数据作为测试用例数据的来源。有人知道这是否可能吗?我搜索了 Stack Exchange、Stack Overflow 和其他资源,但找不到答案或任何示例。

这是我熟悉的数据驱动方法的示例,只是为了让您了解我们现在所处的位置。

*** Settings ***
Library           Selenium2Library
Library           AFRCLibrary
| Test Template | Suspend Region

*** Variables ***


*** Test Cases ***
| Pillar 1 BPS 2019 Suspend Region | Pillar 1 | 2019 | BPS | BPS Region 1 | Pillar 1 BPS 2019 Suspend Region Comments |
| Pillar 2 FGS 2018 Suspend Region | Pillar 2 | 2018 | FGS | FGS Region 1 | Pillar 2 FGS 2018 Suspend Region Comments |

*** Keywords ***
| Suspend Region
| | [Arguments] | ${pillar} | ${year} | ${scheme} | ${region} | ${comments} |
| | Futures Open Application | http://ags125p01:8080/operationalsite/login | ff |
| | FuturesPublicsiteWM | root | gtn | http://ags125p01:8080/operationalsite/futures/maintain_budget |
| | Select Pillar | ${pillar} | ${year} |
| | Select Scheme | ${scheme} |
| | View |
| | Suspend And Confirm | ${region} | ${comments} |
| | Futures Close Application |
| |
4

1 回答 1

1

不幸的是,测试模板的使用或多或少需要在测试用例中对数据进行硬编码。然而,测试模板只不过是一个 for 循环的包装器。你可以这样做:

| | ${database_rows}= | Run sql query
| | ... | Select * from the_database where ...
| | 
| | :FOR | ${row} | IN | @{database_rows}
| | | Suspend Region | @{row}

当然,这需要您编写“运行 sql 查询”关键字或等效关键字来获取数据。

这样做的缺点是所有排列都被视为具有多个关键字的单个测试用例,而不是具有单个关键字的多个测试用例。

如果您想在数据库中的每行有一个测试用例,您可以编写一个执行查询的脚本,使用查询结果生成一个测试套件文件,然后在生成的文件上运行 pybot。

于 2014-08-08T14:59:25.847 回答