Exemple #1
0
def main():
    parseE = ParseExcel()
    parseE.loadWorkBook(file_path)
    sheetObj = parseE.getSheetByName(u"API")
    activeList = parseE.getColumn(sheetObj, API_active)
    for idx, cell in enumerate(activeList[1:], 2):
        if cell.value == "y":
            # 需要执行的接口所在行的行对象
            rowObj = parseE.getRow(sheetObj, idx)
            apiName = rowObj[API_apiName - 1].value
            requestUrl = rowObj[API_requestUrl - 1].value
            requestMethod = rowObj[API_requestMethod - 1].value
            paramsType = rowObj[API_paramsType - 1].value
            apiTestCaseFileName = rowObj[API_apiTestCaseFileName - 1].value

            # 下一步读用例sheet表,准备执行测试用例
            caseSheetObj = parseE.getSheetByName(apiTestCaseFileName)
            caseActiveObj = parseE.getColumn(caseSheetObj, CASE_active)
            for c_idx, col in enumerate(caseActiveObj[1:], 2):
                if col.value == "y":
                    # 说明此case行需要执行
                    caseRowObj = parseE.getRow(caseSheetObj, c_idx)
                    requestData = caseRowObj[CASE_requestData - 1].value
                    relyData = caseRowObj[CASE_relyData - 1].value
                    dataStore = caseRowObj[CASE_dataStore - 1].value
                    if relyData:
                        # 发送接口请求之前,先做依赖数据的处理
                        requestData = "%s" %GetKey.get(eval(requestData), eval(relyData))
                    # 拼接接口请求参数,发送接口请求
                    httpC = HttpClient()
                    print requestMethod, requestUrl, paramsType, requestData
                    response = httpC.request(requestMethod = requestMethod,
                                  requestUrl = requestUrl,
                                  paramsType = paramsType,
                                  requestData = requestData
                                  )
                    responseData = response.json()
                    # 存储依赖数据
                    if dataStore:
                        RelyDataStore.do(eval(dataStore),apiName, c_idx - 1, eval
(requestData),responseData)
                    # 比对结果



                else:
                    print "用例被忽略执行"
        else:
            print "接口被设置忽略执行"
Exemple #2
0
class HandleTestCase():

    def __init__(self,testFilePath):
        self.wb=ParseExcel()
        self.wb.loadWorkBook(testFilePath)

    def getTestAPIInfo(self,rowNum=None):
        #rowNum指定API的具体行
        #wb=ParseExcel()
        #wb.loadWorkBook(testFilePath)
        API_SheetObj=self.wb.getSheetByName("API")
        #print(API_SheetObj)

        testAPIAllInfo=self.wb.getRow(API_SheetObj,rowNum)
        print("testAPIAllInfo--->",testAPIAllInfo)
        APIName=testAPIAllInfo[1].value
        RequestUrl=testAPIAllInfo[2].value
        RequestMethod=testAPIAllInfo[3].value
        ParamsType=testAPIAllInfo[4].value
        CaseSheetName=testAPIAllInfo[5].value
        Active=testAPIAllInfo[6].value
        #print(APIName,RequestUrl,RequestMethod,ParamsType,CaseSheetName,Active)
        APIsheet_rows=self.wb.getRowsNumber(API_SheetObj)
        if Active=="y":
            testCaseSheetObj=self.wb.getSheetByName(CaseSheetName)
            print("testCaseSheetObj--->",testCaseSheetObj)
            testsheet_rows=self.wb.getRowsNumber(testCaseSheetObj)
            return testCaseSheetObj,APIName,RequestUrl, RequestMethod,ParamsType,CaseSheetName,Active,testsheet_rows,APIsheet_rows
        else:
            print("该接口%s,%s不用执行"%(APIName,CaseSheetName))

    def getTestCaseInfo(self,testCaseSheet,rowNum):
        #rowNum指定testcasesheet的具体行
        testCaseAllInfo=self.wb.getRow(testCaseSheet,rowNum)
        print("testCaseAllInfo--->",testCaseAllInfo)
        RequestData=testCaseAllInfo[0].value
        RelyData = testCaseAllInfo[1].value
        ResponseCode=testCaseAllInfo[2].value
        DataStore=testCaseAllInfo[4].value
        CheckPoint=testCaseAllInfo[5].value
        Active=testCaseAllInfo[6].value
        if Active=="y":
            #print(RequestData,RelyData,ResponseCode,DataStore,Active)
            return eval(RequestData),RelyData,ResponseCode,DataStore,eval(CheckPoint),Active
        else:
            print("[%s]第%s条用例不用执行"%(testCaseSheet.title,(rowNum-1)))
            return None