我熟悉在数据驱动的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 |
| |
答案 0 :(得分:1)
不幸的是,测试模板的使用或多或少需要在测试用例中对数据进行硬编码。但是,测试模板不仅仅是for循环的包装器。你可以这样做:
| | ${database_rows}= | Run sql query
| | ... | Select * from the_database where ...
| |
| | :FOR | ${row} | IN | @{database_rows}
| | | Suspend Region | @{row}
当然,这需要您编写“运行SQL查询”关键字或等效项来获取数据。
这样做的缺点是,所有排列都被视为具有多个关键字的单个测试用例,而不是具有单个关键字的多个测试用例。
如果您希望在数据库中每行有一个测试用例,您可以编写一个执行查询的脚本,使用查询结果生成测试套件文件,然后在生成的文件上运行pybot。