def setUp(self):
     global driver, data
     data = GetValue()
     browser = GetPath(data.getvalue('driver'))
     driver = webdriver.Chrome(browser.get_filePath())
     user = Login(driver)
     user.login(data.getvalue('address'), data.getvalue('account'),
                data.getvalue('password'))
Exemplo n.º 2
0
 def __init__(self):
     self.__get_ini = GetIniData()  # 实例化GetIniData
     __json_path = GetPath().get_path(GetIniData().get_ini_data(
         "Path", "caseDataJson"))  # 返回json文件位置
     self.json_data = GetJsonData().get_json_data(__json_path)  # 获取json数据
     self._excel_file = GetPath().get_path(GetIniData().get_ini_data(
         "Excel", "excelPath"))  # 获取Excel地址
     self._excel_sheet_name = GetIniData().get_ini_data(
         "Excel", "sheetName")  # 获取ini文件中sheet页名字
Exemplo n.º 3
0
    def __get_dms_element(self):

        yaml_path = GetPath().get_path(
            r'AutoTesting\base_page\element.yaml')  # 获取element路径
        dms_base_element = GetYamlData().get_yaml_data(
            yaml_path)  # 获取element.yaml中的数据,返回字典。
        return dms_base_element
Exemplo n.º 4
0
    def report(self):
        global path, data

        data = GetValue()
        now_time = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
        path = GetPath(data.getvalue('report_path') + '%s.html' % now_time)
        report_path = path.get_filePath()

        with open(report_path, 'wb') as fp:
            global runner
            runner = HTMLTestRunner.HTMLTestRunner(
                stream=fp,
                title=data.getvalue('title'),
                description=data.getvalue('description'))

            suiteTest = unittest.TestSuite()

            path = GetPath(data.getvalue('cases_path'))

            all_cases = unittest.defaultTestLoader.discover(
                path.get_filePath(), 'test_*.py')

            for case in all_cases:

                suiteTest.addTest(case)

            runner.run(suiteTest)

        email = Smtp()
        email.sendEmail(report_path)
Exemplo n.º 5
0
    def send_email(self, report_path):
        """
        发送邮件
        :param report_path:附件地址
        :return:
        """
        global smtp

        __PATH = GetPath().get_path('gmp\\common\\BOXconfig.yaml')  # 获取配置文件地址
        __CONFIG = GetYamlData().get_yaml_data(__PATH)['SendEmail']  # 获取配置文件内容

        smtpserver = __CONFIG['SMTPSERVER']  # 设置邮箱服务器与端口
        port = __CONFIG['PORT']
        sender = __CONFIG['SENDER']  # 发件人
        pwd = __CONFIG['PWD']  # 授权码
        receiver = __CONFIG['receiver']  # 收件人

        msg = MIMEMultipart()
        msg['from'] = sender  # 填写发件人
        msg['to'] = receiver  # 填写收件人
        msg['subject'] = 'test'  # 主题
        with open(report_path, 'rb') as f:  # 打开附件并读取内容
            data = f.read()
        report_text = MIMEText(data, 'html', 'utf8')  # 写入邮件内容
        msg.attach(report_text)
        att = MIMEText(data, 'base64', 'utf8')  # 添加附件
        att['Content-Type'] = 'application/octet-stream'  # 需要添加附件,设置type
        att['Content-Disposition'] = 'attachment;filename = %s' % report_path
        msg.attach(att)

        smtp = smtplib.SMTP()  # 实例化邮件服务器对象
        try:
            smtp.connect(smtpserver, port)  # 连接服务器
        except Exception as contE:
            print(contE, '服务器连接失败..')
            sys.exit()

        try:
            smtp.login(sender, pwd)  # 登录
        except Exception as loginE:
            print(loginE, '账号或者密码错误')
            sys.exit()

        try:
            smtp.sendmail(sender, receiver.split(','), msg.as_string())  # 发送邮件
            smtp.close()  # 关闭链接
            print('邮件发送完成')
        except Exception as sendE:
            print(sendE, '发送失败,邮箱设置错误')
            sys.exit()
Exemplo n.º 6
0
class GetIniData:
    __CONFIG_PATH = r"AutoTesting\config\baseconfig.ini"

    def __init__(self, ini_path=__CONFIG_PATH):
        self.__get_path = GetPath()
        self.__sysPath = self.__get_path.get_path(ini_path)
        self.__config = ConfigParser()
        self.__config.read(self.__sysPath, encoding="utf-8")

    def get_ini_data(self, *args):
        """
        获取ini文件的内容。
        :param args:
        :return:
        """
        try:
            return self.__config.get(*args)
        except TypeError:
            raise ValueError("请传入正确的参数:(section,option)")
Exemplo n.º 7
0
    def __get_full_path(self):
        """
        在results文件夹下,创建一个以年月日命名的文件夹。
        :return: 返回文件夹创建后的全路径
        """
        now_time = datetime.now().strftime("%Y-%m-%d")
        path = "AutoTesting\\results\\"
        result_path = GetPath().get_path(path)
        full_path = os.path.join(result_path, now_time)

        try:
            if os.path.isdir(full_path):
                return full_path
            else:
                os.mkdir(full_path)
                return full_path

        except FileNotFoundError:
            os.mkdir(result_path)
            os.mkdir(full_path)
            return full_path
Exemplo n.º 8
0
 def __init__(self, datapath='data\\params.txt'):  #win/linux路径不同,需要修改
     path = GetPath(datapath)
     self.datapath = path.get_filePath()
Exemplo n.º 9
0
 def __init__(self, ini_path=__CONFIG_PATH):
     self.__get_path = GetPath()
     self.__sysPath = self.__get_path.get_path(ini_path)
     self.__config = ConfigParser()
     self.__config.read(self.__sysPath, encoding="utf-8")