Äú¿ÉÒÔ¾èÖú£¬Ö§³ÖÎÒÃǵĹ«ÒæÊÂÒµ¡£

1Ôª 10Ôª 50Ôª





ÈÏÖ¤Â룺  ÑéÖ¤Âë,¿´²»Çå³þ?Çëµã»÷Ë¢ÐÂÑéÖ¤Âë ±ØÌî



  ÇóÖª ÎÄÕ ÎÄ¿â Lib ÊÓÆµ iPerson ¿Î³Ì ÈÏÖ¤ ×Éѯ ¹¤¾ß ½²×ù Model Center   Code  
»áÔ±   
   
 
     
   
 ¶©ÔÄ
  ¾èÖú
PythonʵÏÖhttp½Ó¿Ú×Ô¶¯»¯²âÊÔ
 
  5085  次浏览      28
 2019-3-20
 
±à¼­ÍƼö:
±¾ÎÄÀ´×Ôcsdn£¬±¾ÎĽéÉÜÁËhttp½Ó¿Ú×Ô¶¯»¯²âÊÔPythonʵÏÖµÄʵ¼Ê²Ù×÷ÒÔ¼°½Ó¿ÚµÄ×ܽᣬϣÍû¶ÔÄúµÄѧϰÓÐËù°ïÖú¡£

½Ó¿Ú²âÊÔ³£ÓõŤ¾ßÓÐfiddler£¬postman£¬jmeterµÈ£¬Ê¹ÓÃÕâЩ¹¤¾ß²âÊÔʱ£¬ÐèÒªÁ˽ⳣÓõĽӿÚÀàÐͺÍÇø±ð£¬±ÈÈçÎÒÓõ½µÄpostºÍgetÇëÇ󣬱íÃæÉÏ¿´getÓÃÓÚ»ñÈ¡Êý¾ÝpostÓÃÓÚÐÞ¸ÄÊý¾Ý£¬Á½Õß´«µÝ²ÎÊýµÄ·½Ê½Ò²Óв»Ò»Ñù£¬getÊÇÖ±½ÓÔÚurlÀïͨ¹ý?À´Á¬½Ó²ÎÊý£¬¶øpostÔòÊǰÑÊý¾Ý·ÅÔÚHTTPµÄ°üÌåÄÚ(request body)£¬Á½Õߵı¾ÖʾÍÊÇTCPÁ´½Ó£¬²¢ÎÞ²î±ð£¬µ«ÊÇÓÉÓÚHTTPµÄ¹æ¶¨ºÍä¯ÀÀÆ÷/·þÎñÆ÷µÄÏÞÖÆ£¬µ¼ÖÂËûÃÇÔÚÓ¦Óùý³ÌÖÐÌåÏÖ³öһЩ²»Í¬¡£¾ßÌåµÄ¿ÉÒԲο¼´Ë²©ÎÄ£¬½²½âµÄ±È½ÏͨË×Ò×¶®¡£ÕâЩÔÚ¹¤¾ßÖпÉÒÔÖ±½ÓÑ¡Ôñ£¬pythonÐèÒª½èÖúrequests°ü¡£

È·¶¨ºÃ½Ó¿ÚÀàÐͺó£¬ÐèÒª×öµÄ¾ÍÊÇ×¼±¸²âÊÔÊý¾ÝºÍÉè¼Æ²âÊÔÓÃÀýÁË£¬²âÊÔÓÃÀý±ÈÈç˵¿ÉÒÔÅжϷµ»Ø×´Ì¬ÏìÓ¦Â룬»òÕß¶Ô·µ»ØÊý¾Ý½øÐÐÅбðµÈ£¬¾ßÌå¿ÉÒԲο¼postmanÖеÄecho.collections£¬¶ÔÓÚpython¿ÉÒÔÓÃunittestÀ´×éÖ¯²âÊÔÓÃÀýºÍÌí¼Ó¶ÏÑÔ½øÐÐÅжϡ£¶ø¶ÔÓÚ²âÊÔÊý¾ÝµÄ×¼±¸£¬ÐèÒª×öµ½Êý¾ÝºÍÒµÎñ¾¡Á¿·ÖÀ룬¼´½«²âÊÔÊý¾Ý²ÎÊý»¯£¬ÔÚ¹¤¾ßÖпÉÒÔͨ¹ýÌí¼Ó±äÁ¿µÄÐÎʽʵÏÖ£¬¶ÔÓÚpythonÉè¼Æµ½µÄÓйذüÓÐxlrd£¬json£¬Èç¹ûÐèÒªÁ¬½ÓÊý¾Ý¿â»¹ÐèÒªmysql¡£

