Ejemplo n.º 1
0
    def get_all_appium_server_port(self):

        port_list = []
        if os.path.exists(self.f_path):
            ap = ConfigReader(self.f_path)
            section_list = ap.get_sections()
            for sl in section_list:
                port_list.append(ap.get_value(sl, sl))
                port_list.append(ap.get_value(sl, "bp"))
        return port_list
Ejemplo n.º 2
0
class MobileConfigGetter(object):
    def __init__(self):
        self.__fileabspath = None
        self.__projectpath = None
        self.log4py = LoggingPorter()
        fc = FileInspector()
        boolean = fc.is_has_file("owl-appium.ini")
        if boolean: 
            self.__fileabspath = fc.get_file_abspath()
            self.__projectpath = fc.get_project_path()
        self.cf = ConfigReader(self.__fileabspath)

    @property
    def properties(self):
        """
        获取配置文件中的内容并返回对应的对象
        :return:
        """
        ap = AppiumIniDomain()
        try:
            ap.pageLoadTimeout = self.cf.get_value("TimeSet", "pageLoadTimeout")
            ap.waitTimeout = self.cf.get_value("TimeSet", "waitTimeout")
            ap.scriptTimeout = self.cf.get_value("TimeSet", "scriptTimeout")
            ap.pauseTime = self.cf.get_value("TimeSet", "pauseTime")

            ap.capturePath = os.path.join(self.__projectpath, self.cf.get_value("ResultPath", "capturePath"))
            if not os.path.exists(ap.capturePath):
                os.makedirs(ap.capturePath)
            ap.htmlreportPath = os.path.join(self.__projectpath, self.cf.get_value("ResultPath", "htmlreportPath"))
            if not os.path.exists(ap.htmlreportPath):
                os.makedirs(ap.htmlreportPath)
            ap.dumpxmlPath = os.path.join(self.__projectpath, self.cf.get_value("ResultPath", "dumpxmlPath"))
            if not os.path.exists(ap.dumpxmlPath):
                os.makedirs(ap.dumpxmlPath)
            ap.appiumlogPath = os.path.join(self.__projectpath, self.cf.get_value("ResultPath", "appiumlogPath"))
            if not os.path.exists(ap.appiumlogPath):
                os.makedirs(ap.appiumlogPath)
            ap.permissionPath = os.path.join(self.__projectpath, self.cf.get_value("ResultPath", "permissionPath"))
            if not os.path.exists(ap.permissionPath):
                os.makedirs(ap.permissionPath)
            ap.appiumService = os.path.join(self.__projectpath, self.cf.get_value("ResultPath", "appiumService"))

        except Exception, e:
            self.log4py.error("实例化appium配置文件对象时,出现异常 :" + str(e))
        return ap
Ejemplo n.º 3
0
 def __get_appium_port(self, sno):
     """
     这里读取启动服务时生成的那个ini配置文件,读取其中sno对应的状态及服务的port
     :param sno:
     :return:
     """
     ff = ConfigReader(self.run_cfg.properties.appiumService)
     try:
         port = ff.get_value(sno, sno)
         if port:
             self.log4py.info("获取到{}设备对应的appium服务端口{}".format(sno, port))
         return port
     except Exception as e:
         self.log4py.debug("{}设备对应的appium未启动".format(sno))
         return None
Ejemplo n.º 4
0
 def __init__(self):
     self.fc = FileInspector()
     bools = self.fc.is_has_file("owl-framework.ini")
     if bools:
         fp = self.fc.get_file_abspath()
         conf = ConfigReader(fp)
         self.smtp_host = conf.get_value("email", "smtp_host")
         self.pop3_host = conf.get_value("email", "pop3_host")
         self.receiver = conf.get_value("email", "receiver").split(",")
         self.receiver_pa = conf.get_value("email", "receiver_pa")
         self.sender = conf.get_value("email", "sender")
         self.sender_pa = conf.get_value("email", "sender_pa")
         self.report_path = os.path.join(
             self.fc.get_project_path(),
             conf.get_value("ResultPath", "htmlreportPath"))
     self.log4py = LoggingPorter()
