Robot Framework 数据驱动自动化测试:从数据库中导出的数据能否用作测试模板的数据源? [英] Robot Framework data-driven automation testing: Can data derived from a database be used as a data source for a test template?

查看:19
本文介绍了Robot Framework 数据驱动自动化测试:从数据库中导出的数据能否用作测试模板的数据源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am familiar with using template keywords in data-driven Robot Framework testing and know that external sources of data such as text files and csv files can be used to provide test data. However, the organisation I work for wants to use data held in a database as a source for test case data. Does anybody know if this is possible? I have searched Stack Exchange, Stack Overflow and other resources but cannot find an answer or any examples.

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

Here is an example of the data-driven approach I am familiar just to give you an idea of where we are now.

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

推荐答案

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

Unfortunately, the use of test templates more-or-less require that the data is hard-coded in the test case. However, the test template is not much more than a wrapper around a for loop. You could do something like this:

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

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

Of course, this requires that you write the "Run sql query" keyword or an equivalent to fetch the data.

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

The downside of this is that all of the permutations are considered a single test case with multiple keywords, versus multiple test cases with a single keyword.

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

If you want to have one test case per row in a database, you could write a script that does the query, generates a test suite file using the results of the query, and then runs pybot on the generated file.

这篇关于Robot Framework 数据驱动自动化测试:从数据库中导出的数据能否用作测试模板的数据源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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