²âÊÔÍê³ÉºóÉú²ú±¨¸æ»òÕß·¢ËÍÓʼþ£¬Ò²¿ÉÒÔʹÓÃHTMLTestRunnerºÍsmtplibµÈ¡£

ÎÒÒ²´ÓÕâÈý´ó·½Ãæ½øÐÐ×ܽ᣺

1. ½Ó¿Ú·½·¨ÊµÏֺͷâ×°

requests¿â¿ÉÒԺܺõİïÖúÎÒÃÇʵÏÖHTTPÇëÇó£¬API²Î¿¼Îĵµ£¬ÕâÀïÎÒ´´½¨ÁËrunmethod.py£¬ÀïÃæ°üº¬RunMethodÀࣺ

ÕâÀïÐèҪעÒâ¾ÍÊÇpythonĬÈϲÎÊýºÍ¿ÉÑ¡²ÎÊýÒª·ÅÔÚ±ØÑ¡²ÎÊýºóÃæ£¬¶ÔÓÚÏàÓ¦Êý¾ÝʹÓÃjson¸ñʽ½øÐзµ»Ø¡£²ÎÊýverify=false±íʾºöÂÔ¶Ô SSL Ö¤ÊéµÄÑéÖ¤¡£

2.×éÖ¯²âÊÔºÍÉú³É±¨¸æ

ʹÓÃunittestÀ´×éÖ¯²âÊÔ¡¢Ìí¼Ó²âÊÔÓÃÀýºÍ¶ÏÑÔ£¬²âÊÔ±¨¸æ¿ÉÒÔÏÂÔØHTMLTestRunner.py²¢·ÅÔÚpython°²×°Â·¾¶libϼ´¿É£¬´úÂëÈçÏ£º

#coding:utf-8
import unittest
import json
import HTMLTestRunner
from mock import mock
#from demo import RunMain
from runmethod import RunMethod
from mock_demo import mock_test
import os
class TestMethod(unittest.TestCase):
def setUp(self):
#self.run=RunMain()
self.run = RunMethod()
def test_01(self):
url = 'http://coding.imooc.com/api/cate'
data = {
'timestamp':'1507034803124',
'uid':'5249191',
'uuid':'5ae7d1a22c82fb89c78f603420870ad7',
'secrect':'078474b41dd37ddd5efeb04aa591ec12',
'token':'7d6f14f21ec96d755de41e6c076758dd',
'cid':'0',
'errorCode':1001
}
#self.run.run_main = mock.Mock(return_value=data)
res = mock_test(self.run.run_main,data,url,"POST",data)
#res = self.run.run_main(url,'POST',data)
print(res)
self.assertEqual(res['errorCode'],1001,"²âÊÔʧ°Ü") @unittest.skip('test_02')
def test_02(self):

url = 'http://coding.imooc.com/api/cate'
data = {
'timestamp':'1507034803124',
'uid':'5249191',
'uuid':'5ae7d1a22c82fb89c78f603420870ad7',
'secrect':'078474b41dd37ddd5efeb04aa591ec12',
'token':'7d6f14f21ec96d755de41e6c076758dd',
'cid':'0'
}
res = self.run.run_main(url,'GET',data)
self.assertEqual(res['errorCode'],1006,"²âÊÔʧ°Ü")
def test_03(self):
url = 'http://coding.imooc.com/api/cate'
data = {
'timestamp':'1507034803124',
'uid':'5249191',
'uuid':'5ae7d1a22c82fb89c78f603420870ad7',
'secrect':'078474b41dd37ddd5efeb04aa591ec12',
'token':'7d6f14f21ec96d755de41e6c076758dd',
'cid':'0',
'status':11
}
res = mock_test(self.run.run_main,data,url,'GET',data)
print(res)
self.assertGreater(res['status'],10,'²âÊÔͨ¹ý')
if __name__ == '__main__':
filepath = os.getcwd()+'\\report.html'
fp = open(filepath,'wb+')
suite = unittest.TestSuite()
suite.addTest(TestMethod('test_01'))
suite.addTest(TestMethod('test_02'))
suite.addTest(TestMethod('test_03'))
runner = HTMLTestRunner.HTMLTestRunner(stream=fp,title='this is demo test')
runner.run(suite)
#unittest.main()

