1. Install Databaselibrary Library
Databaselibrary:
https://pypi.python.org/pypi/robotframework-databaselibrary/0.6
Online Documentation:
http://franz-see.github.io/Robotframework-Database-Library/
If you like to install a normal Python program, you can download the tar.gz file, unzip and run the setup.py file to install it.
Because we have already installed PIP in the previous section, it is easier and quicker to install with the PIP command:
Now just install the Databaselibrary Library, Python operates a different database, and you need to install the appropriate database driver.
Oracle Database driver: cx_oracle
Https://pypi.python.org/pypi/cx_Oracle
Cx_oracle is a Python extension module for connecting and manipulating Oracle databases, and supports Oracle 9.2 10.2
As well as the 11.1 version.
MySQL Database driver: pymysql
https://pypi.python.org/pypi/PyMySQL/
This contains a pure Python MySQL client library.
2. Operation of Oracle database 2.1 linked database
Connect Oracle Data:
Connect to Database Using Custom Params: Connects to the Oracle database keyword.
Cx_oracle: Connect the Oracle driver.
' username ', ' password ', ' 192.168.201.138:1521/ORCL ':
Connection database configuration information, user name, password, IP address, port number, database name.
2.2 Execute SQL statement
Execute SQL statement:
The Execute SQL String keyword is used to execute SQL statements. Note that the end of the SQL statement does not have a semicolon ";".
The Disconnect from Database keyword is used to break the connection to the data.
Output of the SQL statement results to the test report:
2.3 Execute SQL file
Execute SQL File:
The Execute SQL Script keyword is used to execute the SQL file.
${curdir} represents the current project path.
2.4 Adding system Keywords
The Execute SQL script provided in the database library does not support the inclusion of the Begin,end function in the SQL scripting file, for example:
To perform a pin error with the Execute SQL script keyword:
Then we need to add our own keywords.
Find the query.py file in the. \python27\lib\site-packages\databaselibrary\ directory.
Create the Execute_sql_funcfile function (keyword):
def execute_sql_funcfile (self, Sqlscriptfilename): "" "Execute SQL file, SQL file with begin,end function format" "" Sqlscriptfile = Open ( sqlscriptfilename) cur = nonetry:cur = Self._dbconnection.cursor () SQLStatement = "for line in sqlscriptfile:line = LINE.S Trip () if (Line.startswith ('/* ') ==1 and Line.endswith (' * * ') ==1): Continueif line.startswith (' # '): Continueif Line.startswith ('---'): Continueif (Line.startswith ('---') ==0 and Line.find ('---')!=-1): Line =line[:line.find ('---')]if (line = = "): Continuesqlstatement + = line + ' SQLStatement = sqlstatement.replace (' \ n ', ') print Sqlstatementif len (sqlst atement)! = 0:self.__execute_sql (cur, sqlstatement) self._dbconnection.commit () Finally:if cur:self._ Dbconnection.rollback ()
Then, search for Execute Sql Funcfile in the robot framework to find our custom keywords.
Execute the SQL script as follows:
Robot Framework (databaselibrary library Operations)