Automated testing and continuous integration solutions--Interface testing

Source: Internet
Author: User
Tags extend json in python

In a previous post, someone asked why the interface test was first in line. The reason is very simple, the interface is first, the interface is not good, the subsequent coding work is limited, not to get data. Traditional interface Test interface Automatic test interface Automation Continuous integration discussion of traditional interface testing

Do not know how the other people's home interface test is done. This is the Google plugin with postman. Testers follow the interface developer's wiki, design test cases, and then post/get. View the status or field of the returned JSON.

Weakness is not easy to manage case and inconvenient statistical results, execution to a manual to point, inefficient.

Interface Test Automation

I wrote a script in Python, wrote the case in Excel, then read Excel to implement the process, and automatically judged and counted the results to generate the report.
Case is so designed.

The script reads:

#encoding: Utf-8 import configparser import OS import xlrd import re import httplib import urllib from urlparse import URL Parse Import JSON import time import unittest import PDF Currentdir=os.path.split (Os.path.realpath (__file__)) [0] class Te St_class (): Def getexcel (self): Casefile=currentdir + '/case.xls ' if ((Os.path.exists (casefile)) ==fals E): Print "There is no case.xls under current path, please check."
        "Data=xlrd.open_workbook (casefile) Table = data.sheet_by_name (' login ') nrows = Table.nrows #行数
            Ncols = table.ncols #列数 #colnames = table.row_values (1) #某一行数据 for rownum in range (1,nrows):
                    For Col in range (3, ncols): Value=table.cell (rownum,col). Value if (col==3): Method=value if (col==4): Url=value return Table,nrows,ncols def Getexceldetail (self,table,row,ncols): #rownum = table.row_values (row) #某一行数据 for Col iN Range (0, Ncols): Value=table.cell (row,col). Value if (col==0): Caseid=value
                Print Caseid if (col==3): Method=value Print method if (col==4):  Url=value return Method,url,caseid def httpget (self,url): httpClient = None conn = Urlparse (URL) url=url.encode (' utf-8 ') try:httpclient = Httplib.
            Httpconnection (Conn.netloc, timeout=10) httpclient.request (' GET ', URL) # response is the HttpResponse object Response = Httpclient.getresponse () print response D0=response.read () d0=d0.de
                Code (' Unicode_escape ') except Exception, E:print e finally:if httpClient:
        Httpclient.close () return response.status,d0 def httppost (self,url): HttpClient = None
conn = urlparse (URL) url=url.encode (' Utf-8 ')        Try:header = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/ Plain "} httpClient = Httplib. Httpconnection (Conn.netloc, timeout=30) httpclient.request ("POST", url) response1 = Httpclient.get
            Response () D1=response1.read () d1=d1.decode (' Unicode_escape ') except Exception, E: Print e finally:if httpClient:httpClient.close () return Response1.statu
 S,d1

The

code is a bit too much, not written down. is actually a process of reading Excel, a post, a get. The
also follows a parsing process for JSON. began to think that a dictionary was done, and later found that some {} nested in several layers. The
ended up with a recursive fix.

#! /usr/bin/env python #coding =utf-8 import urllib2 Import JSON Class Readjson (): def read (Self,obj,key): Colle
                ct = list () for k in obj:v = Obj[k] If isinstance (V,STR) or Isinstance (V,unicode): If key== ': Collect.append ({k:v}) Else:collect.appen D ({str (key) + ".")
                +K:V}) elif Isinstance (v,int): If key== ': Collect.append ({k:v}) Else:collect.append ({str (key) + ".")
                +K:V}) elif Isinstance (v,bool): If key== ': Collect.append ({k:v}) Else:collect.append ({str (key) + ".") 
                +K:V}) elif Isinstance (v,dict): Collect.extend (Read (v,k)) elif isinstance (v,list):  Collect.extend (ReadList (v,key)) return collect Def readlist (self,obj,key): collect =List () for index, 

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.