ÕâÀïsetUp()·½·¨ÓÃÀ´ÔÚ²âÊÔ֮ǰִÐУ¬Í¬ÑùµÄÓÐtearDown()·½·¨£¬²âÊÔcaseÒÔtest¿ªÍ·½øÐбàд£¬È»ºóʹÓÃTestSuitÀàÉú³É²âÊÔÌ×¼þ£¬½«caseÌí¼Ó½øÈ¥£¬ÔËÐÐrun suite¼´¿É¡£µ±²âÊÔÓÃÀý½Ï¶àʱ£¬¿ÉÒÔÉú³É¶à¸ö²âÊÔÀà±ð£¬È»ºóʹÓÃTestLoader().LoadTestsFromTestCase(²âÊÔÀà)Éú³É²âÊÔÓÃÀý£¬ÔÙ¼ÓÈëtestsuiteÖ´ÐС£

ÔÚÕâÀÎÒʹÓÃÁËѧϰµ½µÄmock·½·¨£¬mock¼´Ä£ÄâÊý¾Ý£¬µ±ÎÒÃÇÎÞ·¨Êµ¼ÊÖ´ÐлñµÃÊý¾Ýʱ¿ÉÒÔʹÓÃmock·½·¨£¬Ä£ÄâÉú³ÉÎÒÃÇÐèÒªÅбðµÄÊý¾Ý£¬ÕâÀïmock_test·½·¨Í¬Ñù½øÐÐÁË·â×°£º

#coding:utf-8
from mock import mock
def mock_test(mock_method,request_data,url,method,response_data):
mock_method = mock.Mock(return_value=response_data)
res = mock_method(url,method,request_data)
return res

ÕâÀïÄ£ÄâµÄÊÇself.run.run_main()·½·¨£¬½«Õâ¸ö·½·¨µÄ·µ»ØÖµÉèΪresponse_data,¶ø×îÖÕÎÒÃÇÒªÅжϵÄÊÇ·µ»ØÖµres,¿ÉÒÔ½áºÏtest_02¶Ô±È£¬

res = self.run.run_main(url,'GET',data)

ËùÒÔÓÖÐèÒª´«Èë²ÎÊýurl,method,request_data,×îºó·µ»ØÏàÓ¦Êý¾Ý¼´¿É£¬

res = mock_test(self.run.run_main,data,url,'GET',data)

ÕâÀïÎÒ¼ÙÉè·µ»ØµÄÊý¾ÝΪdata,ËæÒâÌí¼ÓÁ˼¸¸öÅжÏÌõ¼þerrorCode==1001ºÍstatus>10×÷ΪÅжÏÒÀ¾Ý¡£×îºóÉú³É±¨¸æÈçÏ£º

3 ²âÊÔÊý¾Ý´¦Àí

ÕâÒ»²¿·ÖÖ÷Òª°üÀ¨Éè¼Æ²âÊÔÊý¾Ý£¬Êý¾ÝÌáÈ¡ºÍ²ÎÊý»¯£¬ÒÔ¼°½â¾öÊý¾ÝÒÀÀµ¡£ÕâÀﻹÊÇÒÔĽ¿ÎÍøÉÏѧϰµÄÀý×ÓΪÀý£¬Ö÷ÒªÒÀ¾Ý²âÊÔÄ¿µÄºÍʹÓÃÁ÷³ÌÀ´Éè¼Æ£¬ÈçÏÂͼ£º

ÕâÀïÊ×ÏÈÉæ¼°µ½µÄ¾ÍÊǶÔExcel±í¸ñµÄ²Ù×÷£¬µ¼ÈëÏà¹Ø¿âimport xlrd,ÏȶÔÈçÉϱíµÄ²âÊÔÓÃÀý½øÐÐÅäÖÃÎļþ±àд£º

class global_var:
Id = '0'
request_name = '1'
url = '2'
run = '3'
request_way = '4'
header = '5'
case_depend = '6'
data_depend = '7'
field_depend = '8'
data = '9'
expect = '10'
result = '11'

ÔÙ¶¨Òå·µ»Ø¸ÃÁеĺ¯Êý£¬ÀýÈç»ñÈ¡caseIdºÍURL£º

def get_id():
return global_var.Id
def get_url():
return global_var.url

3.1²Ù×÷ExcelÎļþ

