Пример #1
0
    def shortNameToFileName(cls):
        log.warning('run_case:%s' % run_case)
        # 指定哪个平台的用例
        case_platform = Run.Main
        if case_platform in 'api':
            CaseSummary_path = Os.ABSpath() + "/Src/Conf/ApiCaseSummary.yml"
        else:
            CaseSummary_path = Os.ABSpath() + "/Src/Conf/UiCaseSummary.yml"

        # 找到指定平台的用例集
        run_case_name = []
        main_case = []
        case_summary = readConfig(CaseSummary_path)
        if case_summary:
            for key, value in case_summary.items():
                case_summary_part = readConfig(CaseSummary_path)[key]
                # 若case_summary_part 为空时,略过
                try:
                    for x, y in case_summary_part.items():
                        # 找到所有用例简称 a01, 如果与传参相等则返回该用例文件名
                        if type(run_case) != list:
                            if run_case in x:
                                log.debug(y)
                                return y, key
                        elif type(run_case) == list:
                            for q in range(0, len(run_case)):
                                if run_case[q] in x:
                                    run_case_name.append(y)
                                    main_case.append(key)
                except:
                    pass
            log.debug('run_case_name: %s' % run_case_name)
            log.debug('main_case: %s' % main_case)
            return run_case_name, main_case
Пример #2
0
 def connect(cls, database='', who='Null'):
     # 链接数据库
     conf_path = ABSpath() + '/Src/Conf/Config.yml'
     if who in 'short_url':
         mysql = readConfig(conf_path)['short_url']
     else:
         mysql = readConfig(conf_path)['local_mysql']
         if platform.system() == 'Linux':
             mysql = readConfig(conf_path)['xxtao_mysql']
     ip = mysql['ip']
     username = mysql["username"]
     password = mysql["password"]
     if not database:
         database = mysql["database"]
     try:
         db = MySQLdb.connect(ip,
                              username,
                              password,
                              database,
                              charset='utf8',
                              cursorclass=MySQLdb.cursors.DictCursor)
         log.debug(db)
         return db, db.cursor()
     except Exception as msg:
         raise msg
Пример #3
0
    def shortNameToFileName(cls):
        log.warning('run_case:%s' % run_case)
        # 指定哪个平台的用例
        case_platform = Run.Main
        if case_platform in 'api':
            CaseSummary_path = Misc.ABSpath() + "/Src/Conf/ApiCaseSummary.yml"
        else:
            CaseSummary_path = Misc.ABSpath() + "/Src/Conf/UiCaseSummary.yml"

        # 找到指定平台的用例集
        run_case_name = []
        main_case = []
        case_summary = readConfig(CaseSummary_path)
        if case_summary:
            for key, value in case_summary.items():
                case_summary_part = readConfig(CaseSummary_path)[key]
                # 若case_summary_part 为空时,略过
                try:
                    for x, y in case_summary_part.items():
                        # 找到所有用例简称 a01, 如果与传参相等则返回该用例文件名
                        if type(run_case) != list:
                            if run_case in x:
                                log.debug(y)
                                return y, key
                        elif type(run_case) == list:
                            for q in range(0, len(run_case)):
                                if run_case[q] in x:
                                    run_case_name.append(y)
                                    main_case.append(key)
                except:
                    pass
            log.debug('run_case_name: %s' % run_case_name)
            log.debug('main_case: %s' % main_case)
            return run_case_name, main_case
