Beispiel #1
0
 def get_top_app(self):
     if self.__wda_connector is None:
         logger.error(
             "wda connector is not inited... plsease make sure wda is connectable"
         )
         return None
     return self.__wda_connector.get_top_bundleid()
Beispiel #2
0
    def joystick_move(self, param):
        '''
        swipe joystick

        :param dict
        :param distance: the distance for joystick swipe
        :param stickname: jotstick_name
        :param duration: hold name
        :param velocity: swip speed
        :param style: value=left,right,up,down
        :return:
        '''

        if not self.device or not self.device.engine_connector():
            return None
        engine = self.device.engine_connector()
        element = engine.find_element(param['stickname'])
        if element is None:
            logger.error("long press element is none in long_press_engine_element_by_name")
            return None
        ret=engine.get_element_bound(element)
        if not ret:
            return False
        targetpos=self.computetarget(ret)
        switch={'left': lambda x:[x[0]-param['distance'],x[1]],
                'right': lambda x:[x[0]+param['distance'],x[1]],
                'up': lambda x:[x[0],x[1]-param['distance']],
                'down': lambda x:[x[0],x[1]+param['distance']]
                }

        topos = switch.get(param['style'], lambda: False)(targetpos)
        self.device.drag_hold(targetpos[0], targetpos[1], topos[0], topos[1], 1,param['duration'], param['velocity'])
        return
Beispiel #3
0
 def init_engine_sdk(self,
                     engine_type,
                     local_engine_port="53001",
                     timeout=60):
     local_engine_port = os.environ.get("LOCAL_ENGINE_PORT",
                                        local_engine_port)
     if local_engine_port is None:
         local_engine_port = "53001"
     if isInCloudMode():
         response = platform_helper.get_platform_client().platform_forward(
             self.__device_sdk_port)
         if response is None:
             return ERR_CLOUD_PLATFORM
         else:
             local_engine_port = response["localPort"]
     else:
         self.__forward(local_engine_port, self.__device_sdk_port)
     counts = int(timeout / 2 + 1)
     for i in range(counts):
         try:
             self.__engine_connector = EngineFactory.createEngine(
                 engine_type, os.environ.get("PLATFORM_IP", "127.0.0.1"),
                 int(local_engine_port))
             if self.__engine_connector is None:
                 logger.error("create engine failed . invalid type : " +
                              str(engine_type))
                 return ERR_INVALID_ENGINETYPE
             version = self.__engine_connector.get_sdk_version()
             if version:
                 logger.debug(version)
                 return ERR_SUCCEED
         except Exception as e:
             time.sleep(2)
     logger.error("init engine sdk timeout")
     return ERR_CONNECT_TO_SDK_FAILED
 def wait_element(self, method, param, timeout):
     method_map = {
         By.NAME_IN_ENGINE: getattr(self, "wait_engine_element_by_name")
     }
     if method not in method_map:
         logger.error("invalid find method :" + method)
         return None
     return method_map.get(method)(param, timeout)
 def touch_element(self, method, param):
     method_map = {
         By.NAME_IN_ENGINE: getattr(self, "touch_engine_element_by_name")
     }
     if method not in method_map:
         logger.error("invalid touch method :" + method)
         return None
     return method_map.get(method)(param)
Beispiel #6
0
    def screen_shot(self, method, param):
        '''

        '''
        method_map = {By.NAME_IN_ENGINE: getattr(self, "screen_engine_shot")}
        if method not in method_map:
            logger.error("invalid screenshot method :" + method)
            return None
        return method_map.get(method)(param)
Beispiel #7
0
 def start_alert_handler(self, handler=None):
     if self.__wda_connector is None:
         logger.error("wda connector is not inited... plsease make sure wda is connectable")
         return ERR_WDA_NOT_RUNNING
     if handler is None:
         handler = self.__default_alert_callback
     logger.info("setting alert handler...")
     self.__wda_connector.get_session().set_alert_callback(handler)
     return ERR_SUCCEED
Beispiel #8
0
    def get_element_engine_text_by_name(self, name):
        if not self.device or not self.device.engine_connector():
            return None
        engine = self.device.engine_connector()
        element = engine.find_element(name)

        if element is None:
            logger.error("touch element is none in touch_engine_elem")
            return None
        res = engine.get_element_text(element)

        return res
Beispiel #9
0
 def swipe_hold_screen(self, method, param):
     '''
         Written by davidzkpu
     :param method: method name
     :param param:  dict
     :return:
     '''
     method_map = {By.NAME_IN_ENGINE: getattr(self, "swipe_hold")}
     if method not in method_map:
         logger.error("invalid hold method :" + method)
         return None
     return method_map.get(method)(param)