È»ºóÎÒÃÇÔÙ±àд²Ù×÷ExcelµÄÄ£¿é£¬Ö÷Òª°üº¬Á˶ÔExcel±í¸ñµÄ²Ù×÷£¬»ñÈ¡±íµ¥¡¢ÐС¢ÁС¢µ¥Ôª¸ñÄÚÈݵȡ£

import xlrd
from xlutils.copy import copy
class OperationExcel:
def __init__(self,file_name=None,sheet_id=None):
if file_name:
self.file_name = file_name
self.sheet_id = sheet_id
else:
self.file_name = '/dataconfig/case1.xls'
self.sheet_id = 0
self.data = self.get_data()
#»ñÈ¡sheetsµÄÄÚÈÝ
def get_data(self):
data = xlrd.open_workbook(self.file_name)
tables = data.sheets()[self.sheet_id]
return tables
#»ñÈ¡µ¥Ôª¸ñµÄÐÐÊý
def get_lines(self):
tables = self.data
return tables.nrows
#»ñȡijһ¸öµ¥Ôª¸ñµÄÄÚÈÝ
def get_cell_value(self,row,col):
return self.data.cell_value(row,col)
#дÈëÊý¾Ý
def write_value(self,row,col,value):
'''дÈëexcelÊý¾Ýrow,col,value'''
read_data = xlrd.open_workbook(self.file_name)
write_data = copy(read_data)
sheet_data = write_data.get_sheet(0)
sheet_data.write(row,col,value)
write_data.save(self.file_name)---------------------

ÆäÖÐдÊý¾ÝÓÃÓÚ½«ÔËÐнá¹ûдÈëExcelÎļþ£¬ÏÈÓÃcopy¸´ÖÆÕû¸öÎļþ£¬Í¨¹ýget_sheet()»ñÈ¡µÄsheetÓÐwrite()·½·¨¡£

3.2²Ù×÷jsonÎļþ

¶ÔÓÚÇëÇóÊý¾Ý£¬ÎÒÊǸù¾Ý¹Ø¼ü×Ö´ÓjsonÎļþÀïÈ¡³ö×ֶΣ¬ËùÒÔ»¹ÐèÒªjson¸ñʽµÄÊý¾ÝÎļþ£¬ÈçÏ¡£¶ÔÓ¦ÇëÇóÊý¾ÝÖеĸ÷¸ö¹Ø¼ü×Ö£º

ËùÒÔ»¹ÐèÒª±àд¶ÔÓ¦²Ù×÷jsonÎļþµÄÄ£¿é£º

import json
class OperetionJson:
def __init__(self,file_path=None):
if file_path == None:
self.file_path = '/dataconfig/user.json'
else:
self.file_path = file_path
self.data = self.read_data()
#¶ÁÈ¡jsonÎļþ
def read_data(self):
with open(self.file_path) as fp:
data = json.load(fp)
return data
#¸ù¾Ý¹Ø¼ü×Ö»ñÈ¡Êý¾Ý
def get_data(self,id):
print(type(self.data))
return self.data[id]

¶Áд²Ù×÷ʹÓõÄÊÇjson.load(),json.dump() ´«ÈëµÄÊÇÎļþ¾ä±ú¡£

3.3 »ñµÃ²âÊÔÊý¾Ý

ÔÚ¶¨ÒåºÃExcelºÍjson²Ù×÷Ä£¿éºó£¬ÎÒÃǽ«ÆäÓ¦ÓÃÓÚÎÒÃǵIJâÊÔ±íµ¥£¬¶¨ÒåÒ»¸ö»ñÈ¡Êý¾ÝÄ£¿é£º