Пример #4
0
    def __init__(self, name=None):
        super(Log, self).__init__(self)
        #建立Log目录
        new_dirname = "Log"
        new_path = os.path.join(ABSpath()+"/Output", new_dirname)
        Config_path = ABSpath()+"/Src/Conf/Config.yml"
        level = Run.log
        if not os.path.isdir(new_path):
            os.makedirs(new_path)
        # 日志文件名
        if name is None:
            name = 'my.log'

        # 定义log存储路径
        if platform.system() == 'Windows':
            self.path = ABSpath() + readConfig(Config_path)['log']['path_win']
        elif platform.system() == 'Darwin' or platform.system() == 'Linux':
            self.path = ABSpath() + readConfig(Config_path)['log']['path_mac']

        self.filename = self.path+rq + '.log'

        self.name = name
        self.logger = logging.getLogger(self.name)
        # 创建一个handler,用于写入日志文件 (每天生成1个,保留10天的日志)
        fh = logging.handlers.TimedRotatingFileHandler(self.filename, 'D', 1, 10)

        fh.setLevel(logging.DEBUG)
        formatter = logging.Formatter(
            '%(asctime)s - %(levelname)s - %(filename)s[line:%(lineno)d] - %(message)s')
        fh.setFormatter(formatter)
        self.addHandler(fh)

        # 再创建一个handler,用于输出到控制台
        self.logger = logging.getLogger(self.name)
        self.logger = logging.getLogger(self.name)
        ch = logging.StreamHandler()
        logger = logging.getLogger(self.name)
        ch = logging.StreamHandler()
        if level in 'debug':
            ch.setLevel(logging.DEBUG)
        elif level in 'info':
            ch.setLevel(logging.INFO)
        elif level in 'error':
            ch.setLevel(logging.ERROR)
        elif level in 'notset':
            ch.setLevel(logging.NOTSET)
        else:
            ch.setLevel(logging.WARNING)
        # 定义handler的输出格式
        formatter = logging.Formatter(
            '%(asctime)s - %(levelname)s - %(filename)s[line:%(lineno)d] - %(message)s')
        ch.setFormatter(formatter)
        # 给logger添加handler
        self.addHandler(ch)
Пример #5
0
    def __init__(self, name=None):
        super(Log, self).__init__(self)
        # 建立Log目录
        new_dirname = "Log"
        new_path = os.path.join(ABSpath() + "/Output", new_dirname)
        Config_path = ABSpath() + "/Src/Conf/Config.yml"
        level = Run.log
        if not os.path.isdir(new_path):
            os.makedirs(new_path)
        # 日志文件名
        if name is None:
            name = "my.log"

        # 定义log存储路径
        if platform.system() == "Windows":
            self.path = ABSpath() + readConfig(Config_path)["log"]["path_win"]
        elif platform.system() == "Darwin" or platform.system() == "Linux":
            self.path = ABSpath() + readConfig(Config_path)["log"]["path_mac"]

        self.filename = self.path + rq + ".log"

        self.name = name
        self.logger = logging.getLogger(self.name)
        # 创建一个handler,用于写入日志文件 (每天生成1个,保留10天的日志)
        fh = logging.handlers.TimedRotatingFileHandler(self.filename, "D", 1, 10)

        fh.setLevel(logging.DEBUG)
        formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(filename)s[line:%(lineno)d] - %(message)s")
        fh.setFormatter(formatter)
        self.addHandler(fh)

        # 再创建一个handler,用于输出到控制台
        self.logger = logging.getLogger(self.name)
        self.logger = logging.getLogger(self.name)
        ch = logging.StreamHandler()
        logger = logging.getLogger(self.name)
        ch = logging.StreamHandler()
        if level in "debug":
            ch.setLevel(logging.DEBUG)
        elif level in "info":
            ch.setLevel(logging.INFO)
        elif level in "error":
            ch.setLevel(logging.ERROR)
        elif level in "notset":
            ch.setLevel(logging.NOTSET)
        else:
            ch.setLevel(logging.WARNING)
        # 定义handler的输出格式
        formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(filename)s[line:%(lineno)d] - %(message)s")
        ch.setFormatter(formatter)
        # 给logger添加handler
        self.addHandler(ch)
Пример #6
0
 def log_out_interface(cls, r="user/logout"):
     u'注销登录状态'
     url = readConfig(Config_path)['url_off'][0]
     log.debug(url)
     parameter = {"r": r}
     requests.get(url, params=parameter)
     log.debug(u'注销成功')
Пример #7
0
 def get_passcode(cls, phone):
     u'获取验证码'
     url = readConfig(Config_path)['url_off'][0]
     parameter = {"r": "user/code", "phone": phone}
     r = requests.get(url, params=parameter)
     q = r.json()
     p = json.dumps(q, sort_keys=True)
     log.debug(u'获取验证码')
     return p[-3]
