Exemple #1
0
 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()
Exemple #2
0
 def __init__(self):
     self.fkctl = FileChecKController()
     if self.fkctl.is_has_file("allpath.ini"):
         fp = self.fkctl.get_fileabspath()
     self.cfgctl = ConfigController(fp)
     self.log4py = LoggingController()
     self.pro_path = self.fkctl.get_project_path()
Exemple #3
0
 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()
Exemple #4
0
 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()
class JsonParser(object):
    def __init__(self):
        self.json_obj = None
        self.fc = FileChecKController()
        if self.fc.is_has_file("android_devices_info.json"):
            self.json_file_path = self.fc.get_fileabspath()
        self.log4py = LoggingController()

    def load_json(self,json_file_path):
        fin = open(json_file_path,"r")
        try:
            json_obj = json.load(fin)
            self.log4py.info("加载了%s文件"%json_file_path)
        except ValueError, e:
            json_obj = {}
        fin.close()
        return json_obj
 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)
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:
Exemple #8
0
class InitDriverOption(object):
    def __init__(self):
        self.log4py = LoggingController()

    def __get_devices(self):
        devices = []
        result = subprocess.Popen("adb devices", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.readlines()
        # 将readlines结果反向排序
        result.reverse()
        for line in result[1:]:
            if "attached" not in line.strip():
                devices.append(line.split()[0])
            else:
                break
        return devices

    def __get_info(self, sno):
        phone_brand = None
        phone_model = None
        os_version = None
        dpi = None
        image_resolution = None
        ip = None
        try:
            result = subprocess.Popen("adb -s %s shell getprop"%sno, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.readlines()
            for res in result:
                #系统版本
                if re.search(r"ro\.build\.version\.release",res):
                    os_version = (res.split(': ')[-1].strip())[1:-1]
                #手机型号
                elif re.search(r"ro\.product\.model",res):
                    phone_model = (res.split(': ')[-1].strip())[1:-1]
                #手机品牌
                elif re.search(r"ro\.product\.brand",res):
                    phone_brand = (res.split(': ')[-1].strip())[1:-1]
                #手机IP
                elif re.search(r'dhcp\.wlan0\.ipaddress', res):
                    ip = (res.split(': ')[-1].strip())[1:-1]
            return sno, phone_brand, phone_model, os_version, ip
        except Exception,e:
            self.log4py.error("Get device info happend ERROR :" + str(e))
            return None
Exemple #9
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
Exemple #10
0
class ServicePort(object):
    def __init__(self):
        self.log4py = LoggingController()
        path_obj = GetAllPathController()
        self.appium_log_path = path_obj.get_appium_logs_path()

    def is_port_used(self, port_num):
        """
        检查端口是否被占用
        netstat -aon | findstr port 能够获得到内容证明端口被占用
        :param port_num: 
        :return: 
        """
        flog = True
        try:
            port_res = subprocess.Popen(
                'netstat -ano | findstr %s' % port_num,
                shell=True,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE).stdout.readlines()
            if len(port_res) <= 0:
                self.log4py.info(str(port_num) + " port unoccupied.")
                flog = False
            else:
                self.log4py.error(str(port_num) + " port has been occupied.")
        except Exception, e:
            self.log4py.error(
                str(port_num) + " port get occupied status failure: " + str(e))
        return flog
class DeviceController():
    def __init__(self):
        self.android = AdbCmder()
        self.log4py = LoggingController()

    '''
        获取连接上电脑的手机设备,返回一个设备名的list
    '''

    def get_devices(self):
        sno_list = self.android.get_device_list()
        return sno_list

    '''
    根据不同的需求,设计了返回dict和list格式的两个function。
    '''

    def get_infos_as_dict(self):
        try:
            info = {}
            lists = self.get_devices()
            if not lists or len(lists) <= 0:
                self.log4py.info("NO Device connected")
                return None
            for sno in lists:
                sno, phone_brand, phone_model, os_version, ram, dpi, image_resolution, ip = self.get_info(
                    sno)
                info[sno] = {
                    "phone_brand": phone_brand,
                    "phone_model": phone_model,
                    "ram": ram,
                    "os_version": os_version,
                    "dpi": dpi,
                    "image_resolution": image_resolution,
                    "ip": ip
                }
            return info
        except TypeError, e:
            self.log4py.error(e)
            return None
Exemple #12
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)  #覆盖保存(注意编码错误)
class FileChecKController():
    def __init__(self):
        self.__fileabspath = None  #不可访问的
        self.__logger = LoggingController()

    '''
    是否存在指定的文件,路径默认为当前项目的目录
    '''

    def is_has_file(self, filename):
        propath = self.get_project_path()
        boolean = self.is_path_has_file(propath, filename)
        return boolean

    '''
    指定目录下是否存在指定的文件
    '''

    def is_path_has_file(self, path, filename):
        boolean = self.check_has_file(path, filename)
        return boolean

    '''
   扫描指定目录下的所有文件,找到所要找的文件,return True or False
     '''

    def check_has_file(self, path, filename):
        try:
            for filep, dirs, filelist in os.walk(path):
                for fl in filelist:
                    if cmp(fl, filename) == 0:  #这个字符串的比较存在风险,python3不支持,待修改
                        self.__fileabspath = os.path.join(filep, fl)
                        self.__logger.info("查找的%s文件存在" % filename)
                        return True
            return False
        except Exception, e:
            self.__logger.error("check_has_file()方法出现异常", e)
Exemple #14
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))
Exemple #15
0
class GetAllPathController(object):
    def __init__(self):
        self.fkctl = FileChecKController()
        if self.fkctl.is_has_file("allpath.ini"):
            fp = self.fkctl.get_fileabspath()
        self.cfgctl = ConfigController(fp)
        self.log4py = LoggingController()
        self.pro_path = self.fkctl.get_project_path()

    def get_dumpxml_path(self):
        self.log4py.info("executive -get_dumpxml_path- function ")
        path = os.path.join(self.pro_path,self.cfgctl.get("dumpxmlPath", "dumpxmlPath"))
        if PATH(path):
            self.log4py.info("获取 %s"%path)
            return path
        return None

    def get_htmlreport_path(self):
        self.log4py.info("executive -get_htmlreport_path- function ")
        path = os.path.join(self.pro_path, self.cfgctl.get("htmlreportPath", "htmlreportPath"))
        if PATH(path):
            self.log4py.info("获取 %s" % path)
            return path
        return None

    def get_logs_path(self):
        self.log4py.info("executive -get_logs_path- function ")
        path = os.path.join(self.pro_path, self.cfgctl.get("logsPath", "logsPath"))
        if PATH(path):
            if not os.path.exists(path):
                os.makedirs(path)
            self.log4py.info("获取 %s" % path)
            return path
        return None

    def get_capture_path(self):
        self.log4py.info("executive -get_logs_path- function ")
        path = os.path.join(self.pro_path, self.cfgctl.get("capturePath", "capturePath"))
        if PATH(path):
            self.log4py.info("获取 %s" % path)
            return path
        return None

    def get_appium_logs_path(self):
        self.log4py.info("executive -get_logs_path- function ")
        path = os.path.join(self.pro_path, self.cfgctl.get("appiumlogPath", "appiumlogPath"))
        if PATH(path):
            if not os.path.exists(path):
                os.makedirs(path)
            self.log4py.info("获取 %s" % path)
            return path
        return None

# if __name__ == "__main__":
#     gp = GetAllPathController()
#     print gp.get_dumpxml_path()
#     print gp.get_capture_path()
#     print gp.get_htmlreport_path()
#     print gp.get_logs_path()
 def __init__(self):
     self.android = AdbCmder()
     self.log4py = LoggingController()
 def __init__(self):
     self.__fileabspath = None  #不可访问的
     self.__logger = LoggingController()
 def __init__(self):
     self.json_obj = None
     self.fc = FileChecKController()
     if self.fc.is_has_file("android_devices_info.json"):
         self.json_file_path = self.fc.get_fileabspath()
     self.log4py = LoggingController()
Exemple #19
0
 def __init__(self):
     self.log4py = LoggingController()
Exemple #20
0
 def __init__(self):
     self.log4py = LoggingController()
     path_obj = GetAllPathController()
     self.appium_log_path = path_obj.get_appium_logs_path()