from util.operation_excel import OperationExcel
import data.data_config
from util.operation_json import OperetionJson
class GetData:
def __init__(self):
self.opera_excel = OperationExcel()
#È¥»ñÈ¡excelÐÐÊý,¾ÍÊÇÎÒÃǵÄcase¸öÊý
def get_case_lines(self):
return self.opera_excel.get_lines()
#»ñÈ¡ÊÇ·ñÖ´ÐÐ
def get_is_run(self,row):
flag = None
col = int(data_config.get_run())
run_model = self.opera_excel.get_cell_value(row,col)
if run_model == 'yes':
flag = True
else:
flag = False
return flag
#ÊÇ·ñЯ´øheader
def is_header(self,row):
col = int(data_config.get_header())
header = self.opera_excel.get_cell_value(row,col)
if header != '':
return header
else:
return None
#»ñÈ¡ÇëÇó·½Ê½
def get_request_method(self,row):
col = int(data_config.get_run_way())
request_method = self.opera_excel.get_cell_value(row,col)
return request_method
#»ñÈ¡url
def get_request_url(self,row):
col = int(data_config.get_url())
url = self.opera_excel.get_cell_value(row,col)
return url
#»ñÈ¡ÇëÇóÊý¾Ý
def get_request_data(self,row):
col = int(data_config.get_data())
data = self.opera_excel.get_cell_value(row,col)
if data == '':
return None
return data
#ͨ¹ý»ñÈ¡¹Ø¼ü×ÖÄõ½dataÊý¾Ý
def get_data_for_json(self,row):
opera_json = OperetionJson()
request_data = opera_json.get_data(self.get_request_data(row))
return request_data
#»ñȡԤÆÚ½á¹û
def get_expcet_data(self,row):
col = int(data_config.get_expect())
expect = self.opera_excel.get_cell_value(row,col)
if expect == '':
return None
return expect
def write_result(self,row,value):
col = int(data_config.get_result())
self.opera_excel.write_value(row,col,value)

¸ÃÄ£¿é½«Excel²Ù×÷ÀàʵÀý»¯ºóÓÃÓÚ²Ù×÷²âÊÔ±íµ¥£¬·Ö±ð»ñµÃ²âÊÔÔËÐÐËùÐèµÄ¸÷ÖÖÌõ¼þ¡£

3.4 ÅжÏÌõ¼þ

ÕâÀïÅжÏÒ»¸öcaseÊÇ·ñͨ¹ý£¬Êǽ«Êµ¼Ê½á¹ûºÍÔ¤ÆÚ½á¹û½øÐжԱȣ¬±ÈÈ磬״̬ÂëstatusÊDz»ÊÇ200£¬»òÕßÔÚ·µ»ØÊý¾ÝÖв鿴ÊÇ·ñº¬ÓÐijһ×ֶΣº

import json
import operator as op
class CommonUtil:
def is_contain(self, str_one,str_two):
'''
ÅжÏÒ»¸ö×Ö·û´®ÊÇ·ñÔÙÁíÍâÒ»¸ö×Ö·û´®ÖÐ
str_one:²éÕÒµÄ×Ö·û´®
str_two£º±»²éÕÒµÄ×Ö·û´®
'''
flag = None
#ÏȽ«·µ»ØµÄres½øÐиñʽת»»£¬unicodeת³ÉstringÀàÐÍ
if isinstance(str_one,unicode):
str_one = str_one.encode('unicode-escape').decode('string_escape')
return op.eq(str_one,str_two)
if str_one in str_two:
flag = True
else:
flag = False
return flag
def is_equal_dict(self,dict_one,dict_two):
'''ÅжÏÁ½¸ö×ÖµäÊÇ·ñÏàµÈ'''
if isinstance(dict_one,str):
dict_one = json.loads(dict_one)
if isinstance(dict_two,str):
dict_two = json.loads(dict_two)
return op.eq(dict_one,dict_two)---------------------

ËùÒÔÎÒÃÇ»ñµÃexpecÊý¾ÝºÍÏàÓ¦Êý¾Ý£¬ÔÙµ÷ÓÃÕâ¸öÀà±ðµÄis_contain() ·½·¨¾ÍÄÜÅжϡ£

3.5 Êý¾ÝÒÀÀµÎÊÌâ

µ±ÎÒÃÇÒªÖ´ÐеÄij¸öcaseµÄÏàÓ¦Êý¾ÝÒÀÀµÓÚÇ°ÃæÄ³¸öcaseµÄ·µ»ØÊý¾Ýʱ£¬ÎÒÃÇÐèÒª¶ÔÏàÓ¦Êý¾Ý½øÐиüУ¬±ÈÈçcase12µÄÏàÓ¦Êý¾Ýrequest_data[Êý¾ÝÒÀÀµ×Ö¶Î]µÄÖµÓ¦¸Ã¸üÐÂÓÚcase11µÄ·µ»ØÊý¾Ýresponse_data[ÒÀÀµµÄ·µ»Ø×Ö¶Î] ¡£ÄÇôÎÒÃǾÍÐèÒªÏÈÖ´ÐÐcase11Äõ½·µ»ØÊý¾Ý£¬ÔÙдÈëcase12µÄÏàÓ¦Êý¾Ý£¬Ê×ÏȶԲÙ×÷ExcelµÄÄ£¿é½øÐиüмÓÈ룺

