Database Library for Robot Framework
The Database Library for Robot Framework allows users to query databases and verify results within Robot Framework tests. It is currently at version 2.4.1 and maintains an active release cadence, with frequent minor and patch updates to introduce new features, fix bugs, and enhance compatibility.
Warnings
- deprecated Keywords `Check If Exists In Database` and `Check If Not Exists In Database` are deprecated and will be removed in future versions.
- gotcha The library itself does NOT include database drivers. You must manually install the appropriate Python DB API 2.0 compliant driver (e.g., `pip install pymysql` for MySQL, `pip install psycopg2` for PostgreSQL) for the database you intend to connect to.
- breaking Several parameters were renamed in version 2.0, notably `sqlScriptFileName` to `sql_script_file` and `sansTran` to `no_transaction`.
- gotcha When using `Check Query Result`, type mismatch issues can occur if comparing numeric database results (e.g., INTEGER) directly with string literals from Robot Framework.
Install
-
pip install robotframework-databaselibrary -
pip install sqlparse -
pip install pymysql
Imports
- DatabaseLibrary
Library DatabaseLibrary
Quickstart
*** Settings ***
Library DatabaseLibrary
*** Test Cases ***
Example Database Interaction
Connect To Database sqlite3 :memory:
Execute SQL String CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)
Execute SQL String INSERT INTO users (name) VALUES ('Alice')
Execute SQL String INSERT INTO users (name) VALUES ('Bob')
${result}= Query SELECT name FROM users WHERE id = 1
Check Query Result SELECT name FROM users WHERE id = 1 equals Alice
Check Row Count SELECT * FROM users == 2
Disconnect From Database