Exemple #1
0
    def executeAndAssert(processname, methodname, casedata, casename,
                         filename):
        #初始化

        #前置

        #执行

        #后置

        #清理

        pd = publicData.instance()
        #初始化
        initSqlFile = r'%s\sql\%s_%s_init.sql' % (pd.getMainDir(), methodname,
                                                  casename)
        if os.path.exists(initSqlFile):
            dbConn = dh.DBConn.instance()
            dbConn.exeSqlFile(initSqlFile)
        try:
            response = AssertHelper.__assertByMethod(methodname, casedata,
                                                     processname, filename)
            if response.status_code == 200:
                AssertHelper.__assertResponse(processname, methodname,
                                              casedata.get('name'),
                                              response.text, filename)
        finally:
            #结果写入数据库
            # pd.getProjectName(),pd.getSuiteName(),casename,None,methodname,
            pass
Exemple #2
0
    def __init__(self):
        if self.__cursor == None and self.__cursor == None:
            pd = publicData.instance()
            html = etree.parse(r"%s\config\config.xml" % (pd.getMainDir()))
            result = html.xpath('//config/database')
            if len(result) == 0:
                raise NameError("database not config")

            host = result[0].find('host').text
            port = int(result[0].find(
                'port').text) if result[0].find('port').text != None else None
            username = result[0].find('username').text
            password = result[0].find('password').text
            db = result[0].find('db').text

            if result[0].get('name') == 'sqlserver':
                self.__conn = pymssql.connect(host=host,
                                              user=username,
                                              password=password,
                                              database=db,
                                              charset="utf8")
            elif result[0].get('name') == 'mysql':
                self.__conn = pymysql.connect(
                    host=host,
                    port=port,
                    user=username,
                    password=password,
                    database=db,
                    charset="utf8",
                    cursorclass=pymysql.cursors.DictCursor)
            self.__cursor = self.__conn.cursor()
Exemple #3
0
 def getoutput(key):
     pd = publicData.instance()
     lock = threading.Lock()
     lock.acquire()
     try:
         return pd.getOutput('%s_%s' %
                             (key, threading.currentThread().ident))
     finally:
         lock.release()
Exemple #4
0
 def getDebugCaseName(path, methodname, filename):
     pd = publicData.instance()
     html = etree.parse(path)
     methodList = html.xpath(
         r"//suite[@name='%s']/files/file[@name='test_%s']/Method" %
         (pd.getSuiteName(), filename))
     for method in methodList:
         if method.text.endswith(methodname):
             return method.text
     return None
Exemple #5
0
 def initPublicData(projectname):
     pd = publicData.instance()
     mainhtml = etree.parse('main.xml')
     runmode = mainhtml.xpath('//run/mode')[0].text
     proconfig = etree.parse(r'tests\%s\config\%s.xml' %
                             (projectname, runmode))
     suitename = proconfig.xpath('//suite')[0].get('name')
     pd.setProjectConfig(projectname, suitename)
     pd.setRunMode(runmode)
     return pd
Exemple #6
0
 def __getvaluebysql(sqlname, param):
     pd = publicData.instance()
     path = r'%s\config\sql.xml' % (pd.getMainDir())
     html = etree.parse(path)
     sql = html.xpath(r"//sqllist/sql[@name='%s']" % (sqlname))[0].text
     if param != None:
         res = param.split(',')
         for index in range(0, len(res)):
             sql = str.replace(sql, '%param%', res[index], 1)
     # print sql
     dbConn = dh.DBConn.instance()
     return dbConn.getValueBySql(sql)
