How to connect Robot Framework to various databases? – User friendly Tech help
The mind, once stretched by a new idea, never regains its original dimensions
n
nSolution:-
n
nBasic flow of working with database with any automation tool is same the way we will do it manually,
ncreate connection to database -> send queries to db -> consume the results.
n
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.
n
nAll the db’s have their corresponding drivers.In our working example we have taken SQL server as our db.
n
nPre-requisites:-
n1.Install Database library
nhttp://franz-see.github.io/Robotframework-Database-Library/
n
2. Install SQL drivers.
n
https://pypi.python.org/pypi/pymssql/2.1.0
n
Example:-
n
Connect To Database pymssql ${dbName} ${dbUsername} ${dbPassword} ${dbHost} ${dbport}
n
nWorking with My SQL:-
nWe need the database library as above and mysql drivers as below :-
nInstall MySQL Driversn
Example:-
n
Connect To Database pymysql ${dbName} ${dbUsername} ${dbPassword} ${dbHost} ${dbport}
n
nNote:–
nIncase 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.
n
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}
n
nWorking with Sybase:-
n
Download and Install JayDeBeApi
n
n
n
n