Robot Framework keyword Customization

Source: Internet
Author: User

There are three ways to customize a keyword:

1. Right-click-->new User Keyword in the Automation catalog

2. Select the steps in the case (multiple lines are optional), right-click-->extract Keyword

3. Write your own module, custom method, automation project reference module, the corresponding module method is a keyword

Methods 1 and 2 are virtually the same, but no Method 3 is free, and in automated projects it is generally a method of mixing

To use the keyword first you need to apply the module:

Module--library (py file or module name in local python installation environment lib--sitepackage, such as Httplibrary.http--http interface test) can be referenced in both directory and suite

Once the package reference is complete, you can use the keyword directly in the case created under suite, F5 can see which keywords are in the corresponding module

(shortcut key: When the keyword is not remembered, enter some keywords in case, shortcut key--ctrl+alt+ space, the keyword selection area appears)

The custom keyword is to write the module yourself and then automate the project reference.

#-*-coding:utf-8-*-ImportMySQLdbclassStorelib:def __init__(self): Self.conn=MySQLdb.connect (Host="127.0.0.1", Port=8888, DB="dbname", the user="Hito", passwd="*********", CharSet='UTF8',) Self.cursor=self.conn.cursor ()def __del__(self): Self.conn.close ()defselect_sql (Self, SQL): Self.cursor.execute (SQL) Items=Self.cursor.fetchall ()returnItemsdefexec_sql (Self, SQL): Self.cursor.execute (SQL) Self.conn.commit ()

This is a MySQL statement execution related script, with select_sql and exec_sql two keywords, reference the script file, you can use the previous two keywords in the case

(There is a hole, reference module if the name of the file and the internal class is inconsistent, the reference is unsuccessful, so make sure the name is the same.)

Robot Framework keyword Customization

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.