RobotFramework : Query xml database : Not able to do a validation on the result set

246 Views Asked by At

When I do a query against xml database and getting the query results as [('Testing',)]. I want to do a simple check against this value to make sure it is same as what's being entered via UI .

Should be equal     ${queryResults}     Testing 

But I am getting an error [('Testing',)] != Testing

Any idea what I am doing wrong here . Is there a way to get the value stripped out of all these symbols ( , ' , ??

1

There are 1 best solutions below

1
On

The return value of a query in the database library is a list of tuples - each list member is a response row, and the tuple is the column values in it.
Why? Because being a list you get them in the same order as the DB returned them, and a tuple - because it's a read-only object (this format actually comes from python's standard db protocol, not from RF's db library itself).

To get the value you're after you have to "unpack" the object; presuming you want to get the first column from the first row, that is the simplest approach:

${db value}=    Set Variable    ${queryResults[0][0]}

The first index is the row number, the second - the column.
Then you can compare ${db value} with your expected value.

Keep a couple of things in mind - the access indices of ordered object (lists, tuples) start from 0; and if there is no element at the index you specify - e.g. there was no such row or column in the DB response - this will cause an exception - a fail status in Robotframework.