示例#1
0
class AppiumDriver(object):

    def __init__(self, driver):
        self.android = AdbCmder()
        self.log4py = LoggingController()
        self.driver = driver
        self.taction = TouchAction(self.driver)
        self.path_get = GetAllPathController()
        self.actions = []
        self.xml_file_path = self.path_get.get_dumpxml_path()
        self.pattern = re.compile(r"\d+")
        self.capturePath = self.path_get.get_capture_path()

    def is_displayed(self, by, value):
        is_displayed = False
        try:
            is_displayed = self.driver.find_element(by, value).is_displayed()
            self.log4py.debug("element [ " + str(value) + " ] displayed? " + str(is_displayed))
        except Exception, e:
            self.log4py.error("element元素没有点位到"+str(e))
        return is_displayed
示例#2
0
class ExcelManager(object):
    def __init__(self, excelfilename):
        self.excelfilename = excelfilename
        fc = FileChecKController()
        boolean = fc.is_has_file(excelfilename)
        if boolean:
            self.excel_path = fc.get_fileabspath()
        self.log4py = LoggingController()

    def read_excel(self, excel_sheet_name):
        """打开目标excel文件  r--读,w--写(覆盖),a--追加写"""
        xls_data = xlrd.open_workbook(self.excel_path, "rb")
        table = xls_data.sheet_by_name(excel_sheet_name)  #打开sheet页
        self.log4py.debug("打开的%s文件中的sheet页" % self.excelfilename)
        return table  # 将指定的sheet页对象返回给调用者

    def writ_excel(self, row, column, value):
        x_data = xlrd.open_workbook(self.excel_path, "rb")  #只能是xls文件
        copy_sheet = copy(x_data)  #copy,并对附件进行操作
        write_xls = copy_sheet.get_sheet(0)  #得到附件中的sheet页
        write_xls.write(row, column, value)  #将测试的结果追加到附件中sheet页中每一行的后面
        copy_sheet.save(self.excel_path)  #覆盖保存(注意编码错误)
def html_reporter():
    logger = LoggingController()
    fc = FileChecKController()
    pro_path = fc.getProjectPath()
    boolean = fc.is_has_file("framework.ini")
    if boolean:
        inipath = fc.get_fileabspath()
        fw_conf = ConfigController(inipath)
    htmlrp_path = fw_conf.get("htmlreportPath", "htmlreportPath")
    htmreportl_abs_path = os.path.join(pro_path,htmlrp_path)
    timecurrent = DateTimeManager().formatedTime("%Y-%m-%d-%H-%M-%S")
    logger.debug("=====创建了一个html文件报告,路径是::"+htmreportl_abs_path)
    file_path = str(htmreportl_abs_path)+timecurrent+"-LDP-TestingRreporter.html"
    try:
        if os.path.exists(file_path):
            html_obj = open(file_path, "a") #打开文件   追加
            return html_obj
        else:
            html_obj = file(file_path, "wb+")
            return html_obj
    except Exception, e:
        logger.error("创建html_reporter出现错误"+str(e))
示例#4
0
class EmailController(object):
    def __init__(self):
        self.fc = FileChecKController()
        bools = self.fc.is_has_file("email.ini")
        if bools:
            fp = self.fc.get_fileabspath()
            conf = ConfigController(fp)
            self.smtp_host = conf.get("emails", "smtp_host")
            self.pop3_host = conf.get("emails", "pop3_host")
            self.receiver = conf.get("emails", "receiver").split(",")
            self.receiver_pa = conf.get("emails", "receiver_pa")
            self.sender = conf.get("emails", "sender")
            self.sender_pa = conf.get("emails", "sender_pa")
        self.log4py = LoggingController()

    def send_email_is_html(self):
        latestfpath, fname, currentfolder = self.fc.get_LatestFile()
        msgRoot = MIMEMultipart('related')
        ff = open(latestfpath, 'rb')
        message = MIMEText(ff.read(), 'html', 'utf-8')
        ff.close()
        message['From'] = self.sender
        #message['To'] = self.receiver
        subject = '实验室数字化平台-自动化测试报告'
        message['Subject'] = Header(subject, 'utf-8')
        msgRoot.attach(message)
        try:
            smtpObj = smtplib.SMTP()
            smtpObj.connect(self.smtp_host)
            smtpObj.login(self.sender, self.sender_pa)
            smtpObj.sendmail(self.sender, self.receiver, msgRoot.as_string())
            self.log4py.debug("SendEmail_withFile邮件发送成功")
            smtpObj.close()
        except Exception, e:
            print e
            self.log4py.error("Error: 无法发送邮件::" + str(e))
