Developing system Keywords

Source: Internet
Author: User

Before three months of training in 51testing, the automated testing framework that has been learning is the Java testng Framework. The first job after graduation was to test the development engineer, and the new company asked to use the robot framework for automated testing. Watch the worm's video, there is a great harvest, there are some of their own ideas. Robot website provides a lot of libraries, there are a lot of keywords, but if you are not satisfied with the existing keywords, you can develop your own system each keyword.

For example, Selenium2library Library, after downloading, is placed in the Python directory under the Site-packages package lib, so we develop the System keyword also put in this path.

1, for example, want to develop a subtraction system keyword, we first write a calc.py file

1 #coding =utf-8
 2 
 3 class Calc (object):
 4     def Add (self,a,b):
 5         C=int (a) +int (b)
 6         Return c
 7 
 8     def sub (self,a,b):
 9         c=int (a)-int (b)         return c 
12 # Verify that the Python file is correct for
c=calc ()
print C.add (1,4)

2. Create a new Main.robot file, call the Add, sub method defined above

1 ***settings***
 2 Library                 Calc
 3 
 4 ***test cases***
 5 case1
 6     ${result}       Add         5       6
 7     log             ${result}
 8 
 9     ${result}       Sub         8       9
10     Log             ${result}

3, in order to run, there must be a __init__.py file, under Python-lib-site-packages a new Calc folder, the following new __init__.py file

1 from Calc Import Calc
2 
3 __version__= ' 0.1 '
4 
5 class Calccode (Calc):
6     Robot_library_scope = ' GLOBAL '

which First import the Calc class from calc.py and then define the Calccode integrated Calc class so that it becomes a library, in Main.robot, declares the library to be the Python-lib-site-packages-calc directory, and then use the Add in the Calc class , sub method, execution.

The results are as follows:

View log.html in the work area,

has been printed out.

Thank you for your reading and hard work.

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.