Пример #8
0
 def enable_phone(cls):
     url1 = cls.url_category
     while True:
         phone = UserLogin.generate_phone()
         url_all = readConfig(Config_path)[url1]
         url = url_all.split(',')[0]
         log.debug("url:%s" % url)
         if UserLogin.inter_validation(r='user/checkphone',
                                       phone=phone,
                                       url=url):
             return phone
Пример #9
0
 def Falsecreenshot(cls, casename):
     """截图放到相应路径中"""
     cname = casename + datetime.datetime.now().strftime(
         "%Y%m%d.%H%M%S.%f")[:-3]
     # 截图创建路径
     FalseScreenshotPath = Os.ABSpath() + readConfig(
         Config_path)['path']['FalseScreenshot']
     log.debug(u'读取截图路径:' + str(FalseScreenshotPath))
     Os.mkdir(path=Os.ABSpath() + "/Output/Screenshot", name='Fail')
     cls.driver.get_screenshot_as_file(FalseScreenshotPath +
                                       "%s.png" % cname)
     log.debug(u'False截图成功')
Пример #10
0
 def Falsecreenshot(self, casename):
     """截图放到相应路径中"""
     if operation in ["chrome", "firfox", "ie"]:
         cname = casename + datetime.datetime.now().strftime("%Y%m%d.%H%M%S.%f")[:-3]
         # 截图创建路径
         FalseScreenshotPath = Misc.ABSpath() + readConfig(Config_path)["path"]["FalseScreenshot"]
         log.debug(u"读取截图路径:" + str(FalseScreenshotPath))
         Misc.mkdir(path=Misc.ABSpath() + "/Output/Screenshot", name="Fail")
         self.driver.get_screenshot_as_file(FalseScreenshotPath + "%s.png" % cname)
         log.debug(u"False截图成功")
     else:
         log.warning("未执行截图")
Пример #11
0
 def Falsecreenshot(cls, casename):
     """截图放到相应路径中"""
     if operation in ['chrome', 'firfox', 'ie']:
         cname = casename + datetime.datetime.now().strftime("%Y%m%d.%H%M%S.%f")[:-3]
         # 截图创建路径
         FalseScreenshotPath = Misc.ABSpath()+readConfig(Config_path)['path']['FalseScreenshot']
         log.debug(u'读取截图路径:' + str(FalseScreenshotPath))
         Misc.mkdir(path=Misc.ABSpath()+"/Output/Screenshot", name='Fail')
         cls.driver.get_screenshot_as_file(FalseScreenshotPath+"%s.png" % cname)
         log.debug(u'False截图成功')
     else:
         log.warning('未执行截图')
Пример #12
0
 def del_screen(cls, who=" None||Fail||Pass"):
     """
     删除全部截图
     :param who:  None||Fail||Pass
     :return:
     """
     try:
         FalseScreenshotPath = readConfig(Config_path_ym)['path']['FalseScreenshot']
         TrueScreenshotPath = readConfig(Config_path_ym)['path']['TrueScreenshot']
         Misc.mkdir(Misc.ABSpath()+"/Output/Screenshot", "Fail")
         Misc.mkdir(Misc.ABSpath()+"/Output/Screenshot", "Pass")
         if who == "Fail":
             Misc.del_file(dir=FalseScreenshotPath, filename='l')
         elif who == "Pass":
             Misc.del_file(dir=TrueScreenshotPath, filename='l')
         else:
             Misc.del_file(dir=FalseScreenshotPath, filename='l')
             Misc.del_file(dir=TrueScreenshotPath, filename='l')
     except Exception as msg:
         log.error(u'删除截图失败')
         print (msg)
         raise
