Appium 自动化图文教程
Appium 自动化(图文教程) 上海-悠悠
目录
第 1 章 环境搭建 ............................................................................................................................. 5
1.1 android-sdk 环境 ................................................................................................................ 5
1.1.1 环境准备 ................................................................................................................. 5
1.1.2 jdk 安装 .................................................................................................................... 6
1.1.3 android-sdk 下载安装 ............................................................................................. 8
1.1.4 android-sdk 环境变量 ............................................................................................. 9
1.1.5 adb 环境................................................................................................................. 10
1.1.6 连接手机 ............................................................................................................... 11
1.2 appium 环境 ..................................................................................................................... 18
1.2.1 必备软件安装 ....................................................................................................... 18
1.2.1 Python 安装 ........................................................................................................... 18
1.2.3 安装 node.js .......................................................................................................... 19
1.2.4 安装 appium ......................................................................................................... 20
1.2.5 安装.net framework .............................................................................................. 22
1.2.6 appium-doctor ....................................................................................................... 22
第 2 章 API 详解 ........................................................................................................................... 40
2.1 启动 app .......................................................................................................................... 40
2.1.1 下载 aapt .............................................................................................................. 41
2.1.2 获取 apk 包名 ....................................................................................................... 43
2.1.3 获取 launcherActivity ........................................................................................... 43
2.1.4 写脚本................................................................................................................... 44
2.1.5 运行 appium ......................................................................................................... 45
2.1.6 最终代码如下 ....................................................................................................... 47
2.2 元素定位 uiautomatorviewer ......................................................................................... 48
2.2.1 启动 uiautomatorviewer.bat................................................................................. 48
2.2.2 连接手机 ............................................................................................................... 50
2.2.3 定位元素 ............................................................................................................... 51
2.2.4 点搜索框 ............................................................................................................... 52
2.2.5 参考代码 ............................................................................................................... 52
2.2.6 元素定位 ............................................................................................................... 53
2.3 Appium Inspector .............................................................................................................. 54
2.3.1 设置 appium ......................................................................................................... 55
2.3.2 开启 appium ......................................................................................................... 56
2.3.3 Ispector Window .................................................................................................... 56
2.3.4 查看属性 ............................................................................................................... 57
2.5.5 常见异常 ............................................................................................................... 57
2.4 Remote 远程控制 ............................................................................................................. 58
2.4.1 设置 IP .................................................................................................................. 58
2.4.2 访问地址 ............................................................................................................... 59
2.4.3 配置测试机 ........................................................................................................... 60
2.4.4 远程操作 ............................................................................................................... 61
2.5 输入中文.......................................................................................................................... 62
2.5.1 定位搜索 ............................................................................................................... 62
Appium 自动化(图文教程) 上海-悠悠
2.5.2 运行脚本 ............................................................................................................... 62
2.5.3 屏蔽软键盘 ........................................................................................................... 63
2.5.4 输入中文字符 ....................................................................................................... 64
2.5.5 还原设置 ............................................................................................................... 66
2.5.6 最终脚本如下 ....................................................................................................... 66
2.6 Appium API..................................................................................................................... 67
1.contexts ................................................................................................................................ 68
2. current_context ................................................................................................................... 68
3. context ................................................................................................................................ 68
4. find_element_by_ios_uiautomation ................................................................................... 69
5. find_element_by_accessibility_id ....................................................................................... 69
6.scroll ..................................................................................................................................... 69
7. drag_and_drop .................................................................................................................... 70
8.tap ........................................................................................................................................ 70
9. swipe ................................................................................................................................... 71
10.flick ..................................................................................................................................... 71
11.pinch ................................................................................................................................... 72
12.zoom ................................................................................................................................... 72
13.reset ................................................................................................................................... 73
15. keyevent ............................................................................................................................ 74
16. press_keycode ................................................................................................................... 74
17. long_press_keycode .......................................................................................................... 74
19. wait_activity ...................................................................................................................... 75
20. background_app ............................................................................................................... 76
21.is_app_installed ................................................................................................................. 76
22.install_app .......................................................................................................................... 76
23.remove_app ....................................................................................................................... 77
24.launch_app ......................................................................................................................... 77
25.close_app ........................................................................................................................... 77
26. start_activity ..................................................................................................................... 78
27.lock ..................................................................................................................................... 79
29.open_notifications ............................................................................................................. 79
30.network_connection .......................................................................................................... 79
31. set_network_connection .................................................................................................. 80
32. available_ime_engines ...................................................................................................... 81
33.is_ime_active ..................................................................................................................... 81
34.activate_ime_engine .......................................................................................................... 81
35.deactivate_ime_engine ...................................................................................................... 82
36.active_ime_engine ............................................................................................................. 82
37. toggle_location_services ................................................................................................... 82
38.set_location ........................................................................................................................ 83
39.tag_name ........................................................................................................................... 83
40.text ..................................................................................................................................... 83
41.click .................................................................................................................................... 84
Appium 自动化(图文教程) 上海-悠悠
42.submit ................................................................................................................................ 84
43.clear .................................................................................................................................... 84
44.get_attribute ...................................................................................................................... 84
45.is_selected.......................................................................................................................... 86
46.is_enabled .......................................................................................................................... 86
47.find_element_by_id ........................................................................................................... 86
48. find_elements_by_id ........................................................................................................ 87
49. find_element_by_name .................................................................................................... 87
50. find_elements_by_name .................................................................................................. 87
51. find_element_by_link_text ............................................................................................... 88
52. find_elements_by_link_text ............................................................................................. 88
53. find_element_by_partial_link_text ................................................................................... 88
54. find_elements_by_partial_link_text ................................................................................. 89
55. find_element_by_tag_name ............................................................................................. 89
56. find_elements_by_tag_name ........................................................................................... 89
57. find_element_by_xpath .................................................................................................... 90
58. find_elements_by_xpath .................................................................................................. 90
59. find_element_by_class_name .......................................................................................... 91
60. find_elements_by_class_name ......................................................................................... 91
61. find_element_by_css_selector ......................................................................................... 92
62.send_keys ........................................................................................................................... 92
63. is_displayed ....................................................................................................................... 93
64. location_once_scrolled_into_view ................................................................................... 93
65.size...................................................................................................................................... 94
66. value_of_css_property ...................................................................................................... 94
67.location .............................................................................................................................. 94
68.rect ..................................................................................................................................... 95
69. screenshot_as_base64 ...................................................................................................... 95
70.execute_script .................................................................................................................... 95
71.execute_async_script ......................................................................................................... 96
72.current_url ......................................................................................................................... 96
73. page_source ...................................................................................................................... 96
74.close ................................................................................................................................... 97
75.quit ..................................................................................................................................... 97
评论