Robot Framework Database Automation

Source: Internet
Author: User
Tags number sign

9 Robot Framework Database Automation 9.1 Robot Framework Database Automation Environment build 9.1.1 Installation Preparation

1) Download the Robotframework-database-library file from the network disk

NET Disk: Http://pan.baidu.com/s/1skZ3oDn

Official website: https://pypi.python.org/pypi/robotframework-databaselibrary/0.6

2) Unzip the compressed package.

9.1.2 Installing the Database-library Library

1, under DOS switch to the next robotframework-database-library decompression directory, execute python setup.py install

2. After installation, there is a databaselibrary folder in the C:\Python27\Lib\site-packages Python installation directory stating that the installation was successful.

9.1.3 Installing Pymysql Client Driver

1) Download the installation file

Official website: https://pypi.python.org/pypi/PyMySQL/

NET Disk: http://pan.baidu.com/s/1nvtUo1j

2) Unzip the package

3) Install Pymysql Client

Under DOS switch to the next Pymysql extract directory, execute python setup.py install

9.1.4 Installing cx_oracle Client Driver

1) Download the installation file

Official website: https://pypi.python.org/pypi/cx_Oracle

NET Disk: Http://pan.baidu.com/s/1geAflzd

2) Install Cx_oracle Client

Click File installation and install it by default.

9.2 Operating MySQL database 9.2.1 installing MySQL database server

MySQL Database server Installation here will not talk about, everyone to see the relevant tutorials can be. My database is installed under C:\Program files\mysql\mysql Server 5.5.

9.2.2 MySQL database environment variable configuration

If you want to connect the MySQL database directly under DOS, you need to add the C:\Program files\mysql\mysql Server 5.5\bin path to the PATH environment variable.

9.2.3 operating the database under DOS

1. Connect MySQL database under DOS and view the project database of investment management system of EDB

2. Query the T_school_type table data.

9.2.4 The database connection database under the robot framework.

Project Example one: connecting the database

1. Create a new mysql_db test suite (new suite) and create a new mysql_test test case.

2. Import the Databaselibrary library to the mysql_db test suite

3. connect MySQL database with connect to database using Custom params keyword

Press F5 to see a description of the connect to Database Using the Custom params keyword, as

"PSYCOPG2" refers to the database type, where MySQL is used, so it is pymysql

"Connection parameters" database= ' recruit_students ', user= ' root ', password= ' root ', host= ' localhost ', port=3306

Connect database configuration information, database name, user name, password, IP address, port number.

Code implementation:

Operation Result:

9.2.5 Disconnect from database key to close the connection

Press F5 to see a description of the disconnect from database keyword, as

Disconnect from Database []

Used to turn off data connections.

Project Examples:

9.2.5 Execute SQL String execution SQL statement keyword

Press F5 to view a description of the Execute SQL string keyword, such as

Execute Sql String [sqlString]

Used to execute the SQL statement "sqlString indicates that the parameter is an SQL statement"

Project Examples:

Operation Result:

9.2.6 query keyword Execute SQL query statement

Press F5 to see a description of the query keyword, such as

Query [Selectstatement]

SQL statement for executing the SQL statement "selectstatement indicates that the parameter is a query"

Usually there is no point in querying, and we will pass the results of the query to a variable to see the results of the query.

Official examples:

Project Examples:

Operation Result:

9.2.7 Execute SQL script keyword execution sql file

Press F5 to view a description of the Execute SQL script keyword, such as

Execute Sql Script [Sqlscriptfilename]

Used to execute the SQL file "Sqlscriptfilename indicates that the parameter is a SQL execution file that needs to be executed"

Official examples:

The SQL command will be delimited by semicolons of the (';').

For example: delete person_employee_table; Delete delete employee_table person_table;

In addition, the last SQL command can omit its trailing semicolon.

For example: delete person_employee_table; Delete delete employee_table person_table;

In view of this, this means that you can expand your SQL command in a few lines.

For example: delete person_employee_table; Delete delete employee_table person_table;

However, the line is processed from a number sign (' # ') to a comment line. Therefore, the contents of the row will not be executed.

For example: #删除桥接表第一 ... Remove from person_employee_table;# ... Then bridge the table. Delete delete employee_table person_table;

Project Examples:

Steps:

1. Create a new Sqlscriptfile.sql file in the project

2. Write a query statement in the file select * from T_school_type;

Code implementation:

${execdir} indicates the current project (D:\PROJECT\EDUCATIONAL\TEST_PROJECT1) path

Operation Result:

9.3 Operating Oracle Database 9.3.1 operating Oracle database under DOS

1. under DOS, enter sqlplus sys/ password as sysdba Connect to the Oracle database.

2. Create a test_db table space.

SQL statement:

Create Tablespace test_db

DataFile ' D:\oracle\xny\product\11.2.0\dbhome_1\oradata\test.dbf '

Size 2024m autoextend on;

3. Create a user for the table space.

Create user syntax:

Create user Test_user--username

Identified by "xny123"--Password

Default Tablespace test_db--Specify a table space

4. authorize the new user.

SQL statement: Grant DBA to Test_user;

5. Create a new table dept.

SQL statement: CREATE TABLE Dept (DNO Number (2), name Varchar2 (Ten), loc varchar2 (20));

6. Insert 3 data into the newly created table.

SQL statements:

INSERT INTO Dept (DNO,NAME,LOC) VALUES (1, ' Develop ', ' Shenzhen ');

INSERT INTO Dept (DNO,NAME,LOC) VALUES (2, ' Test ', ' Shenzhen ');

INSERT INTO Dept (DNO,NAME,LOC) VALUES (3, ' Admin ', ' Shenzhen ');

Commit

7. Query Table Dept Data

SQL statement: SELECT * FROM dept;

9.3.2 operating the Oracle database under the robot framework

A) Project example preparation work:

    1. Create a new oracle_db test suite (new suite) with a new Oracle_project project, and create a new oracle_test1 test case.

2. Import the Databaselibrary library to the oracle_db test suite.

3. Connect to Oracle database

Description

Connect to Database Using Custom Params: Connects to the Oracle database keyword.

Cx_oracle: Connect the Oracle driver.

' username ', ' password ', ' 127.0.0.1:1521/ORCL ':

Connection database configuration information, user name, password, IP address, port number, database name.

Operation Result:

II) Project Example: Query the Dept table data created above.

Code implementation:

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.

Operation Result:

Note: Oracle's next related keyword operation is the same as the MySQL operation, which is not covered here.

Robot Framework Database Automation

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.