1. # -*- coding: utf-8 -*-
2. # @Time : 2021/5/1
3. # @Author : 大海
4. from time import sleep
5. from appium import webdriver
6.
7. desired_capabilities = {
8. "platformName": "Android", # 测试的平台 Android/iOS
9. "deviceName": "127.0.0.1:62001", # adb devices 查看,这里使用的是夜神模拟器
10. "platformVersion": "7.1.2",
11. "appPackage": "com.jingdong.app.mall", # 京东app
12. "appActivity": ".main.MainActivity"
13.
14. }
15.
16. driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_capabilities=desired_capabilities)
17. driver.implicitly_wait(10)
18. # 获取屏幕的size
19. size = driver.get_window_size()
20. print(size)
21. # 屏幕宽度width
22. print(size['width'])
23. # 屏幕高度width
24. print(size['height'])
25.
26. # 点击同意
27. driver.find_element_by_id('com.jingdong.app.mall:id/bqd').click()
28.
29.
30. def swipe_up(driver, t=500, n=1):
31. """向上滑动屏幕"""
32. print("向上滑动屏幕")
33. s = driver.get_window_size()
34. x1 = s['width'] * 0.5 # x坐标
35. y1 = s['height'] * 0.75 # 起始y坐标
36. y2 = s['height'] * 0.25 # 终点y坐标
37. for i in range(n):
38. driver.swipe(x1, y1, x1, y2, t)
39.
40.
41. def swipe_down(driver, t=500, n=1):
42. """向下滑动屏幕"""
43. print("向下滑动屏幕")
44. s = driver.get_window_size()
45. x1 = s['width'] * 0.5 # x坐标
46. y1 = s['height'] * 0.25 # 起始y坐标
47. y2 = s['height'] * 0.75 # 终点y坐标
48. for i in range(n):
49. driver.swipe(x1, y1, x1, y2, t)
50.
51.
52. def swipe_left(driver, t=500, n=1):
53. """向左滑动屏幕"""
54. print("向左滑动屏幕")
55. s = driver.get_window_size()
56. x1 = s['width'] * 0.75
57. y1 = s['height'] * 0.5
58. x2 = s['width'] * 0.25
59. for i in range(n):
60. driver.swipe(x1, y1, x2, y1, t)
61.
62.
63. def swipe_right(driver, t=500, n=1):
64. """向右滑动屏幕"""
65. print("向右滑动屏幕")
66. s = driver.get_window_size()
67. x1 = s['width'] * 0.25
68. y1 = s['height'] * 0.5
69. x2 = s['width'] * 0.75
70. for i in range(n):
71. driver.swipe(x1, y1, x2, y1, t)
72.
73.
74. if __name__ == '__main__':
75. sleep(5)
76. swipe_up(driver)
77. swipe_down(driver)