Robot Framework Tutorial (5)-Connecting the Oracel database

Source: Internet
Author: User
Tags writing test scripts

The Robot Framework provides a variety of library libraries. Where the database library can be used to connect operational databases.

1. Installing the database Library

Open the Robot framework website, find the database library, the official website provides Java and Python two version of the database library, here I use the Python version, the address is

http://franz-see.github.io/Robotframework-Database-Library/

The Software Requirement section is the operational environment requirements of the database library, including the specific requirements

Python/jython/ironpython

Robotframework

A Database API Specification 2.0 Python Module so you'll use it to connect to the database.

One of the Python and robot framework we have installed, we now need to install a database API Specification 2.0 Python module, that is, the Python modules used to connect the databases.

The logic here is this way, the database library is actually a proxy module in the middle of the Robot framework and database Interfaces, the Robot framework through the database library The provided interface, indirectly called the database Interfaces, thus implements the purpose of manipulating the databases.

Open the Database Interfaces page, locate the Oracle API driver and find your installation file for the current Python environment version, download and install

http://sourceforge.net/projects/cx-oracle/files/

After that, download the installation databaselibrary.

After the installation is complete, you can see the Database Library folder and the Cx_oracle.pyd file in your \python27\lib\site-packages directory

2. Writing test scripts

Run ride and press F5 to view the database library keywords.

We write a test case for a database query with the following script:

Connect to Database Using Custom Params    cx_oracle    'bpm','BPM ','orcl'@{data}    query    from  sys_ Userlog many    @{data}log    ${data[0][1]}${count}    Get length    ${data}log    ${count} Disconnect from Database

Run the script with the following results

After running to view the log, the table in Chinese has all become garbled. The default encoding for cx_oracle is not Utf-8 and needs to be converted manually. Databaselibrary itself does not provide a conversion function, in order to solve this problem, we need to extend the databaselibrary.

3. Solve Chinese garbled problem in database library

Open the query.py file under the installation directory and add a decode function to decode the string

def decode (Self,customstr,mode):        return customstr.decode (mode)

Change the test script to increase the transcoding process

Run again, get the system output, test pass

Summarize:

This completes the robot framework connection to the database and operates the process. In the process of use, we also need to design testcase and write SQL for the business logic.

In the next article, we will describe the robot framework when writing test scripts, using the IF and for keywords for process control.

Robot Framework Tutorial (5)-Connecting the Oracel database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.