Skip to main content

Database Library for Robot Framework

Project description

Robot Framework Database Library

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.

Requirements

  • Python
  • Robot Framework
  • Python database module you're going to use - e.g. oracledb

Installation

pip install robotframework-databaselibrary

Usage examples

Basic usage

*** 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}

Handling multiple database connections

*** Settings ***
Library          DatabaseLibrary
Test Setup       Connect To All Databases
Test Teardown    Disconnect From All Databases

*** Keywords ***
Connect To All Databases
    Connect To Database    psycopg2    db    db_user    pass    127.0.0.1    5432
    ...    alias=postgres
    Connect To Database    pymysql    db    db_user    pass    127.0.0.1    3306
    ...    alias=mysql

*** Test Cases ***
Using Aliases
    ${names}=    Query    select LAST_NAME from person    alias=postgres
    Execute Sql String    drop table XYZ                  alias=mysql

Switching Default Alias
    Switch Database    postgres
    ${names}=    Query    select LAST_NAME from person
    Switch Database    mysql
    Execute Sql String    drop table XYZ

See more examples in the folder tests.

Database modules compatibility

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.

Python modules currently "natively" supported

Oracle

  • oracledb
    • Both thick and thin client modes are supported - you can select one using the driverMode parameter.
    • However, due to current limitations of the oracledb module, it's not possible to switch between thick and thin modes during a test execution session - even in different suites.
  • cx_Oracle

MySQL

PostgreSQL

MS SQL Server

SQLite

Teradata

IBM DB2

ODBC

Kingbase

  • ksycopg2

Further references (partly outdated)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

robotframework-databaselibrary-1.4.tar.gz (16.1 kB view details)

Uploaded Source

Built Distributions

File details

Details for the file robotframework-databaselibrary-1.4.tar.gz.

File metadata

File hashes

Hashes for robotframework-databaselibrary-1.4.tar.gz
Algorithm Hash digest
SHA256 6e6473915aca314cd8d0979e5f77020602398e7b83abf72fc86cea098721309f
MD5 d02d1edf1e0c3d49754ad136836af71c
BLAKE2b-256 268abe95b5e4030d1fd11ecdf4365a996f0c9dd7288476f8f63e22af0c37d64a

See more details on using hashes here.

File details

Details for the file robotframework_databaselibrary-1.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for robotframework_databaselibrary-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2186dba399d5c7bc6eebcb3ef0a8db84440dc1ad1dfd709b22d02136d075dc8a
MD5 7446be7a1a09cf97a747219360e5004b
BLAKE2b-256 65ebe4e96f2470f694432d779c127b2ac7b2ba7c67aa03136b2e72d8c63a4241

See more details on using hashes here.

File details

Details for the file robotframework_databaselibrary-1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for robotframework_databaselibrary-1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e2808195f5425ecbf2a29af432bf6961cff58e033309bf08e01b11475856a5d5
MD5 26f8547c23775728da3686579bfdcb20
BLAKE2b-256 02b1a7f065b90939ecc2ef3462477647539aa032c137250ba7ff61e4e2cc286a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page