1
votes

I'm trying to check if an item is in the database before attempting to delete it as part of my test setup.

The issue: The 'Check if Exists in Database' keyword works on its own, but not when combined with the built in keyword 'Run Keyword and Return Status'.

that gets the error: 'InterfaceError: not a query'

Code is below:

***Settings***

Documentation     RF DB Test

Library    DatabaseLibrary


***Variables***
${token}    '<token>'

***Test Cases***

Set Log Level
    Set Log Level     TRACE

Connect to DB
     Connect To Database Using Custom Params     cx_Oracle  <connection details>

Cleanup DB
    ${EntryExists}=     Run Keyword and Return Status       Check if Exists in Database select * from MY_TABLE where token=${token}

Edit

Thanks for your formatting answers and suggestions folks. I also received the error for this line

Query       delete from MY_TABLE where token=${token}

10:14:40.984 FAIL InterfaceError: not a query 10:14:40.984 DEBUG Traceback (most recent call last): File "...Python\Python35\lib\site-packages\DatabaseLibrary\query.py", line 56, in query allRows = cur.fetchall()

Basically, I was trying to use the delete command with the Query keyword, but found that the undocumented keyword 'Execute Sql String' worked

Execute Sql String       delete from MY_TABLE where token=${token}
2
It seems to be a problem with the sql formed. assign the sql to a string variable and then pass that to Check if Exists in Database ${sql} - Shijo
it looks like you have only one space between Check if Exists in Database and the query statement. Also, please show the complete and exact error message. - Bryan Oakley

2 Answers

0
votes
  1. Keep your indentation consistent. I would suggest to use 4 spaces (set your IDE and that's it). I can see 4 spaces, 5 spaces, 2 spaces and most importantly: only one space between Check if Exists in Database and select * from MY_TABLE where token=${token}. Note that RF takes more than two spaces as delimeter (see: http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#plain-text-format) but one space is not enough.
  2. Why did you created separate Test Case for every keyword?

I suppose your Test Case could look like:

***Test Cases***
Nice Name Of My Test Case
    [Documentation]    Let's not forget to describe
    [Setup]    Set Log Level    TRACE
    [Teardown]    Disconnect From Database
    Connect To Database Using Custom Params    cx_Oracle    <connection_details>
    ${entry_exists}    Run Keyword And Return Status       Check If Exists In Database    select * from MY_TABLE where token=${token}
    Run Keyword If    '${entry_exists}' == 'True'    DB Cleanup

Obviously all the current steps aren't enough for any meaningful Test Case, they should probably end up as a Test Setup, but that's, I believe, what you mean.

0
votes

Add 4 spaces or tab after keyword "Check if Exists in Database" mentioned below.

${EntryExists}=     Run Keyword and Return Status       Check if Exists in Database     select * from MY_TABLE where token=${token}

"Check if Exists in Database" keyword will return Boolean value(Pass/ Fail). So you don't required to use "Run Keyword And Return Status"