How to connect Robot Framework to various databases?

The mind, once stretched by a new idea, never regains its original dimensions

Robot framework connection to Database


Basic flow of working with database with any automation tool is same the way we will do it manually,
create connection to database -> send queries to db -> consume the results.

For automation tools like UFT we can used createobject methods without installing any drivers(API). But for most of the open source tools (libraries/frameworks) like selenium or robot framework we need drivers to create connectivity with database(db) for executing our queries.

All the db’s have their corresponding drivers.In our working example we have taken SQL server as our db.

1.Install Database library

2. Install SQL drivers.


Connect To Database pymssql ${dbName} ${dbUsername} ${dbPassword} ${dbHost} ${dbport}

Working with My SQL:-
We need the database library as above and mysql drivers as below :-
Install MySQL Drivers


Connect To Database pymysql ${dbName} ${dbUsername} ${dbPassword} ${dbHost} ${dbport}

Incase you face issues with using “Execute SQL string” keyword of the library, we can use the “Query” keyword as shown to have the the same effect.
Execute Query
[Arguments] ${queryString}
log ${queryString}
Comment ${status} ${result} Run Keyword And Ignore Error Execute Sql String ${queryString}
${status} @{queryResults} Run Keyword And Ignore Error Query ${queryString}
${query} Set Variable ${queryResults[0][0]}
Comment Remove extra characters
${query} Convert To String ${query}
${query} Replace String ${query} (' ${EMPTY}
${result} Replace String ${query} ',) ${EMPTY}
[Return] ${result}

Working with Sybase:-

One reply on “How to connect Robot Framework to various databases?”

Leave a Reply

Your email address will not be published. Required fields are marked *