from poco.drivers.android.uiautomation import AndroidUiautomationPoco poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)
def lautch_app(self,package,activity=None): """ 启动app :param package: :param activity: :return: """ try: start_app(package) return True except Exception as e: print("启动失败:{}".format(e)) print("启动{}失败!!!".format(package)) return False
def get_myWindow_size(self): """ 获取设备的高度和宽度 :return: """ width, height = self.poco.get_screen_size() return width, height
def mobile_page_up_or_down_swip(self,start_x=0.5,start_y=0.6,end_y=0.9): ''' 页面上下滑动 :return: ''' size = self.get_myWindow_size() print("size[0]={0},size[1]={1}".format(size[0],size[1])) logger.info("size[0]={0},size[1]={1}".format(size[0],size[1])) x1 = size[0] * start_x # size[0]取元组的第一个值,*0.5表示中间的点 y1 = size[1] * start_y # size[1]取元组的第二个值,*0.1表示距离底部近 y2 = size[1] * end_y time.sleep(2) swipe((x1*start_x, y1*start_y),vector=(x1*start_x,y2*end_y))
def mobile_page_left_or_right_swip(self,start_x= 0.5,start_y= 3/4,end_x= 1/6): ''' 页面左右滑动 :return: ''' size = self.get_myWindow_size() print("size[0]={0},size[1]={1}".format(size[0],size[1])) x1 = int(size[0] * start_x) # size[0]取元组的第一个值,*0.5表示中间的点 y1 = int(size[1] * start_y) # size[1]取元组的第二个值,*0.1表示距离底部近 x2 = int(size[0] * end_x) time.sleep(2) swipe((x1 * start_x, y1 * start_y),(x2 * end_x, y1 * start_y))
def click_element(self,method,context): """ 点击元素 :param name: :return: """ if method == "name": self.poco(name=context).click() elif method == "text": self.poco(text=context).click()
def input_element(self,method,context,value): """ 输入 :param method: :param context: :return: """ if method == "name": self.poco(name=context).set_text(value) elif method == "text": self.poco(text=context).set_text(value)
def click_keyboard(self,name): """ 模拟键盘点击 :param name: :return: """ keyevent(name)
def find_element_by_method(self,method,context): """ 通过method判断元素是否存在 :return: """ if method == "name": return self.poco(name=context).exists() elif method == "text": return self.poco(text=context).exists() else: pass