Esempio n. 1
0
# -*- coding: UTF-8 -*-
import inspect, sys, datetime
from common.Excel import Reader, Writer

reader = Reader()
writer = Writer()
alllist = []
runtype = 'WEB'


# 反射获取关键字
def geffunc(line, http):
    func = None
    try:
        func = getattr(http, line[0])
    except Exception as e:
        print(e)

    return func


# 反射获取参数
def getargs(func):
    if func:
        args = inspect.getfullargspec(func).__str__()
        args = args[args.find('args=') + 5:args.find(', varargs')]
        args = eval(args)
        args.remove('self')
        l = len(args)
        return l
    else:
Esempio n. 2
0
        print('暂时不支持超过3个参数的关键字')


# 读配置文件
config.get_config('./conf/conf.properties')
logger.info(config.config)

# 初始化数据库
mysql = Mysql()
mysql.init_mysql('./conf/userinfo.sql')

# 逐行读取excel
reader = Reader()
casename = 'Web'
reader.open_excel('./lib/%s.xls' % casename)
writer = Writer()
writer.copy_open('./lib/%s.xls' % casename, './lib/result-%s.xls' % casename)

sheetname = reader.get_sheets()
writer.set_sheet(sheetname[0])
starttime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
writer.write(1, 3, starttime)
reader.readline()
casetype = reader.readline()[1]
# 执行用例的关键字库对象
obj = None
if casetype == 'HTTP' or casetype == '':
    # 执行http接口自动化
    obj = HTTP(writer)
elif casetype == 'SOAP':
    obj = SOAP(writer)
