1、獲取屏幕分辨率
????def get_screen_size(self):
? ? ? ? ?window_size=self.driver.get_window_size()
? ? ? ? ?x=window_size['width']
? ? ? ? ?y=window_size['height']
? ? ? ? ?return x,y? ? ? ? ? ? ? ? ? ? ? ? ? #因?yàn)橐玫竭@個(gè)值堪遂,所以要返回x、y的值
? ?x,y=get_screen_size()? ? ? ? ? ? ? ? ? ? ? #輸出屏幕分辨率值
? ?print(x,y)
2本缠、單點(diǎn)滑動(dòng)操作
1.)上滑
? ? def swipe_up(self, t):
? ? ? ? screen_size = self.get_screen_size()
? ? ? ? x1 = screen_size['width'] * 0.5
? ? ? ? y1 = screen_size['height'] * 0.75
? ? ? ? y2 = screen_size['height'] * 0.25
? ? ? ? self.driver.swipe(x1, y1, x1, y2, t)
2.)下滑
? ? def swipe_down(self, t):
? ? ? ? screen_size = self.get_screen_size()
? ? ? ? x1 = screen_size['width'] * 0.5
? ? ? ? y1 = screen_size['height'] * 0.25
? ? ? ? y2 = screen_size['height'] * 0.75
? ? ? ? self.driver.swipe(x1, y1, x1, y2, t)
3.)左滑
? ? def swipe_left(self, t):
? ? ? ? screen_size = self.get_screen_size()
? ? ? ? x1 = screen_size['width'] * 0.75
? ? ? ? y1 = screen_size['height'] * 0.5
? ? ? ? x2 = screen_size['width'] * 0.25
? ? ? ? self.driver.swipe(x1, y1, x2, y1, t)
? 4.)右滑
? ? def swipe_right(self, t):
? ? ? ? screen_size = self.get_screen_size()
? ? ? ? x1 = screen_size['width'] * 0.25
? ? ? ? y1 = screen_size['height'] * 0.5
? ? ? ? x2 = screen_size['width'] * 0.75
? ? ? ? self.driver.swipe(x1, y1, x2, y1, t)
3、多點(diǎn)滑動(dòng)函數(shù)封裝
1.)放大
????def zoom(self):
????????x,y=get_screen_size()
????????action1=TouchAction(driver)? ? ? ? ? ??
? ? ????action2=TouchAction(driver)??
????????add_action=MultiAction(driver)? ? ? ? ??
? ? ????action1.press(x=0.6*x,y=0.6*y).move_to(x=0.1*x,y=0.1*y).wait(1000).release()
????????action2.press(x=0.4*x,y=0.4*y).move_to(x=0.2*x, y=0.2*y).wait(1000).release()
????????add_action.add(action1,action2)
????????print("執(zhí)行放大操作")
? ? ????add_action.perform()? ? ? ? ??
2.)縮小
????def shrink():
????????x,y=get_size()
????????action1=TouchAction(driver)
????????action2=TouchAction(driver)
????????add_action=MultiAction(driver)
????????action1.press(x=0.1*x,y=0.1*y).move_to(x=0.6*x,y=0.6*y).wait(1000).release()
????????action2.press(x=0.2*x,y=0.2*y).move_to(x=0.4*x,y=0.4*y).wait(1000).release()
????????add_action.add(action1,action2)
????????print("執(zhí)行縮小操作")
????????add_action.perform()