0

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 |
| |
Sufian
  • 6,405
  • 16
  • 66
  • 120
user3918800
  • 21
  • 1
  • 2
  • Anything can be done if you design it properly. – duffymo Aug 08 '14 at 12:36
  • True no doubt. cn you point me in the right direction? – user3918800 Aug 08 '14 at 12:52
  • Nope, I've got a job. You need somebody who can write requirements, understand schema design and normalization, and how to code relational databases. If that's not you, find some help. – duffymo Aug 08 '14 at 12:57
  • So have I. I am not asking how to create a database schema. I am asking how to pass a dataset friom the database to the to the robot framework so that it can be interated through automatically by the Robot Framework and run as test cases. If you have no time to help me I am baffled as to why you are replying especially when you consider this to be a database issue which it is not. It is a data-driven Robot Framework related question and a perfectly valid one. – user3918800 Aug 08 '14 at 14:10
  • Note the answer below. Written by someone who knows what automated acceptance testing is and does not confuse it with creating a database. – user3918800 Aug 08 '14 at 16:38
  • Can't win 'em all. Call me back when your rep hits 10. – duffymo Aug 08 '14 at 17:17
  • No worries. If I ever get there I wil lol!! :-) – user3918800 Aug 21 '14 at 09:28

1 Answers1

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.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Just thought I would say that your final sentence is very useful and the way that I will be recommending. Cheers!! – user3918800 Aug 21 '14 at 09:29
  • This is exactly what we do for our Robot Framework, but hold the raw data in an external DB and either use the query Key Word to pull in any required test into Robot or use external files if we only need to populate the database for testing. – MichaelF Jul 29 '15 at 17:31