0

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 ( , ' , ??

A. Kootstra
  • 6,827
  • 3
  • 20
  • 43
mac
  • 53
  • 3
  • 12
  • Can you provide the example code that creates/fills the `${queryResults}` variable? The best approach is not to filter the variable after the fact, but to make sure your result is correct in the first place. – A. Kootstra Apr 04 '18 at 07:23

1 Answers1

0

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.

Todor Minakov
  • 19,097
  • 3
  • 55
  • 60