class MySQLController(object):
    def __init__(self):
        self.logger = LoggingController()
        self.fc = FileChecKController()
        boolean = self.fc.is_has_file("db.ini")
        if boolean:
            self.inipath = self.fc.get_fileabspath()
        self.conf = ConfigController(self.inipath)
        self.host = str(self.conf.get("dbset", "host"))
        self.port = int(self.conf.get("dbset", "port"))
        self.user = str(self.conf.get("dbset", "user"))
        self.passwd = str(self.conf.get("dbset", "passwd"))
        self.db = str(self.conf.get("dbset", "db"))
        self.charset = str(self.conf.get("dbset", "charset"))
        self.conn = mysqldb.Connect(self.host, self.user, self.passwd, self.db,
                                    self.port, self.charset)
        self.logger.debug("数据库初始化完成" + self.host + str(self.port) + self.db +
                          self.charset)

    def execute_select(self, sql):
        cursor = self.conn.cursor()
        try:
            cursor.execute(sql)
            self.logger.debug("check_acct_available :" + sql)
            res = cursor.fetchall()
            if len(res) < 1:
                self.logger.error("%s执行查询内容不存在" % sql)
            return res
        finally:
            cursor.close()
        return None

    def execute_add_one(self, sql):
        cursor = self.conn.cursor()  #操作数据库的游标
        try:
            cursor.execute(sql)  #执行sql语句
            if cursor.rowcount == 1:
                self.logger.debug("%s添加成功" % sql)
                self.conn.commit()  #执行成功后向数据库进行提交
                return True
        except Exception, e:
            self.conn.rollback()
            self.logger.error("插入数据出现错误" + str(e))
        finally:
class CreateConfigFile(object):
    def __init__(self):
        self.cfg = ConfigParser.ConfigParser()
        self.log4py = LoggingController()
        self.path = (os.getcwd()).split('src')[0] + "\\testconfig"

    def set_appium_uuids_ports(self, device_list, port_list):
        """
        遍历list,按照下表进行对应映射
        :param device_lsit: 手机uuid
        :param port_list: pc启动的appium服务端口
        """
        f_path = self.create_config_file(self.path)

        if len(device_list) > 0 and len(port_list) > 0:
            self.cfg.read(f_path)
            for i in range(len(device_list)):
                filed = device_list[i]
                key = filed
                value = port_list[i]
                # 因为是覆盖写入,没有section,需要先添加再设置, 初始化的服务都加一个run的标识
                self.cfg.add_section(filed)
                self.cfg.set(filed, key, value)
                self.cfg.set(filed, "run", "0")
            self.cfg.write(open(f_path, 'wb'))
            self.log4py.debug(
                "设备sno与appium服务端口映射已写入appiumService.ini配置文件:{}--{}".format(
                    key, value))

    def set_appium_uuid_port(self, device, port, bp):
        """
        如果这样一个一个的写入到配置文件中,是追加还是覆盖?如果是覆盖的,服务启动完成后就剩一个配置,所以不行
        如果是追加,需要判断配置文件中是否已经有了相同的section,有就更新,没有就添加
        :param device: 手机uuid
        :param port pc启动的appium服务端口
        """
        f_path = os.path.join(self.path, 'appiumService.ini')
        if not os.path.exists(f_path):
            os.makedirs(f_path)
        if device is not None and port is not None:
            self.cfg.read(f_path)
            sec = device
            key = sec
            value = port
            if sec in self.cfg.sections():
                self.cfg.set(sec, key, value)
                self.cfg.set(sec, "bp", bp)
                self.cfg.set(sec, "run", "0")
            else:
                self.cfg.add_section(sec)
                self.cfg.set(sec, key, value)
                self.cfg.set(sec, "bp", bp)
                self.cfg.set(sec, "run", "0")
            self.cfg.write(open(f_path, 'wb'))
            self.log4py.debug(
                "设备sno与appium服务端口映射已写入appiumService.ini配置文件:{}--{}".format(
                    key, value))

    def create_config_file(self, path):
        """
        如果path这个文件不存在,就创建这个文件;存在就清空文件
        :param path: 
        :return: 
        """
        if not os.path.exists(path):
            os.makedirs(path)
        f_path = os.path.join(path, 'appiumService.ini')
        f = open(f_path, "wb")
        f.close()
        return f_path

    def get_all_appium_server_port(self):
        f_path = os.path.join(self.path, 'appiumService.ini')
        port_list = []
        if os.path.exists(f_path):
            self.cfg.read(f_path)
            section_list = self.cfg.sections()
            for sl in section_list:
                port_list.append(self.cfg.get(sl, sl))
                port_list.append(self.cfg.get(sl, "bp"))
        return port_list