Python+robot Framework Interface Automation testing

Source: Internet
Author: User

Python+requests implementation of the interface request has been introduced in the previous chapter, there is no understanding or doubt can be accessed

Python+request Interface Automation Framework

At present, we need to consider how to implement the keyword-driven implementation of interface automation output, through the encapsulation of the keyword to achieve a certain sense of the script and the use of the separation!

Robot framework installation is not too much, online data comparison too much ~

Instance:!!!!!

Step one: Create a new project

The test project can be directory or file storage, format can be in TXT,TSV or HTML format, recommend project selection directory and txt, so as to facilitate management

Step two: New test sets

Test sets like test items, you can also catalog and file storage, format can also be used in TXT,TSV or HTML format, recommended test set Select File storage and txt

Step three: Create a new test case

———————— this series of base support components is created after the ———— directory structure is ————————

Here's how to create a use case on this framework!!!

We know! The RF is driven by the keyword, and is identified by the test library and the test object is manipulated.

So how do you use keywords? First we need to import the TEST library!!!

Step four: Add Lib, the need for the application to the test library are in, in fact, you can also use URLLIB2 this library to get URL content information

Ps:json and requests are all imported libraries from Python! (queryprdodcut.py is a library of my personal package)

F5 can be queried by the method of the Lib, to see if they need to use which to choose which application

Step five, method application, hold down CTRL to have the method that can be described

Step six: Output a case of a scene, here is a case I personally created (currently in the third library and its own method output case)

The 1.set variable represents the Set Variable 2. The Catenate representative assembles multiple parameters together 3.requests.get represents the use of the Resquests library to get response4.should be qeual as strings using a GET request Whether the representation is equal to the expected value is an assertion (refer to http://blog.sina.com.cn/s/blog_7f66d4ea0101k3fl.html)

5.log Representative View Content

Special Note: This method allows the use of Rep.status_code and rep.content

It is cumbersome to use the tape, so many entries have been entered to complete a request, so I encapsulated a GET Request library for HTTP (of course checkvalue is also a function of my personal encapsulation ~)

The specific implementation is as follows:

__author__ = ' Niuzhigang ' #!/usr/bin/env python#*-coding:utf-8-*-#encoding =utf-8import jsonimport  requestsclass Queryproduct (object):    @classmethod    def interfacetest (SELF,REQADRESS,REQINTERFACE,REQC,REQD, Floattimeout ):        Requrl = reqadress + reqinterface        print "Print requrl--->" +requrl        header={"Content-type": " Application/json "}        reqparams = {' c ': Reqc, ' d ': reqd}        Reqparam = Json.dumps (reqparams,encoding= ' utf-8 ', ensure _ascii=false)        print  ' Print reqparams---> ' +reqparam        timeout = float (floattimeout)        # GET request Result        Getrep = Requests.get (Url=requrl,headers=header, params=reqparams,timeout=timeout)        print "Get req Result---> "+getrep.text        return Getrep.text

  

So that's the problem? How do you use a library of your own definition? (specifically how to develop a bit of Python basic knowledge can be ~ I do not say ~)

Here's a list of personal-packaged libraries to play ~

PS: Self-encapsulated library can be printed according to their own needs of the log ~ implementation method is the function of print!!!

Operating RF results are as follows:

Step Seven: View the results of the decision, perform play key or F8 (PS blue are hyperlinks can be played as: Want to open a specific case click

can be viewed) the results are as follows:

Add: Currently only implement the interface infrastructure, follow-up will maintain more such as sending reports, email, etc. and more keywords package ~ ~ ~

Of course, this also supports UI Automation such as the Web import Selenium library to enable UI Automation

I also just contact RF, I hope we have a lot of mutual exchange!!!

Python+robot Framework Interface Automation testing

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.