Ejemplo n.º 5
0
def html_reporter():
    logger = LoggingPorter()
    fc = FileInspector()
    pro_path = fc.get_project_path()
    boolean = fc.is_has_file("owl-framework.ini")
    if boolean:
        inipath = fc.get_file_abspath()
        cf = ConfigReader(inipath)
    htmlrp_path = cf.get_value("ResultPath", "htmlreportPath")
    htmreportl_abs_path = os.path.join(pro_path, htmlrp_path)
    timecurrent = formated_time("%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))
Ejemplo n.º 6
0
class WebConfingGetter(object):
    def __init__(self):
        self.__fileabspath = None
        self.__projectpath = None
        self.log4py = LoggingPorter()
        fc = FileInspector()
        boolean = fc.is_has_file("owl-selenium.ini")
        if boolean:
            self.__fileabspath = fc.get_file_abspath()
            self.__projectpath = fc.get_project_path()
        self.conf = ConfigReader(self.__fileabspath)

    @property
    def properties(self):
        """
        获取配置文件中的内容并返回对应的对象
        :return:
        """
        wp = SeIniDomain()
        try:
            wp.pageLoadTimeout = self.conf.get_value("TimeSet",
                                                     "pageLoadTimeout")
            wp.waitTimeout = self.conf.get_value("TimeSet", "waitTimeout")
            wp.scriptTimeout = self.conf.get_value("TimeSet", "scriptTimeout")
            wp.pauseTime = self.conf.get_value("TimeSet", "pauseTime")

            wp.capturePath = os.path.join(
                self.__projectpath,
                self.conf.get_value("ResultPath", "capturePath"))
            if not os.path.exists(wp.capturePath):
                os.makedirs(wp.capturePath)
            wp.htmlreportPath = os.path.join(
                self.__projectpath,
                self.conf.get_value("ResultPath", "htmlreportPath"))
            if not os.path.exists(wp.htmlreportPath):
                os.makedirs(wp.htmlreportPath)
            wp.logsPath = os.path.join(
                self.__projectpath,
                self.conf.get_value("ResultPath", "logsPath"))
            if not os.path.exists(wp.logsPath):
                os.makedirs(wp.logsPath)
            wp.baseURL = self.conf.get_value("baseURL", "baseURL")
            wp.browser = self.conf.get_value("run", "browser")
            wp.type = self.conf.get_value("run", "type")
            wp.browserdriver = os.path.join(
                self.__projectpath, self.conf.get_value("driver", wp.browser))

            if wp.type == "0":
                d = {}
                d['url'] = self.conf.get_value('remoteProfile', 'url')
                d['browserName'] = self.conf.get_value('remoteProfile',
                                                       'browserName')
                d['version'] = self.conf.get_value('remoteProfile', 'version')
                d['maxinstance'] = self.conf.get_value('remoteProfile',
                                                       'maxinstance')
                d['platform'] = self.conf.get_value('remoteProfile',
                                                    'platform')
                wp.remoteProfile = d
        except Exception, e:
            self.log4py.error("实例化selenium配置文件对象时,出现异常 :" + str(e))
        return wp
Ejemplo n.º 7
0
class CreateConfigFile(object):
    def __init__(self):
        self.fkctl = FileInspector()

        if self.fkctl.is_has_file("owl-appium.ini"):
            fp = self.fkctl.get_file_abspath()
            self.cfg = ConfigReader(fp)
        self.log4py = LoggingPorter()
        self.log4py.info("-----配置文件操作开始-----")
        self.f_path = os.path.join(
            self.fkctl.get_project_path(),
            self.cfg.get_value("ResultPath", "appiumService"))

    def __del__(self):
        self.log4py.info("-----配置文件操作结束-----")

    def set_appium_uuids_ports(self, device_list, port_list):
        """
        遍历list,按照下表进行对应映射
        :param device_lsit: 手机uuid
        :param port_list: pc启动的appium服务端口
        """
        bol = self.create_config_file(self.f_path)
        if bol:
            self.log4py.info("创建appiumService.ini文件成功:{}".format(self.f_path))
            ap = ConfigReader(self.f_path)
            if len(device_list) > 0 and len(port_list) > 0:
                for i in range(len(device_list)):
                    filed = device_list[i]
                    key = filed
                    value = port_list[i]
                    # 因为是覆盖写入,没有section,需要先添加再设置, 初始化的服务都加一个run的标识
                    ap.add_section_key_value(filed, key, value)
                    ap.set_value(filed, "run", "0")
                ap.flush()
                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服务端口
        """
        bol = self.create_config_file(self.f_path)
        if bol:
            if device is not None and port is not None:
                ap = ConfigReader(self.f_path)
                sec = device
                key = device
                value = port
                if ap.had_section(sec):
                    ap.set_value(sec, key, value)
                    ap.set_value(sec, "bp", bp)
                    ap.set_value(sec, "run", "0")
                else:
                    ap.add_section_key_value(sec, key, value)
                    ap.set_value(sec, "bp", bp)
                    ap.set_value(sec, "run", "0")
                ap.flush()
                self.log4py.debug(
                    "设备sno与appium服务端口映射已写入appiumService.ini配置文件:{}--{}".format(
                        key, value))

    def create_config_file(self, path):
        """
        如果path这个文件不存在,就创建这个文件;存在就清空文件
        :param path: 是一个文件的绝对路径
        :return: 
        """
        if os.path.exists(path) and os.path.isfile(path):
            return True
        dir_name = os.path.dirname(path)
        if not os.path.exists(dir_name):
            os.makedirs(dir_name)
        f = open(path, "wb")
        f.close()
        if os.path.exists(path) and os.path.isfile(path):
            return True
        return False

    def get_all_appium_server_port(self):

        port_list = []
        if os.path.exists(self.f_path):
            ap = ConfigReader(self.f_path)
            section_list = ap.get_sections()
            for sl in section_list:
                port_list.append(ap.get_value(sl, sl))
                port_list.append(ap.get_value(sl, "bp"))
        return port_list

    def get_appium_logs_path(self):
        path = os.path.join(self.fkctl.get_project_path(),
                            self.cfg.get_value("ResultPath", "appiumlogPath"))
        if PATH(path):
            if not os.path.exists(path):
                os.makedirs(path)
            self.log4py.info("获取到appium服务的日志绝对路径 %s" % path)
            return path.replace("\\", "/")
        return None