Пример #13
0
 def del_screen(cls, who=" None||Fail||Pass"):
     """
     删除全部截图
     :param who:  None||Fail||Pass
     :return:
     """
     try:
         FalseScreenshotPath = readConfig(
             Config_path)['path']['FalseScreenshot']
         TrueScreenshotPath = readConfig(
             Config_path)['path']['TrueScreenshot']
         Os.mkdir(Os.ABSpath() + "/Output/Screenshot", "Fail")
         Os.mkdir(Os.ABSpath() + "/Output/Screenshot", "Pass")
         if who == "Fail":
             Os.del_file(dir=FalseScreenshotPath, filename='l')
         elif who == "Pass":
             Os.del_file(dir=TrueScreenshotPath, filename='l')
         else:
             Os.del_file(dir=FalseScreenshotPath, filename='l')
             Os.del_file(dir=TrueScreenshotPath, filename='l')
     except Exception as msg:
         log.error(u'删除截图失败')
         print msg
         raise
Пример #14
0
 def save_as_file(cls, comments, file_name='demand', write='a', path = cookfile_path):
     """
     追加文件内容
     :param comments:
     :return:
     """
     if path in 'chart':
         path = ABSpath() + readConfig(Config_path_ym)['path']['webapp']
     file_name = path + file_name
     fp = open(file_name, write)
     try:
         fp.write(str(comments) + ',')
     except Exception as msg:
         raise msg
     finally:
         fp.close()
Пример #15
0
    def url_target_Choose(cls, modules_path="/"):
        """
        默认选中:pc_xxtao
        可选值:
        1.m     = {m}
        2.pc    = {pc}
        3.api   = {api,a}
        :param modules_path:
        :return:
        """
        driver = cls.driver
        input_url = Run.url_target

        # 定义全部url列表
        url = readConfig(Config_path)
        if input_url in "www.xxtao.com":
            cls.url_category = "url_off"
        elif input_url in "www.wanpinghui.com":
            cls.url_category = "url_on"
        else:
            cls.url_category = "url_off"
        url_all = []
        read_url = url[cls.url_category]
        log.debug("read_url:%s" % read_url)
        url_by = read_url.split(',')
        for u in url_by:
            url_all.append(u)
        log.debug("url_all:%s" % url_all)
        if ',' not in modules_path:
            driver.get(url_all[2] + modules_path)
        url_by = modules_path.split(',')[0]
        modules_path_value = modules_path.split(',')[1]
        # m端
        if url_by == 'm' or url_by == 'M':
            driver.get(url_all[1] + modules_path_value)
            log.warning('main_domain=>' + url_all[1] + modules_path_value)
            return url_all[1] + modules_path_value
        # pc端
        if url_by == 'p' or url_by == 'P':
            driver.get(url_all[2] + modules_path_value)
            log.warning('main_domain=>' + url_all[2] + modules_path_value)
            return url_all[2] + modules_path_value
        # api 接口
        if url_by in 'api' or url_by in 'API':
            driver.get(url_all[0] + modules_path_value)
            log.warning('main_domain=>' + url_all[0] + modules_path_value)
            return url_all[0] + modules_path_value
Пример #16
0
    def url_target_Choose(self, modules_path="/"):
        """
        默认选中:pc_xxtao
        可选值:
        1.m     = {m}
        2.pc    = {pc}
        3.api   = {api,a}
        :param modules_path:
        :return:
        """
        driver = self.driver
        input_url = Run.url_target

        # 定义全部url列表
        url = readConfig(Config_path)
        if input_url in "www.xxtao.com":
            self.url_category = "url_off"
        elif input_url in "www.wanpinghui.com":
            self.url_category = "url_on"
        else:
            self.url_category = "url_off"
        url_all = []
        read_url = url[self.url_category]
        log.debug("read_url:%s" % read_url)
        url_by = read_url.split(",")
        for u in url_by:
            url_all.append(u)
        log.debug("url_all:%s" % url_all)
        if "," not in modules_path:
            driver.get(url_all[2] + modules_path)
        url_by = modules_path.split(",")[0]
        modules_path_value = modules_path.split(",")[1]
        # m端
        if url_by == "m" or url_by == "M":
            driver.get(url_all[1] + modules_path_value)
            log.warning("main_domain=>" + url_all[1] + modules_path_value)
            return url_all[1] + modules_path_value
        # pc端
        if url_by == "p" or url_by == "P":
            driver.get(url_all[2] + modules_path_value)
            log.warning("main_domain=>" + url_all[2] + modules_path_value)
            return url_all[2] + modules_path_value
        # api 接口
        if url_by in "api" or url_by in "API":
            driver.get(url_all[0] + modules_path_value)
            log.warning("main_domain=>" + url_all[0] + modules_path_value)
            return url_all[0] + modules_path_value
