The Database Library for Robot Framework allows you to query a database and verify the results.
It requires an appropriate Python module to be installed separately - depending on your database, like e.g. oracledb
or pymysql
.
The library consists of some keywords designed to perform different checks on your database. Here you can find the keyword docs.
- Python
- Robot Framework
- Python database module you're going to use - e.g.
oracledb
pip install robotframework-databaselibrary
*** Settings ***
Library DatabaseLibrary
Test Setup Connect To My Oracle DB
*** Keywords ***
Connect To My Oracle DB
Connect To Database
... oracledb
... dbName=db
... dbUsername=my_user
... dbPassword=my_pass
... dbHost=127.0.0.1
... dbPort=1521
*** Test Cases ***
Person Table Contains Expected Records
${output}= Query select LAST_NAME from person
Length Should Be ${output} 2
Should Be Equal ${output}[0][0] See
Should Be Equal ${output}[1][0] Schneider
Person Table Contains No Joe
${sql}= Catenate SELECT id FROM person
... WHERE FIRST_NAME= 'Joe'
Check If Not Exists In Database ${sql}
See more examples in the folder tests
.
The library is basically compatible with any Python Database API Specification 2.0 module.
However, the actual implementation in existing Python modules is sometimes quite different, which requires custom handling in the library. Therefore there are some modules, which are "natively" supported in the library - and others, which may work and may not.
- ksycopg2