#»ñȡijһÁеÄÄÚÈÝ
def get_cols_data(self,col_id=None):
if col_id != None:
cols = self.data.col_values(col_id)
else:
cols = self.data.col_values(0)
return cols
#¸ù¾Ý¶ÔÓ¦µÄcaseidÕÒµ½¶ÔÓ¦µÄÐкÅ
def get_row_num(self,case_id):
num = 0
cols_data = self.get_cols_data()
for col_data in cols_data:
if case_id in col_data:
return num
num = num+1
#¸ù¾ÝÐкţ¬ÕÒµ½¸ÃÐеÄÄÚÈÝ
def get_row_values(self,row):
tables = self.data
row_data = tables.row_values(row)
return row_data
#¸ù¾Ý¶ÔÓ¦µÄcaseid ÕÒµ½¶ÔÓ¦ÐеÄÄÚÈÝ
def get_rows_data(self,case_id):
row_num = self.get_row_num(case_id)
rows_data = self.get_row_values(row_num)
return rows_data

¼´ÎÒÃÇͨ¹ýÒÀÀµµÄcaseIdÕÒµ½¶ÔÓ¦µÄÐкţ¬Äõ½ÕûÐеÄÄÚÈÝ¡£ÎÒÃÇĬÈÏÄõ½ÁÐ0µÄÄÚÈÝ£¨¼´caseId£©Ñ­»·ÕûÁÐÕÒµ½ÒÀÀµµÄcaseIdÔÚµÚ¼¸ÐУ¬È»ºó·µ»ØÕûÐÐÊý¾Ý£¬¼´ÊµÏÖ·½·¨get_rows_data(case_id) ¡£È»ºóÔÙÈ¥Ö´Ðк͸üУ¬ÎÒÃDZàдһ¸öרÃÅ´¦ÀíÒÀÀµÊý¾ÝµÄÄ£¿é£¬Í¬Ê±£¬ÎªÁË»ñÈ¡ÒÀÀµÊý¾Ý£¬»¹ÐèÒª¶Ô»ñÈ¡Êý¾ÝÄ£¿é½øÐиüÐÂÈçÏ£º

#»ñÈ¡ÒÀÀµÊý¾ÝµÄkey
def get_depend_key(self,row):
col = int(data_config.get_data_depend())
depent_key = self.opera_excel.get_cell_value(row,col)
if depent_key == "":
return None
else:
return depent_key
#ÅжÏÊÇ·ñÓÐcaseÒÀÀµ
def is_depend(self,row):
col = int(data_config.get_case_depend())
depend_case_id = self.opera_excel.get_cell_value(row,col)
if depend_case_id == "":
return None
else:
return depend_case_id
#»ñÈ¡Êý¾ÝÒÀÀµ×Ö¶Î
def get_depend_field(self,row):
col = int(data_config.get_field_depend())
data = self.opera_excel.get_cell_value(row,col)
if data == "":
return None
else:
return data

½«·½·¨Ó¦ÓÃÓÚרÃÅ´¦ÀíÒÀÀµÊý¾ÝµÄÄ£¿é£º

from util.operation_excel import OperationExcel
from base.runmethod import RunMethod
from data.get_data import GetData
from jsonpath_rw import jsonpath,parse
class DependdentData:
def __init__(self,case_id):
self.case_id = case_id
self.opera_excel = OperationExcel()
self.data = GetData()
#ͨ¹ýcase_idÈ¥»ñÈ¡¸Ãcase_idµÄÕûÐÐÊý¾Ý
def get_case_line_data(self):
rows_data = self.opera_excel.get_rows_data(self.case_id)
return rows_data
#Ö´ÐÐÒÀÀµ²âÊÔ£¬»ñÈ¡½á¹û
def run_dependent(self):
run_method = RunMethod()
row_num = self.opera_excel.get_row_num(self.case_id)
request_data = self.data.get_data_for_json(row_num)
#header = self.data.is_header(row_num)
method = self.data.get_request_method(row_num)
url = self.data.get_request_url(row_num)
res = run_method.run_main(method,url,request_data)
return json.loads(res)#·µ»ØÊý¾ÝÊÇ×Ö·û´®ÐèҪת³Éjson¸ñʽ·½±ãºóÐø²éѯ
#¸ù¾ÝÒÀÀµµÄkeyÈ¥»ñȡִÐÐÒÀÀµ²âÊÔcaseµÄÏìÓ¦,È»ºó·µ»Ø
def get_data_for_key(self,row):
depend_data = self.data.get_depend_key(row)
response_data = self.run_dependent()
json_exe = parse(depend_data)
madle = json_exe.find(response_data)
return [math.value for math in madle][0]

