def Executionmode2(runresult,casepath,resultname): bk = xlrd.open_workbook(casepath, formatting_info=True) # 打开excel文件 resultlist = runresult[1::2] caselist=runresult[0::2] if resultname in bk.sheet_names(): ch = bk.sheet_by_name(resultname) nrows = ch.nrows ncols = ch.ncols # print runresult for m in range(1, nrows): AC_result = resultlist[m - 1] # print AC_result EX_result = ch.cell_value(m, ncols - 1) eachcase = ch.cell_value(m, ncols - 2) finalresult = acex(AC_result, EX_result) if finalresult == False: writeLog.errorlog('FAIL:wrong datas case is number:case%s' % m, eachcase) else: # print runresult checkpass=[] for i in range(0,len(runresult[1::2])): result=json.loads(resultlist[i]) data = result["datas"] # 取key对应的value flag = result["flag"] desc = result["desc"] if desc=="参数错误" and flag==3: teststate='pass' else: teststate='Need verify' checkpass.append(teststate) print checkpass results=[] for i in zip(checkpass,caselist,resultlist): results.extend(list(i)) print results writeExcelresult.writeResult2(results,casepath,resultname) def Verificationmode2(desc, flag): if desc == "参数错误" and flag == 3: teststate = 'pass' else: teststate = 'Need verify' def Verificationmode1(desc, flag, Nullstate): if desc == "参数错误" and flag == 3 and Nullstate == 0: teststate = 'pass' else: teststate = 'Need verify'
def Executionmode(runresult,casepath,resultname): bk = xlrd.open_workbook(casepath, formatting_info=True) # 打开excel文件 if resultname in bk.sheet_names(): ch = bk.sheet_by_name(resultname) nrows = ch.nrows ncols = ch.ncols # print runresult resultlist=runresult[1::2] for m in range(1, nrows): AC_result = resultlist[m - 1] # print AC_result EX_result = ch.cell_value(m, ncols - 1) eachcase = ch.cell_value(m, ncols - 2) finalresult = acex(AC_result, EX_result) if finalresult == False: writeLog.errorlog('FAIL:wrong datas case is number:case%s' % m, eachcase) else: print runresult writeExcelresult.writeResult(runresult,casepath,resultname)
def createcase(casepath, defaultname, resultname, Speparamlist): bk = xlrd.open_workbook(casepath, formatting_info=True) # 打开excel文件 httpString = bk.sheet_by_name('Sheet1').cell_value(0, 0) # 接口url在表1里 sh = bk.sheet_by_name(defaultname) runFirstnullresult = [] methods = sh.cell_value(1, 1) try: list1 = getvalue.getdvalue(casepath, defaultname, methods) if methods == 'GET': mypermission = permission1 else: mypermission = permission2 for i in range(len(list1) - 1, len(list1)): ###大于等于列表长度-1参数 nulllist = [] iter = itertools.combinations(list1, i) ###i表示取列表中的n个参数进行组合 nulllist.append(list(iter)) ######iter是一个循环器,所以它的值只能用1次,需要把值存到变量里 # print nulllist for j in range(0, len(nulllist[0])): ####生成列表个数 parameter1 = mypermission parameter2 = list(nulllist[0][j]) testcase = parameter1 + parameter2 # print testcase result = Requesttype.Requesttype(methods, testcase, httpString) eachcase = Requesttype.Requestcase(methods, testcase, httpString) # print eachcase # print EX_result runFirstnullresult.append(eachcase) runFirstnullresult.append(result) for y in Speparamlist: for i in range(0, len(list1)): parameter1 = getvalue.getdvalue(casepath, defaultname, methods) x = sh.cell_value(i + 4, 0) if methods == 'GET': element2 = x + '=' + y else: element2 = '"' + x + '":"' + y + '"' parameter1.pop(i) # print list1 parameter1.append(element2) # print parameter1 parameter = mypermission testcase = parameter + parameter1 AC_result = Requesttype.Requesttype(methods, testcase, httpString) eachcase = Requesttype.Requestcase(methods, testcase, httpString) runFirstnullresult.append(eachcase) runFirstnullresult.append(AC_result) if resultname in bk.sheet_names(): ch = bk.sheet_by_name(resultname) nrows = ch.nrows ncols = ch.ncols for n in range(1, nrows): EX_result = ch.cell_value(n, ncols - 1) finalresult = ACEXcompare.acex(AC_result, EX_result) if finalresult == False: writeLog.errorlog('FAIL:wrong datas case is number:', eachcase) else: return runFirstnullresult writeExcelresult.writenullResult(runFirstnullresult, resultpath, defaultname) except Exception, e: print e
def runcase(casepath, sheetname, resultname): bk = xlrd.open_workbook(casepath) # 打开excel文件 httpString = bk.sheet_by_name('Sheet1').cell_value(0, 0) # 接口url在表1里 sh = bk.sheet_by_name(sheetname) # 测试数据在表2里 mrows = sh.nrows mcols = sh.ncols runFirstresult = [] a = FileOperation.FileExsit(os.getcwd() + r'/log/failresult.html') if a == True: FileOperation.DelFile(os.getcwd() + r'/log/failresult.html') try: #拼接参数名与参数值 for j in range(1, mrows): methods = sh.cell_value(j, 2) testcase = [] for i in range(3, mcols): x = sh.cell_value(0, i) # 参数名,获取单元格的数据类型 y = sh.cell_value(j, i) # 参数值 xtype = sh.cell(0, i).ctype ytype = sh.cell(j, i).ctype ###################ctype : 0 empty,1 string, 2 number, 3 date, 4 boolean, 5 error if (xtype == 2): x = str(int(x)) if (ytype == 2) or (ytype == 4): y = str(int(y)) y = str(y) if x.find(' ') != -1 or y.find(' ') != -1: x = x.replace(' ', '+') y = y.replace(' ', '+') if ytype == 4 and y == '1': y = 'True' elif ytype == 4 and y == '0': y = 'False' if methods == 'GET': element2 = x + '=' + y else: element2 = '"' + x + '":"' + y + '"' testcase.append(element2) # print testcase AC_result = Requesttype.Requesttype(methods, testcase, httpString) eachcase = Requesttype.Requestcase(methods, testcase, httpString) # print AC_result runFirstresult.append(eachcase) runFirstresult.append(AC_result) # print runFirstresult if resultname in bk.sheet_names(): ch = bk.sheet_by_name(resultname) nrows = ch.nrows ncols = ch.ncols resultlist = runFirstresult[1::2] # print resultlist for m in range(1, nrows): AC_result = resultlist[m - 1] EX_result = ch.cell_value(m, ncols - 1) finalresult = ACEXcompare.acex(AC_result, EX_result) if finalresult == False: writeLog.errorlog( 'FAIL:wrong datas case is number:case%s' % m, eachcase) else: return runFirstresult writeExcelresult.writeResult(runFirstnullresult, resultpath, defaultname) except Exception, e: print e
def runcase(casepath): bk = xlrd.open_workbook(casepath) # 打开excel文件 httpString = bk.sheet_by_name('Sheet1').cell_value(0, 0) #接口url在表1里 sh = bk.sheet_by_name('Sheet2') #测试数据在表2里 nrows = sh.nrows ncols = sh.ncols FileOperation.DelFile(r'./log/failresult.html') try: #拼接参数名与参数值 for j in range(1, nrows): mylist = [] myvalue = [] for i in range(3, ncols - 1): x = sh.cell_value(j, i) #参数值 y = sh.cell_value(0, i) #参数名 if isinstance(x, float): x = str(int(x)) if isinstance(x, float): y = str(int(y)) if x == True: x = 'TRUE' if x == False: x = 'FALSE' if x.find(' ') != -1: x = x.replace(' ', '+') if y.find(' ') != -1: y = y.replace(' ', '+') #param = '"'+y+'"'+'='+'"'+x+'"'#加双引号 param = y + '=' + x #不加双引号 mylist.append(param) s = '&' params = s.join(mylist) #拼接成get型 value = '"' + y + '":"' + x + '"' myvalue.append(value) values = ','.join(myvalue) #拼接成post型 #print params #print values num = sh.cell_value(j, 0) num = str(int(num)) name = sh.cell_value(j, 1) name = str(name) EX_result = sh.cell_value(j, ncols - 1) expectresult = json.loads(EX_result) Edatas = expectresult["datas"] Edesc = expectresult["desc"] Eflag = expectresult["flag"] methods = sh.cell_value(j, 2) if methods == 'GET': AC_result = httpRequests.httpRequests(httpString, params, methods) else: AC_result = httpRequests.httpRequests(httpString, values, methods) actualresult = json.loads(AC_result) #改为json格式 datas = actualresult["datas"] #取key对应的value flag = actualresult["flag"] desc = actualresult["desc"] url = httpRequests.URLreturn(httpString, params) #print url finalresult = checkPoint.check_result(datas, Edatas, desc, Edesc, flag, Eflag, name) if finalresult == False: writeLog.errorlog( 'FAIL:wrong datas case is number:' + num + ':' + name, url) except Exception, e: print e