How can we validate tabular data in robot framework?

2.3k views Asked by At

In Cucumber, we can directly validate the database table content in tabular format by mentioning the values in below format: | Type | Code | Amount | | A | HIGH | 27.72 | | B | LOW | 9.28 | | C | LOW | 4.43 | Do we have something similar in Robot Framework. I need to run a query on the DB and the output looks like the above given table.

1

There are 1 answers

3
Bryan Oakley On

No, there is nothing built in to do exactly what you say. However, it's fairly straight-forward to write a keyword that takes a table of data and compares it to another table of data.

For example, you could write a keyword that takes the result of the query and then rows of information (though, the rows must all have exactly the same number of columns):

| | ${ResultOfQuery}= | <do the database query>
| | Database should contain  | ${ResultOfQuery}
| | ... | #Type    | Code    | Amount
| | ... | A        | HIGH    | 27.72
| | ... | B        | LOW     | 9.28
| | ... | C        | LOW     | 4.43

Then it's just a matter of iterating over all of the arguments three at a time, and checking if the data has that value. It would look something like this:

**** Keywords *** 
| Database should contain
| | [Arguments] | ${actual} | @{expected}
| | :FOR | ${type} | ${code} | ${amount} | IN | @{expected}
| | | <verify that the values are in ${actual}>

Even easier might be to write a python-based keyword, which makes it a bit easier to iterate over datasets.