ÆäÖÐjsonpathÓÃÓÚÕÒµ½¶à²ã¼¶Êý¾Ý£¬ÀàËÆÓÚxpath£¬¼´Í¨¹ýÒÀÀµ×ֶαíʾµÄ²ã¼¶¹ØÏµÔÚ·µ»ØÊý¾ÝÖÐÕÒµ½¶ÔÓ¦µÄÖµ£¬×îºóÔÙÖ´ÐиÃcaseʱ°ÑÊý¾Ý¸üС£

3.6 Ö÷Á÷³Ì

°ÑÉÏÊöËùÓÐÄ£¿éµ¼È룬±àдÖ÷Á÷³ÌÄ£¿é£º

from base.runmethod import RunMethod
from data.get_data import GetData
from util.common_util import CommonUtil
from data.dependent_data import DependdentData
from util.operation_header import OperationHeader
from util.operation_json import OperetionJson
class RunTest:
def __init__(self):
self.run_method = RunMethod()
self.data = GetData()
self.com_util = CommonUtil()
#³ÌÐòÖ´ÐÐ
def go_on_run(self):
res = None
pass_count = []
fail_count = []
rows_count = self.data.get_case_lines()
for i in range(1,rows_count):
is_run = self.data.get_is_run(i)
if is_run:
url = self.data.get_request_url(i)
method = self.data.get_request_method(i)
request_data = self.data.get_data_for_json(i)
expect = self.data.get_expcet_data(i)
header = self.data.is_header(i)
depend_case = self.data.is_depend(i)
if depend_case != None:
self.depend_data = DependdentData(depend_case)
#»ñÈ¡µÄÒÀÀµÏìÓ¦Êý¾Ý
depend_response_data = self.depend_data.get_data_for_key(i)
#»ñÈ¡ÒÀÀµµÄkey
depend_key = self.data.get_depend_field(i)
request_data[depend_key] = depend_response_data
res = self.run_method.run_main(method,url,request_data)
if self.com_util.is_contain(expect,res):
self.data.write_result(i,'pass')
pass_count.append(i)
else:
self.data.write_result(i,res)
fail_count.append(i)
print(len(pass_count))
print(len(fail_count))
if __name__ == '__main__':
run = RunTest()
run.go_on_run()

ÕâÑùÎÒÃǾÍÍê³ÉÁ˲âÊÔÖ´ÐУ¬²¢¶Ô½á¹û½øÐÐÁËͳ¼Æ£¬Í¬Ê±½â¾öÁËÊý¾ÝÒÀÀµÎÊÌâ¡£

   
5085 ´Îä¯ÀÀ       28
Ïà¹ØÎÄÕÂ

΢·þÎñ²âÊÔÖ®µ¥Ôª²âÊÔ
һƪͼÎÄ´øÄãÁ˽â°×ºÐ²âÊÔÓÃÀýÉè¼Æ·½·¨
È«ÃæµÄÖÊÁ¿±£ÕÏÌåϵ֮»Ø¹é²âÊÔ²ßÂÔ
È˹¤ÖÇÄÜ×Ô¶¯»¯²âÊÔ̽Ë÷
Ïà¹ØÎĵµ

×Ô¶¯»¯½Ó¿Ú²âÊÔʵ¼ù֮·
jenkins³ÖÐø¼¯³É²âÊÔ
ÐÔÄܲâÊÔÕï¶Ï·ÖÎöÓëÓÅ»¯
ÐÔÄܲâÊÔʵÀý
Ïà¹Ø¿Î³Ì

³ÖÐø¼¯³É²âÊÔ×î¼Ñʵ¼ù
×Ô¶¯»¯²âÊÔÌåϵ½¨ÉèÓë×î¼Ñʵ¼ù
²âÊԼܹ¹µÄ¹¹½¨ÓëÓ¦ÓÃʵ¼ù
DevOpsʱ´úµÄ²âÊÔ¼¼ÊõÓë×î¼Ñʵ¼ù