Solution:-
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.
Pre-requisites:-
1.Install Database library
http://franz-see.github.io/Robotframework-Database-Library/
2. Install SQL drivers.
https://pypi.python.org/pypi/pymssql/2.1.0
Example:-
Connect To Database pymssql ${dbName} ${dbUsername} ${dbPassword} ${dbHost} ${dbport}
We need the database library as above and mysql drivers as below :-
Install MySQL Drivers
Example:-
Connect To Database pymysql ${dbName} ${dbUsername} ${dbPassword} ${dbHost} ${dbport}
Note:–
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?”
this is not about various databases but only about MySQL