Beispiel #10
0
    def touch_engine_element_by_name(self, name):
        if not self.device or not self.device.engine_connector():
            return None
        engine = self.device.engine_connector()
        element = engine.find_element(name)
        if element is None:
            logger.error("touch element is none in touch_engine_elem")
            return None
        bound = engine.get_element_bound(element)
        targetPos=self.computetarget(bound)
        self.device.touch(targetPos[0],targetPos[1])

        return element
Beispiel #11
0
 def login_tencent(self, account, password):
     if self.device is None:
         logger.error("login_tencent: device is none...")
         return ga2.ERR_LOGIN_FAILED
     top_app = self.device.get_top_app()
     logger.info("top bundle id: " + self.device.get_top_app())
     if top_app == TencentLoginHelper.QQ_BUNDLE_ID:
         return self.login_qq(account=account, password=password)
     elif top_app == TencentLoginHelper.WECHAT_BUNDLE_ID:
         return self.login_wechat(account=account, password=password)
     else:  #sometimes there are alerts, try to login both qq and wechat
         if self.login_qq(account=account,
                          password=password) == ga2.ERR_LOGIN_FAILED:
             return self.login_wechat(account=account, password=password)
         return ga2.ERR_SUCCEED
Beispiel #12
0
 def long_press_engine_element_by_name(self, name, duration=2):
     if not self.device or not self.device.engine_connector():
         return None
     engine = self.device.engine_connector()
     element = engine.find_element(name)
     if element is None:
         logger.error("long press element is none in long_press_engine_element_by_name")
         return None
     bound = engine.get_element_bound(element)
     targetPos = (bound.x + bound.width / 2, bound.y + bound.height / 2)
     if isInCloudMode():
         (width, height) = self.device.display_size()
         Reporter().screenshot_with_mark(width, height, targetPos[0], targetPos[1])
     self.device.long_press(targetPos[0], targetPos[1], duration)
     return element
Beispiel #13
0
 def launch(self, appid, timeout=60, alert_handler=None):
     if self.__wda_connector is None:
         logger.error("wda connector is not inited... plsease make sure wda is connectable")
         return ERR_WDA_NOT_RUNNING
     session = self.__wda_connector.new_session(bundleid=appid)
     if alert_handler is None:
         alert_handler = self.__default_alert_callback
     for i in range(0, 10):
         time.sleep(3)
         cur_top_app = self.get_top_app()
         logger.info("current top app is :" + cur_top_app + "target is: " + appid)
         if cur_top_app != appid:
             alert_handler(session)
         else:
             break
     return ERR_SUCCEED
Beispiel #14
0
 def multifingers_swip(self, method, param):
     method_map = {By.NAME_IN_ENGINE: getattr(self, "multi_fingers_control")}
     if method not in method_map:
         logger.error("invalid screenshot method :" + method)
         return None
     return method_map.get(method)(param)
Beispiel #15
0
 def wda_session(self):
     if self.__wda_connector == None:
         logger.error(
             "wda connector is not inited... plsease make sure wda is connectable"
         )
     return self.__wda_connector.get_session()
Beispiel #16
0
 def long_press_element(self, method, param, duration=2):
     method_map = {By.NAME_IN_ENGINE: getattr(self, "long_press_engine_element_by_name")}
     if method not in method_map:
         logger.error("invalid long press method :" + method)
         return None
     return method_map.get(method)(param, duration)
Beispiel #17
0
 def move_joystick(self, method, param):
     method_map = {By.NAME_IN_ENGINE: getattr(self, "joystick_move")}
     if method not in method_map:
         logger.error("invalid move method :" + method)
         return None
     return method_map.get(method)(param)
Beispiel #18
0
 def get_dumptree(self, method, timeout):
     method_map = {By.NAME_IN_ENGINE: getattr(self, "wait_engine_dump_tree")}
     if method not in method_map:
         logger.error("invalid find method :" + method)
         return None
     return method_map.get(method)(timeout)
Beispiel #19
0
 def get_version(self, method,timeout):
     method_map = {By.NAME_IN_ENGINE: getattr(self, "get_engine_version")}
     if method not in method_map:
         logger.error("invalid find method :" + method)
         return None
     return method_map.get(method)(timeout)
Beispiel #20
0
 def tencent_login(self, method):
     method_map = {By.NAME_IN_ENGINE: getattr(self, "wait_engine_tencent_login")}
     if method not in method_map:
         logger.error("invalid loging method :" + method)
         return None
     return method_map.get(method)()