Exemple #7
0
    def getValue(file, method, project):
        pa = []
        casename = None
        pd = publicData.instance()
        if pd.getMainDir() == "":
            pd = FuncUtil.initPublicData(project)  #只初始化一次
        filename = file[5:-3]
        path = '%s\data\%s.xml' % (pd.getMainDir(), filename)

        # DEBUG模式,有可能会指定TESTCASE
        if pd.getRunMode().lower() == "debug":
            casename = xmlUtil.getDebugCaseName(
                '%s\config\debug.xml' % (pd.getMainDir()), method, filename)

        # 指定的TESTCASE
        if casename != None:
            result = xmlUtil.getDataByMethodCase(path, method, casename)
        else:  #全部的testcase
            result = xmlUtil.getDataByMethod(path, method)

        # 非单接口形式,而是接口流程
        if len(result) == 0:
            result = xmlUtil.getProcessDataByMethod(path, method)
            if len(result) > 0:
                for testmethod in result[0].getchildren():
                    for testcase in testmethod.getchildren():
                        pa.append([
                            method,
                            testmethod.get('name'), testcase,
                            testcase.get('name'), filename
                        ])
        else:
            for i in range(len(result)):
                pa.append([
                    method, method, result[i], result[i].get('name'), filename
                ])

        if pa == []:
            raise Exception("文件%s中的方法%s未配置数据" % (file, method))
        else:
            return pa
Exemple #8
0
    def __assertResponse(processname, methodname, casename, response,
                         filename):
        pd = publicData.instance()
        path = r'%s\asset\%s.xml' % (pd.getMainDir(), filename)
        assertList = xmlUtil.getAssert(path, processname, methodname, casename)
        for assertEle in assertList:
            operator = assertEle.get('operator') if assertEle.get(
                'operator') != None else "equal"  #默认的operator是equal

            type = assertEle.get('type')
            method = assertEle.get('method') if assertEle.get(
                'method') != None else "equal"  #默认的method是equal
            param = assertEle.get('param')
            val = assertEle.get('value')
            func1 = {
                'type': type,
                'method': method,
                'param': param,
                'value': val
            }  #第一个函数
            method1 = assertEle.get('method1')
            if method1 != None:
                type1 = assertEle.get('type1')
                param1 = assertEle.get('param1')
                val1 = assertEle.get('value1')
                func2 = {
                    'type': type1,
                    'method': method1,
                    'param': param1,
                    'value': val1
                }  #第二个函数
                getattr(AssertMethed, 'comparetwomethod')(response,
                                                          assertEle.text,
                                                          operator,
                                                          func1=func1,
                                                          func2=func2)
            else:
                getattr(AssertMethed, method)(response,
                                              assertEle.text,
                                              operator,
                                              func1=func1)
Exemple #9
0
runmode = html.xpath('//run/mode')[0].text  #运行模式,RUN或者DEBUG
projects = html.xpath('//run/project')[0].text.split(',')  #运行的项目名,逗号分隔
allurepath = html.xpath('//run/allure')[0].text  #ALLURE_COMMANDER_LINE安装路径
webserverdir = html.xpath('//run/serverdir')[0].text  #展示ALLURE报表的WEB服务器地址
reporttype = html.xpath('//run/report')[0].text  #报表方式

#迭代项目执行
for curProject in projects:
    #项目目录
    basedir = r'tests\%s' % (curProject)
    #运行文件
    runfile = r'%s\config\run.xml' % (
        basedir) if runmode == "run" else r'%s\config\debug.xml' % (basedir)

    #公共数据初始化
    pd = publicData.instance()
    pd = FuncUtil.initPublicData(curProject)
    #sql初始化
    initSqlFile = r'%s\sql\init.sql' % (basedir)
    if runmode == "run" and os.path.exists(initSqlFile):
        dbConn = dh.DBConn.instance()
        dbConn.exeSqlFile(initSqlFile)

    #删除日志文件
    if os.path.exists('.\log\log.log'):
        os.remove('.\log\log.log')

    #项目下的TEST文件或DEBUG文件,当前默认一个项目一个SUITE生成一个LOG文件
    try:
        htmltest = etree.parse(runfile)
        suite = htmltest.xpath('//suite')[0]