Esempio n. 3
0
    casename = 'XLSHTTP接口用例.xls'

    config.get_config('./lib/conf.properties')
    mysql = Mysql()
    mysql.init_mysql('./lib/userinfo.sql')

    #开始读取用例
    reader = Reader()
    # http = HTTP()
    # reader.open_excel('./lib/HTTP接口用例.xls')
    reader.open_excel('./lib/' + casename)
    sheetname = reader.get_sheets()
    logger.info(sheetname)

    writer = Writer()
    # writer.copy_open('./lib/HTTP接口用例.xls', './lib/result-HTTP接口用例.xls')
    writer.copy_open('./lib/' + casename, './lib/result-' + casename)
    # sheetname = writer.get_sheets()

    #获取开始时间
    t = str(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
    #设置shet页
    writer.set_sheet(sheetname[0])
    # 写入结果文件
    writer.write(1, 3, t)

    #识别接口类型
    reader.readline()
    line = reader.readline()
    if line[1] == 'HTTP':
Esempio n. 4
0
def runCases():
    reader = Reader()
    writer = Writer()
    http = HTTP(writer)
    reader.open_excle('../lib/cases/HTTP接口用例.xls')
    writer.copy_open('../lib/cases/HTTP接口用例.xls',
                     '../lib/results/result-HTTP接口用例.xls')
    sheetname = writer.get_sheets()
    sheetname = reader.get_sheets()
    for sheet in sheetname:
        # 设置当前读写都是当前sheet页面
        reader.set_sheet(sheet)
        writer.set_sheet(sheet)
        # 默认都写在第7列
        writer.clo = 7

        # 遍历读取所有的sheet页面的内容
        for i in range(reader.rows):
            line = reader.readine()
            # 如果第一列或者第二列有内容,就是分组信息,不运行
            if len(line[0]) > 0 or len(line[1]) > 0:
                pass
            else:
                print(line)
                writer.row = i
                func = getfunc(line, http)
                lenargs = getargs(func)
                run(func, lenargs, line)
    writer.save_close()
Esempio n. 5
0
# -*- coding: UTF-8 -*-
import inspect, sys, datetime
from common.Excel import Reader, Writer
from common import logger
import threading

reader = Reader()
writer = Writer()
alllist = []
runtype = 'WEB'
title =''
lock = threading.Lock()

# 反射获取关键字
def geffunc(line, http):
    func = None
    try:
        func = getattr(http, line[0])
    except Exception as e:
        print(e)
    return func

# 反射获取参数
def getargs(func):
    if func:
        args = inspect.getfullargspec(func).__str__()
        args = args[args.find('args=') + 5:args.find(', varargs')]
        args = eval(args)
        args.remove('self')
        l = len(args)
Esempio n. 6
0
def runCases():
    global casepath, resultpath
    reader = Reader()
    writer = Writer()
    web = Web(writer)
    reader.open_excel(casepath)
    # 第一行
    reader.readline()
    # 第二行
    line = reader.readline()
    runtype = line[1]
    print(runtype)
    if runtype == 'WEB':
        obj = Web(writer)
    if runtype == 'HTTP':
        obj = HTTP(writer)

    writer.copy_open(casepath, resultpath)
    sheetname = reader.get_sheets()
    writer.set_sheet(sheetname[0])
    writer.write(1, 3,
                 str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
    for sheet in sheetname:
        # 设置当前读写的sheet页面
        reader.set_sheet(sheet)
        writer.set_sheet(sheet)
        # 默认写第7列
        writer.clo = 7

        for i in range(reader.rows):
            line = reader.readline()
            # 如果第一列或者第二列有内容,就是分组信息,不运行
            if len(line[0]) > 0 or len(line[1]) > 0:
                pass
            else:
                # 从excel读取的每行数据
                # logger.info(line)
                writer.row = i
                func = geffunc(line, obj)
                lenargs = getargs(func)
                run(func, lenargs, line)

    writer.set_sheet(sheetname[0])
    writer.write(1, 4,
                 str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
    writer.save_close()
Esempio n. 7
0
def runCase():
    global casepath, resultpath
    r = Reader()
    w = Writer()

    r.open_excel(casepath)  #打开表,默认为第一个sheet
    w.copy_open(casepath, resultpath)
    sheetname = r.get_sheets()

    #根据表格的配置,创建不同的对象,例如表中第2行第2个字段为WEB,即创建WEB()对象
    way = r.getparameter('1', '1')
    if way == 'APP':
        obj = APP(None)
    elif way == 'HTTP':
        obj = HTTP(w)
    elif way == 'SOAP':
        obj = SOAP(w)
    elif way == 'WEB':
        obj = WEB()

    w.set_sheet(sheetname[0])
    w.write(2, 3, str(
        datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))  # StartTime

    for sheet in sheetname:
        #设置读写都是当前的sheet页面
        r.set_sheet(sheet)
        w.set_sheet(sheet)
        w.clo = 7  #写入的列数以固定,所以设置列数为第8列,!第一列为0
        for i in range(r.rows):
            line = r.readline()
            w.row = i  #读到第几行就写入第几行
            print(line)
            if len(line[0]) > 0 or len(line[1]) > 0:
                continue
            else:
                # 接口类型设置2
                func = get_func(obj, line)

                L = get_args(func)
                run(func, L, line)

    w.set_sheet(sheetname[0])
    w.write(2, 4, str(
        datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))  #EndTime
    w.save_close()
Esempio n. 8
0
        func(line[4], line[5], line[6])
        return
    else:
        print('暂时不支持超过3个参数的关键字')


# 读取配置信息
config.get_config('./conf/conf.properties')
# 数据库初始化
mysql = Mysql()
mysql.init_mysql('./conf/userinfo.sql')
# 逐行读取excel
casename = 'Web'
reader = Reader()
reader.open_excel('./lib/cases/%s.xls' % casename)
writer = Writer()
writer.copy_open('./lib/cases/%s.xls' % casename,
                 './lib/results/result-%s.xls' % casename)

sheetname = reader.get_sheets()
reader.readline()
casetype = reader.readline()[1]
obj = None  # 执行用例的关键字对象
if casetype == 'HTTP':
    # 执行http接口自动化
    obj = HTTP(writer)
elif casetype == 'SOAP':
    obj = SOAP(writer)
elif casetype == 'WEB':
    obj = Web(writer)
elif casetype == 'APP':
Esempio n. 9
0
    if len(args) == 1:
        func(line[4])
        return
    if len(args) == 2:
        func(line[4], line[5])
        return
    if len(args) == 3:
        func(line[4], line[5], line[6])
        return
    print("warning: 目前仅支持三个以内的参数")


casename = "SOAP"
reader = Reader()
reader.open_excel("./lib/cases/" + casename + ".xls")
writer = Writer()
writer.copy_open('./lib/cases/' + casename + '.xls',
                 './lib/results/' + casename + '-result.xls')
sheetnames = writer.get_sheets()

reader.readline()
caseType = reader.readline()[1]
http = None
if caseType == 'HTTP':
    http = HTTP(writer)
elif caseType == 'SOAP':
    http = SOAP(writer)

#开始执行时间
writer.set_sheet(sheetnames[0])
writer.write(1, 3, str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))