Пример #17
0
    def url_target_Choose(cls, modules_path="/", chrome_options=None):
        """
        默认选中:pc_xxtao
        可选值:
        1.m     = {m}
        2.pc    = {pc}
        3.api   = {api,a}
        :param modules_path:
        :return:
        """
        driver = cls.driver
        input_url = Run.url_target

        # 定义全部url列表
        url = readConfig(Config_path)
        if input_url in "www.xxtao.com":
            cls.url_category = "url_off"
        elif input_url in "www.wanpinghui.com":
            cls.url_category = "url_on"
        else:
            cls.url_category = "url_off"
        url_all = []
        read_url = url[cls.url_category]
        log.debug("read_url:%s" % read_url)
        url_by = read_url.split(',')
        for u in url_by:
            url_all.append(u)
        log.debug("url_all:%s" % url_all)
        if ',' not in modules_path:
            driver.get(url_all[2] + modules_path)
        url_by = modules_path.split(',')[0]
        modules_path_value = modules_path.split(',')[1]
        # m端
        if url_by == 'm' or url_by == 'M':
            driver.get(url_all[1] + modules_path_value)
            log.warning('main_domain=>'+url_all[1]+modules_path_value)
            return url_all[1]+modules_path_value
        # pc端
        if url_by == 'p' or url_by == 'P':
            driver.get(url_all[2] + modules_path_value)
            log.warning('main_domain=>' + url_all[2]+modules_path_value)
            return url_all[2]+modules_path_value
        # api 接口
        if url_by in 'api' or url_by in 'API':
            driver.get(url_all[0] + modules_path_value)
            log.warning('main_domain=>' + url_all[0]+modules_path_value)
            return url_all[0]+modules_path_value
Пример #18
0
    def generate_case_suite(cls, test_dir):
        """
        1.读取用例集配置文件,并将需要执行的用例复制到执行目录中
            who = ui / api
        2.根据传入参数run_case,将制定用例移入test_dir文件夹中
        :param test_dir:
        :return:
        """
        Config_path = Misc.ABSpath() + "/Src/Conf/Config.yml"
        try:
            test_dir = str(test_dir)
            casesummartLocalpath = ''
            category = ''
            main_path = []

            if Main in 'ui':
                casesummartLocalpath = "/Src/Conf/UiCaseSummary.yml"
                category = "UiCase"
            elif Main in 'api':
                casesummartLocalpath = "/Src/Conf/ApiCaseSummary.yml"
                category = "ApiCase"
            CaseSummary_path = Misc.ABSpath() + casesummartLocalpath
            log.debug(u'CaseSummary_path:%s' % CaseSummary_path)
            case_main = readConfig(Config_path)[category]
            # 全部可执行用例集及相应路径=》case_main
            log.debug('case_main:%s' % case_main)
            if case_main:
                # 通过用例小名进行测试
                if run_case_by_name == '' and type(run_case_by_name) != list:

                    if type(run_case) != list and run_case in 'all':
                        for main_name, main_case_path in case_main.items():
                            case = readConfig(CaseSummary_path)[main_name]
                            try:
                                for case_key, case_name in case.items():
                                    MainRelated.move_case(main_case_path, case_name, test_dir)
                            except:
                                log.warning("%s is null" % main_name)
                    else:
                        # 通过main_name确定main_case_path的值
                        run_case_name, main_case = MainRelated.shortNameToFileName()
                        for main_name, main_case_path in case_main.items():
                            log.debug('main_name:%s' % main_name)
                            if main_name in main_case:
                                main_path.append(main_case_path)
                                log.debug('main_path:%s' % main_path)

                        if type(run_case_name) != list:
                            MainRelated.move_case(main_path, run_case_name, test_dir)
                        elif type(run_case_name) == list:
                            for case_name in run_case_name:
                                MainRelated.move_case(main_path, case_name, test_dir)

                # 通过用例文件名进行测试
                else:
                    for main_name, main_case_path in case_main.items():
                        case = readConfig(CaseSummary_path)[main_name]
                        log.debug('main_name:%s' % main_name)
                        log.debug('main_case_path:%s' % main_case_path)
                        log.debug('case:%s' % case)
                        casename = []
                        # 统计当前main_case_path下所有的casename
                        try:
                            for case_key, case_name in case.items():
                                casename.append(case_name)
                        except:
                            pass
                        if case:
                            if type(run_case_by_name) != list:
                                # run_case_by_name 为默认值是'':
                                if run_case_by_name == '':
                                    for case_key, case_name in case.items():
                                        MainRelated.move_case(main_case_path, case_name, test_dir)
                                else:
                                    # run_case_by_name为字符串,指定:单一用例文件
                                    for casename_value in casename:
                                        if casename_value == run_case_by_name:
                                            case_name = run_case_by_name
                                            MainRelated.move_case(main_case_path, case_name, test_dir)

                            # run_case 为列表时:
                            elif type(run_case_by_name) == list:
                                # 传参run_case与当前main_case_path路径下casename 进行对比
                                for run_case_name in run_case_by_name:
                                    for casename_value in casename:
                                        if casename_value == run_case_name:
                                            case_name = run_case_name

                                            # 如果存在相同casename,则替换执行用例为传入参数,并进行移动
                                            MainRelated.move_case(main_case_path, case_name, test_dir)

            else:
                log.warning('case_main is Null')
        except Exception as msg:
            log.error(u'generate_case_suite=》fail')
            raise msg
