APP自动化测试总结二:滑动操作的封装

 1 class BasePage():
 2     def __init__(self, driver):
 3         self.driver = driver
 4 
 5     def swipe_left(self):
 6         """从右到左滑动"""
 7         size = self.driver.get_window_rect()
 8         width = size['width']
 9         height = size['height']
10         self.driver.swipe(start_x=width * 0.9, start_y=height * 0.5,
11                      end_x=width * 0.1, end_y=height * 0.5)
12 
13     def swipe_right(self):
14         """从左到右滑动"""
15         size = self.driver.get_window_rect()
16         width = size['width']
17         height = size['height']
18         self.driver.swipe(start_x=width * 0.1, start_y=height * 0.5,
19                      end_x=width * 0.9, end_y=height * 0.5)
20 
21     def swipe_up(self):
22         """从下到上"""
23         size = self.driver.get_window_rect()
24         width = size['width']
25         height = size['height']
26         self.driver.swipe(start_x=width * 0.5, start_y=height * 0.9,
27                      end_x=width * 0.5, end_y=height * 0.1)
28 
29     def swipe_down(self):
30         """从下到上"""
31         size = self.driver.get_window_rect()
32         width = size['width']
33         height = size['height']
34         self.driver.swipe(start_x=width * 0.5, start_y=height * 0.1,
35                      end_x=width * 0.5, end_y=height * 0.9)
36 
37 
38 caps = {
39     "platformName": "Android",
40     "appPackage": "com.xxzb.fenwoo",
41     "appActivity": ".activity.addition.WelcomeActivity",
42     # "app": ".apk"
43 }
44 
45 driver = Remote(desired_capabilities=caps,
46                 # command_executor='http://127.0.0.1:4723/wd/hub'
47                 )
48 driver.implicitly_wait(10)
49 
50 # 等待页面出现(ac = driver.current_activity  可提前获取current_activity后再使用)
51 driver.wait_activity('.activity.addition.WelcomeActivity', 8)
52 time.sleep(2)
53 
54 
55 # 进入到首页 #com.xxzb.fenwoo:id/btn_start
56 page = BasePage(driver)
57 for i in range(3):
58     page.swipe_left()
59 
60 driver.find_element('id', 'com.xxzb.fenwoo:id/btn_start').click()
61 
62 driver.tap()
63 
64 time.sleep(3)
65 driver.quit()

 

posted @ 2022-12-28 17:27  Chaman囍  阅读(49)  评论(0编辑  收藏  举报