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)
    a = FileOperation.FileExsit(os.getcwd() + r'/log/failresult.html')
    if a == True:
        FileOperation.DelFile(os.getcwd() + r'/log/failresult.html')
    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
            AC_result = Requesttype.Requesttype(methods, testcase, httpString)
            eachcase = Requesttype.Requestcase(methods, testcase, httpString)
            # print eachcase
            # print EX_result
            runFirstnullresult.append(eachcase)
            runFirstnullresult.append(AC_result)
        for i in range(0, len(list1)):
            for y in Speparamlist:
                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)
                print AC_result
                eachcase = Requesttype.Requestcase(methods, testcase,
                                                   httpString)
                runFirstnullresult.append(eachcase)
                runFirstnullresult.append(AC_result)
        # print runFirstnullresult
        return runFirstnullresult
        Execution.Executionmode1(runFirstnullresult, casepath, resultname)

    except Exception, e:
        print e
Beispiel #2
0
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
        return runFirstresult
        Execution.Executionmode(runFirstresult, casepath, casesheet,
                                resultname)

    except Exception, e:
        print e
def get_appidinfo(getvalue_dict):
    today = str(time.strftime("%Y-%m-%d %H.%M", time.localtime(time.time())))
    a = FileOperation.FileExsit(os.getcwd() + r'/log/failresult.html')
    if a == True:
        FileOperation.Copy_file(
            os.getcwd() + r'/log/failresult.html',
            os.getcwd() +
            r'/log/failresult_history/failresult_%s.html' % today)
        FileOperation.DelFile(os.getcwd() + r'/log/failresult.html')
    b = FileOperation.FileExsit(os.getcwd() + r'/log/static.txt')
    if b == True:
        FileOperation.Copy_file(
            os.getcwd() + r'/log/static.txt',
            os.getcwd() + r'/log/staticlog/static_%s.txt' % today)
        FileOperation.DelFile(os.getcwd() + r'/log/static.txt')
    app_openid_data = []
    # print getvalue_dict
    path = getvalue_dict['appid']
    # print path
    a = FileOperation.FileExsit(os.getcwd() + path)
    if a == True:
        file = open(os.getcwd() + path, "r")
        for line in file.readlines():
            if line[0] == '#' or line[0] == '#' or len(line.strip()) == 0:
                pass
            else:
                app_openid = eval(line.decode(encoding='utf-8'))
                app_openid_data.append(app_openid)
                # appid = line.strip('\n').decode(encoding='utf-8')
                # appidlist.append(appid)
        file.close()
        # print app_openid_data
        return app_openid_data

    else:
        print '请检查/appid/appidlist.txt文件是否存在。'
        send_emails.send_failEmail('请检查/appid/appidlist.txt文件是否存在。')
        return 'NULL'
Beispiel #4
0
def createtypecase(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)
    nrows = sh.nrows
    runresult = []
    methods = sh.cell_value(1, 1)

    a = FileOperation.FileExsit(os.getcwd() + r'/log/failresult.html')
    if a == True:
        FileOperation.DelFile(os.getcwd() + r'/log/failresult.html')

    try:

        list1 = getvalue.getdvalue(casepath, defaultname, methods)
        # print list1
        if methods == 'GET':
            mypermission = permission1
        else:
            mypermission = permission2
        for i in range(5, nrows):  ##所在行
            x = sh.cell_value(i, 0)  # 参数名,获取单元格的数据类型
            y = sh.cell_value(i, 1)  # 参数值
            z = sh.cell_value(i, 2)  #参数类型
            if z == 'str':
                pass
                # print '不替换字符串类型参数'
            else:
                z = "<type '%s'>" % z
                testlist = []
                for j in range(0, len(Speparamlist)):
                    deparamtype = type(Speparamlist[j])
                    if z == str(deparamtype):
                        pass
                        # print '取出同类型参数不进行替换'
                    else:
                        testlist.append(Speparamlist[j])
                # print testlist
                for n in range(0, len(testlist)):
                    y = str(testlist[n])
                    x = sh.cell_value(i, 0)
                    # print x
                    parameter1 = getvalue.getdvalue(casepath, defaultname,
                                                    methods)
                    # print parameter1
                    if methods == 'GET':
                        element2 = x + '=' + y
                    else:
                        element2 = '"' + x + '":"' + y + '"'
                    # print element2
                    parameter1.pop(i - 4)
                    parameter1.append(element2)
                    # print parameter1
                    parameter = mypermission
                    testcase = parameter + parameter1
                    # print testcase
                    AC_result = Requesttype.Requesttype(
                        methods, testcase, httpString)
                    print AC_result
                    eachcase = Requesttype.Requestcase(methods, testcase,
                                                       httpString)
                    runresult.append(eachcase)
                    runresult.append(AC_result)
        # print runresult
        return runresult

        Execution.Executionmode(
            runresult,
            casepath,
            resultname,
        )

    except Exception, e:
        print e
Beispiel #5
0
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
Beispiel #6
0
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
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)
    a = FileOperation.FileExsit(os.getcwd() + r'/log/failresult.html')
    if a == True:
        FileOperation.DelFile(os.getcwd() + r'/log/failresult.html')
    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
            AC_result = Requesttype.Requesttype(methods, testcase, httpString)
            eachcase = Requesttype.Requestcase(methods, testcase, httpString)
            # print eachcase
            # print EX_result
            runFirstnullresult.append(eachcase)
            runFirstnullresult.append(AC_result)
        for i in range(0, len(list1)):
            for y in Speparamlist:
                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)
        # print runFirstnullresult
        if resultname in bk.sheet_names():
            ch = bk.sheet_by_name(resultname)
            nrows = ch.nrows
            ncols = ch.ncols
            resultlist = runFirstnullresult[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 runFirstnullresult
            writeExcelresult.writeResult(runFirstnullresult, resultpath,
                                         defaultname)

    except Exception, e:
        print e