Пример #19
0
 def __init__(cls):
     Config_path_ym = Misc.ABSpath() + "/Src/Conf/Config.yml"
     cookfile_path = Misc.ABSpath() + readConfig(Config_path_ym)['path']['global_dir']
Пример #20
0
import datetime,time
import random
import requests
import json
from Src.Function.LogMainClass import Log
from ReadConfig import readConfig

log = Log('Misc')

def ABSpath():
    """获取当前的绝对路径"""
    ABSPATH = os.path.abspath(sys.argv[0])
    ABSPATH = os.path.dirname(ABSPATH)
    return ABSPATH
Config_path_ym = ABSpath() + "/Src/Conf/Config.yml"
cookfile_path = ABSpath() + readConfig(Config_path_ym)['path']['global_dir']

class Misc:

    def __init__(cls):
        Config_path_ym = Misc.ABSpath() + "/Src/Conf/Config.yml"
        cookfile_path = Misc.ABSpath() + readConfig(Config_path_ym)['path']['global_dir']

    def __getCurrentFilePath(cls, is_path='no'):
        """
        返回当前文件的名称、文件名及路径
        :param is_path:
        :return:
        """
        if is_path == 'no':
            return os.path.basename(__file__)
Пример #21
0
def send_mail(send_file_path, send_who):
    """
    :param send_file_path: 测试报告文件路径
    :return:
    """
    Main = Run.Main
    input_url = Run.url_target
    config_file_path = Misc.ABSpath() + "/Src/Conf/Config.yml"
    email = readConfig(config_file_path)['email']
    smtpserver = email['mail_host']
    smtpuser = email['mail_user']
    password = email['mail_pass']
    mailto = []
    try:
        if send_who == "Null":
            # 拼装接收人
            if input_url in 'www.wanpinghui.com':
                receive_category = "email_receiver_wph"
                mailto = readConfig(config_file_path)[receive_category]
            elif input_url in 'www.xxtao.com':
                receive_category = "email_receiver_xxtao"
                mailto = readConfig(config_file_path)[receive_category]
        else:
            mailto = send_who
        log.debug("send_file_path:%s" % send_file_path)
        log.debug("smtpserver:%s" % smtpserver)
        log.debug("smtpuser:%s" % smtpuser)
        log.debug("password:%s" % password)
        log.debug("mailto:%s" % mailto)
        msg = MIMEMultipart()
        # 定义发送人
        msg['From'] = smtpuser

        # 定义接收邮件对象
        msg['To'] = ",".join(mailto)

        # 邮件标题
        run_case_total, run_pass_total, run_failures_total, run_error_total = GlobalVariable.parsing_string(
            GlobalVariable.get_value())
        title = "[" + str(input_url) + "|C:" + str(run_case_total) + "|P:" + str(run_pass_total) + "|F:" + str(
            run_failures_total) + "|E:" + str(run_error_total) + "]"
    except Exception as msg:
        raise msg

    if 'u' in Main:
        Subject = "%sUI_Report" % title
    else:
        Subject = "%sAPI_Report" % title

    times = GlobalVariable.get_times()
    if times in [49, 50]:
        Subject1 = "=>System_Push"
    else:
        Subject1 = ''
    Subject = Subject + Subject1
    msg['Subject'] = Header(Subject, 'utf-8').encode()
    msg["Accept-Language"] = "zh-CN"
    msg["Accept-Charset"] = "ISO-8859-1,utf-8"

    file_name = new_report(send_file_path)
    sendfile = send_file_path + file_name

    content1 = """<h3><a href = "http://pages.wph.xxtao.com/test-report/""" + file_name + """"">在线报告</a>||<a href = "http://at.test.xxtao.com/">实时监控系统</a><h3>"""
    content2 = "<h3>测试环境:[" + input_url + "] <h3>"
    content = content1 + content2
    fp = open(sendfile, 'rb')
    try:
        # 将html中内容贴在邮件正文中
        msg.attach(MIMEText(content + fp.read(), 'html', 'utf-8'))
    except Exception as msg:
        log.error(u'邮件发送失败')
        raise msg
    finally:
        fp.close()

        # 添加附件
        fp = open(sendfile, 'rb')
    try:
        part = MIMEApplication(fp.read())
        part.add_header('Content-Disposition', 'attachment', filename=file_name)
        msg.attach(part)
    except Exception as msg:
        log.error(u'邮件发送失败')
        raise msg
    finally:
        fp.close()

    try:
        # 发送邮件
        server = smtplib.SMTP()
        try:
            # 不加密形式
            server.connect(smtpserver, '25')
        except:
            # 通过ssl形式发送邮件
            server = smtplib.SMTP_SSL(smtpserver, '465')

        # log.debug(u'邮件日志'+str(server.set_debuglevel(1)))
        server.login(smtpuser, password)
        server.sendmail(smtpuser, mailto, msg.as_string())
        server.quit()
        log.debug(u'邮件发送成功')
    except Exception as msg:
        log.error(u'邮件发送失败')
        raise msg
