def __action_goback(self, action): """ 行为执行:goback :param action: :return: """ DriverBase.adb_shell('shell input keyevent 4')
def __action_ifcheck(self, action): """ 行为执行:ifcheck :param action: :return: """ parms = action.parms if len(parms): img_info = self.__ocr_analysis(action.action, parms[0], True) if not isinstance(img_info, bool): if img_info is not None: Var.ocrimg = img_info['ocrimg'] check = True else: check = False elif len(parms) == 1: check = DriverBase.check(key=parms[0], timeout=Var.timeout, interval=Var.interval, index=0) elif len(parms) == 2: check = DriverBase.check(key=parms[0], timeout=Var.timeout, interval=Var.interval, index=parms[1]) else: raise TypeError( 'check takes 2 positional arguments but {} was given'. format(len(parms))) return check else: raise TypeError( 'click missing 1 required positional argument: element')
def __action_adb(self, action): """ 行为执行:adb :param action: :return: """ if len(action.parms) == 1: DriverBase.adb_shell(action.parms[0]) else: raise TypeError('adb missing 1 required positional argument')
def __action_tap(self, action): """ 行为执行:tap :param action: :return: """ if len(action.parms) == 2: DriverBase.tap(float(action.parms[0]), float(action.parms[-1])) else: raise TypeError('tap missing 2 required positional argument: x, y')
def __action_install_app(self, action): """ 行为执行:install_app :param action: :return: """ if len(action.parms) == 1: DriverBase.install_app(action.parms[0]) else: raise TypeError( 'installApp missing 1 required positional argument: app_path')
def __action_uninstall_app(self, action): """ 行为执行:uninstall_app :param action: :return: """ if len(action.parms) == 1: DriverBase.uninstall_app(action.parms[0]) else: raise TypeError( 'uninstallApp missing 1 required positional argument: package_info' )
def __init_config(self): self.__config = analytical_file( os.path.join(self.__ROOT, 'config.yaml')) for configK, configV in self.__config.items(): if configK == 'desiredcaps': Var.desired_caps = configV[0] for desiredcapsK, desiredcapsV in Var.desired_caps.items(): Var[desiredcapsK] = desiredcapsV else: Var[configK] = configV DriverBase.init()
def __action_start_app(self, action): """ 行为执行:start_app :param action: :return: """ parms = action.parms if len(parms) == 1: DriverBase.launch_app(parms[0]) else: raise TypeError( 'launchApp missing 1 required positional argument: package_info' )
def __action_press(self, action): """ 行为执行:press :param action: :return: """ if len(action.parms) == 2: DriverBase.press(float(action.parms[0]), float(action.parms[-1])) elif len(action.parms) == 3: DriverBase.press(float(action.parms[0]), float(action.parms[1]), float(action.parms[-1])) else: raise TypeError( 'press missing 2 required positional argument: x, y')
def __action_stop_app(self, action): """ 行为执行:stop_app :param action: :return: """ parms = action.parms if parms is None: DriverBase.close_app(Var.package) elif len(parms) == 1: DriverBase.close_app(parms[0]) else: raise TypeError( 'closeApp takes 1 positional argument but {} were giver'. format(len(parms)))
def __action_getText(self, action): """ 行为执行:getText :param action: :return: """ parms = action.parms if len(parms) == 1: text = DriverBase.get_text(key=parms[0], timeout=Var.timeout, interval=Var.interval, index=0) elif len(parms) == 2: text = DriverBase.get_text(key=parms[0], timeout=Var.timeout, interval=Var.interval, index=parms[-1]) else: raise TypeError( 'getText missing 1 required positional argument: element') return text
def __action_click(self, action): """ 行为执行:click :param action: :return: """ parms = action.parms if len(parms): img_info = self.__ocr_analysis(action.action, parms[0], True) if not isinstance(img_info, bool): Var.ocrimg = img_info['ocrimg'] x = img_info['x'] y = img_info['y'] DriverBase.tap(x, y) elif len(parms) == 1: DriverBase.click(key=parms[0], timeout=Var.timeout, interval=Var.interval, index=0) elif len(parms) == 2: DriverBase.click(key=parms[0], timeout=Var.timeout, interval=Var.interval, index=parms[1]) else: raise TypeError( 'click missing 1 required positional argument: element')
def __action_input(self, action): """ 行为执行:input :param action: :return: """ parms = action.parms if len(parms) == 2: DriverBase.input(key=parms[0], text=parms[1], timeout=Var.timeout, interval=Var.interval, index=0) elif len(parms) == 3: DriverBase.input(key=parms[0], text=parms[1], timeout=Var.timeout, interval=Var.interval, index=parms[2]) else: raise TypeError( 'input missing 2 required positional argument: element, text')
def __action_swipe(self, action): """ 行为执行:swipe :param action: :return: """ parms = action.parms if parms is None: raise TypeError( 'swipe missing 4 required positional argument: from_x, from_y, to_x, to_y' ) if parms[0] == 'up': DriverBase.swipe_up() elif parms[0] == 'down': DriverBase.swipe_down() elif parms[0] == 'left': DriverBase.swipe_left() elif parms[0] == 'right': DriverBase.swipe_right() elif len(parms) == 4: DriverBase.swipe(float(action.parms[0]), float(action.parms[1]), float(action.parms[2]), float(action.parms[3])) elif len(action.parms) == 5: DriverBase.swipe(float(action.parms[0]), float(action.parms[1]), float(action.parms[2]), float(action.parms[3]), int(action.parms[4])) else: raise TypeError( 'swipe takes 1 positional argument but {} were giver'.format( len(action.action)))
def setUp(self): if Var.restart and not self.skip: DriverBase.launch_app(None)
def tearDown(self): if Var.restart and not self.skip: DriverBase.close_app(None)