Ejemplo n.º 1
0
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
Ejemplo n.º 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
Ejemplo n.º 3
0
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'
Ejemplo n.º 4
0
def sendEmail():
    """
    发送邮件
    """
    failcase = os.path.dirname(os.path.abspath(__file__)) + r'\log\failresult.html'
    Failtest = []
    isFExists =  FileOperation.FileExsit(failcase)
    # print isFExists
    if not isFExists:
        pass
    else:
        Failtest = ['%s'%(failcase)]
    MSG_TEXT = "failed case result addreass : 到时候我会把附件里的文件放到服务器上,然后这个位置放个链接。目前暂时打开附件查看。"
    myEmail.SendEmailWithAttachment('*****@*****.**',['*****@*****.**','*****@*****.**'],'AutoTestResult-sentbyHSN',MSG_TEXT,Failtest,'smtp.qiye.163.com:25')
    print u"邮件已发送"
Ejemplo n.º 5
0
def get_opeind(appid, path):
    openid = 'NULL'
    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'))
                # print app_openid
                if app_openid['appid'] != appid:
                    continue
                else:
                    openid = app_openid['openid']
    else:
        print '请检查/appid/appidlist.txt文件是否存在。'
        send_emails.send_failEmail('请检查/appid/appidlist.txt文件是否存在。')

    return openid
Ejemplo n.º 6
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
Ejemplo n.º 7
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
Ejemplo n.º 8
0
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