Пример #22
0
# coding=utf-8
__author__ = 'xcma'
import urllib, urllib2, requests
import Run
import unittest, os, cookielib
from ReadConfig import readConfig
from LogMainClass import Log
from Misc import Misc
import sys

# utf-8
reload(sys)
sys.setdefaultencoding('utf8')
log = Log('Methods')
Config_path_ym = Misc.ABSpath()+"/Src/Conf/Config.yml"
cookfile_path = Misc.ABSpath() + readConfig(Config_path_ym)['path']['global_dir']
cookfile_name = readConfig(Config_path_ym)['cookfile_name']

# 获取主域名
input_url = Run.url_target
url_category = "url_off"
if input_url in "www.xxtao.com":
    url_category = "url_off"
elif input_url in "www.wanpinghui.com":
    url_category = "url_on"
else:
    url_category = "url_off"
url_all = readConfig(Config_path_ym)[url_category]
if ',' not in url_all:
    main_domain = url_all
else:
Пример #23
0
    def generate_case_suite(cls, test_dir):
        """
        1.读取用例集配置文件,并将需要执行的用例复制到执行目录中
            who = ui / api
        2.根据传入参数run_case,将制定用例移入test_dir文件夹中
        :param test_dir:
        :return:
        """
        Config_path = Os.ABSpath() + "/Src/Conf/Config.yml"
        try:
            test_dir = str(test_dir)
            casesummartLocalpath = ''
            category = ''
            main_path = []
            case = []
            main_case_path = ''
            if Main in'ui':
                casesummartLocalpath = "/Src/Conf/UiCaseSummary.yml"
                category = "UiCase"
            elif Main in 'api':
                casesummartLocalpath = "/Src/Conf/ApiCaseSummary.yml"
                category = "ApiCase"
            CaseSummary_path = Os.ABSpath() + casesummartLocalpath
            log.debug(u'CaseSummary_path:%s' % CaseSummary_path)
            case_main = readConfig(Config_path)[category]
            # 全部可执行用例集及相应路径=》case_main
            log.debug('case_main:%s' % case_main)
            if case_main:
                # 通过用例小名进行测试
                if run_case_by_name == '' and type(run_case_by_name) != list:

                    if type(run_case) != list and run_case in 'all':
                        for main_name, main_case_path in case_main.items():
                            case = readConfig(CaseSummary_path)[main_name]
                            try:
                                for case_key, case_name in case.items():
                                    MainRelated.move_case(main_case_path, case_name, test_dir)
                            except:
                                log.warning("%s is null" % main_name)
                    else:
                        # 通过main_name确定main_case_path的值
                        run_case_name, main_case = MainRelated.shortNameToFileName()
                        for main_name, main_case_path in case_main.items():
                            log.debug('main_name:%s' % main_name)
                            if main_name in main_case:
                                main_path.append(main_case_path)
                                log.debug('main_path:%s' % main_path)

                        if type(run_case_name) != list:
                            MainRelated.move_case(main_path, run_case_name, test_dir)
                        elif type(run_case_name) == list:
                            for case_name in run_case_name:
                                MainRelated.move_case(main_path, case_name, test_dir)

                # 通过用例文件名进行测试
                else:
                    for main_name, main_case_path in case_main.items():
                        case = readConfig(CaseSummary_path)[main_name]
                        log.debug('main_name:%s' % main_name)
                        log.debug('main_case_path:%s' % main_case_path)
                        log.debug('case:%s' % case)
                        casename = []
                        # 统计当前main_case_path下所有的casename
                        try:
                            for case_key, case_name in case.items():
                                casename.append(case_name)
                        except:
                            pass
                        if case:
                            if type(run_case_by_name) != list:
                                # run_case_by_name 为默认值是'':
                                if run_case_by_name == '':
                                    for case_key, case_name in case.items():
                                        MainRelated.move_case(main_case_path, case_name, test_dir)
                                else:
                                    # run_case_by_name为字符串,指定:单一用例文件
                                    for casename_value in casename:
                                        if casename_value == run_case_by_name:
                                            case_name = run_case_by_name
                                            MainRelated.move_case(main_case_path, case_name, test_dir)

                            # run_case 为列表时:
                            elif type(run_case_by_name) == list:
                                # 传参run_case与当前main_case_path路径下casename 进行对比
                                for run_case_name in run_case_by_name:
                                    for casename_value in casename:
                                        if casename_value == run_case_name:
                                            case_name = run_case_name

                                            # 如果存在相同casename,则替换执行用例为传入参数,并进行移动
                                            MainRelated.move_case(main_case_path, case_name, test_dir)
Пример #24
0
# coding=utf-8
__author__ = 'xcma'
import urllib, urllib2, json, requests
import Run
import unittest, os, shutil, cookielib
from ReadConfig import readConfig
from LogMainClass import Log
from Utils import ABSpath
import json ,time, sys

# utf-8
reload(sys)
sys.setdefaultencoding('utf8')
log = Log('Methods')
Config_path_ym = ABSpath()+"/Src/Conf/Config.yml"
cookfile_path = ABSpath() + readConfig(Config_path_ym)['path']['global_dir']
cookfile_name = readConfig(Config_path_ym)['cookfile_name']

# 获取主域名
input_url = Run.url_target
url_category = "url_off"
if input_url in "www.xxtao.com":
    url_category = "url_off"
elif input_url in "www.wanpinghui.com":
    url_category = "url_on"
else:
    url_category = "url_off"
url_all = readConfig(Config_path_ym)[url_category]
if ',' not in url_all:
    main_domain = url_all
else: