Beispiel #1
0
def _current_resmgr_session():
    tc = context.current_testcase()
    if tc is None:
        logger.warn("注意!非用例模式,将返回默认测试文件资源管理器,此处调用可能在测试环境下异常")
        return TestResourceManager(
            LocalResourceManagerBackend()).create_session()
    return tc.test_resources
Beispiel #2
0
 def __init__(self, device=None):
     if not device:
         from testbase import context
         tc = context.current_testcase()
         if tc:
             device = tc.acquire_device()
         else:
             # 使用本地设备
             device = Device()
     super(QT4ABrowser, self).__init__(self.process_name, device)
Beispiel #3
0
 def log_record(self, level, msg, record=None, attachments=None):
     '''处理一个日志记录
     
     :param level: 日志级别,参考EnumLogLevel
     :type level: string
     :param msg: 日志消息
     :type msg: string
     :param record: 日志记录
     :type record: dict
     :param attachments: 附件
     :type attachments: dict
     '''
     if record is None:
         record = {}
     if attachments is None:
         attachments = {}
     if isinstance(msg, unicode):
         msg = msg.encode('utf8')
     with self.__lock:
         if not self.__accept_result:
             return
         if level >= EnumLogLevel.ERROR:
             self.__steps_passed[self.__curr_step] = False
             if level > self.__error_level:
                 self.__error_level = level
             if level == EnumLogLevel.TESTTIMEOUT:
                 extra_record, extra_attachments = self._get_extra_fail_record_safe(
                 )  #超时时调用这个可能会卡死,所以要这样处理
                 record.update(extra_record)
                 attachments.update(extra_attachments)
             else:
                 try:
                     extra_record, extra_attachments = context.current_testcase(
                     ).get_extra_fail_record()
                     record.update(extra_record)
                     attachments.update(extra_attachments)
                 except:
                     self.handle_log_record(
                         EnumLogLevel.ERROR, '测试失败时获取测试用例上下文失败',
                         {'traceback': traceback.format_exc()}, {})
         self.handle_log_record(level, msg, record, attachments)
Beispiel #4
0
 def log_record(self, level, msg, record=None, attachments=None ):
     '''处理一个日志记录
     
     :param level: 日志级别,参考EnumLogLevel
     :type level: string
     :param msg: 日志消息
     :type msg: string
     :param record: 日志记录
     :type record: dict
     :param attachments: 附件
     :type attachments: dict
     '''
     if record is None:
         record = {}
     if attachments is None:
         attachments = {}
     if isinstance(msg, unicode):
         msg = msg.encode('utf8')
     with self.__lock:
         if not self.__accept_result:
             return
         if level >= EnumLogLevel.ERROR:
             self.__steps_passed[self.__curr_step] = False
             if level > self.__error_level:
                 self.__error_level = level
             if level == EnumLogLevel.TESTTIMEOUT:
                 extra_record, extra_attachments = self._get_extra_fail_record_safe() #超时时调用这个可能会卡死,所以要这样处理
                 record.update(extra_record)
                 attachments.update(extra_attachments)    
             else:
                 try:
                     extra_record, extra_attachments = context.current_testcase().get_extra_fail_record()
                     record.update(extra_record)
                     attachments.update(extra_attachments)
                 except:
                     self.handle_log_record(EnumLogLevel.ERROR, '测试失败时获取测试用例上下文失败', 
                                       {'traceback':traceback.format_exc()}, {})
         self.handle_log_record(level, msg, record, attachments)
Beispiel #5
0
 def runTest(self):
     self.logInfo(str(context.current_testcase().casedata))
     self.logInfo(str(self.casedata))
Beispiel #6
0
 def _run(outputs, errors):
     try:
         outputs.append(
             context.current_testcase().get_extra_fail_record())
     except:
         errors.append(traceback.format_exc())
Beispiel #7
0
    def __init__(self, attrs={}, devicemanager=None):
        '''Device构造函数

        :param attrs: 设备UDID字符串|设备属性字典
                                    keys: udid            - 设备UDID
                                          host            - 设备主机ip
                                          is_simulator    - 是否为模拟器
        :type attrs: str|dict
        :param devicemanager: 设备管理类
        :type devicemanager: DeviceManager
        '''
        cond = {}
        if isinstance(attrs, six.string_types):
            cond['udid'] = attrs
        elif isinstance(attrs, dict):
            cond = attrs.copy()
        else:
            raise Exception('Device attributes type error: %s' % type(attrs))
        ct = None
        if devicemanager:
            self._device_resource = devicemanager.acquire_device(cond)
        else:
            ct = context.current_testcase()
            if ct is None:
                self._test_resources = TestResourceManager(
                    LocalResourceManagerBackend()).create_session()
            else:
                self._test_resources = ct.test_resources
            self._device_resource = self._test_resources.acquire_resource(
                "ios", condition=cond)

        if self._device_resource is None:
            raise Exception('无可用的真机和模拟器: %s' % str(cond))

        props = self._device_resource
        if 'properties' in self._device_resource:  # online mode
            devprops = self._device_resource['properties']
            props = {
                p['name'].encode(Encoding): p['value'].encode(Encoding)
                for p in devprops
            }
            props['id'] = self._device_resource['id']

        if 'csst_uri' not in props or props['csst_uri'] == 'None':
            props['csst_uri'] = None

        self._device_resource = DeviceResource(props['host'], int(
            props['port']), props['udid'], props['is_simulator'],
                                               props['name'], props['version'],
                                               props['csst_uri'], props['id'])

        self._base_url = self._device_resource.driver_url
        self._ws_uri = self._device_resource.ws_uri
        self._host = RPCClientProxy('/'.join([self._base_url, 'host/']),
                                    self._ws_uri,
                                    allow_none=True,
                                    encoding=Encoding)
        self._device_udid = self._device_resource.udid
        self._device_name = self._device_resource.name
        self._device_ios = self._device_resource.version
        if isinstance(self._device_resource.is_simulator, bool):
            self._device_simulator = self._device_resource.is_simulator
        else:
            self._device_simulator = self._device_resource.is_simulator == str(
                True)

        if self._device_simulator:
            self._host.start_simulator(self._device_udid)
        self._app_started = False
        Device.Devices.append(self)
        url = '/'.join([self._base_url, 'device', '%s/' % self._device_udid])
        self._driver = RPCClientProxy(url,
                                      self._ws_uri,
                                      allow_none=True,
                                      encoding=Encoding)
        self._keyboard = Keyboard(self)
        logger.info('[%s] Device - Connect - %s - %s (%s)' %
                    (datetime.datetime.fromtimestamp(
                        time.time()), self.name, self.udid, self.ios_version))
        # 申请设备成功后,对弹窗进行处理
        rule = settings.get('QT4I_ALERT_DISMISS', DEFAULT_ALERT_RULE)
        if rule:
            try:
                self._dismiss_alert(rule)
            except:
                logger.exception('dismiss alert %s' % rule)
Beispiel #8
0
 def _run(outputs, errors):
     try:
         outputs.append(context.current_testcase().get_extra_fail_record())
     except:
         errors.append(traceback.format_exc())