Robot Framework data-driven automation testing: Can data derived from a database be used as a data source for a test template?

不打扰是莪最后的温柔 提交于 2019-12-06 15:59:07

问题


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

回答1:


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}

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.

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.



来源:https://stackoverflow.com/questions/25203679/robot-framework-data-driven-automation-testing-can-data-derived-from-a-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!