74个API大全
API太多了,我以为一天就能做出来,谁成想地鸽了三天(捂脸)
希望能对大家有所帮助嗷!!!
书接上文【appium】appium自动化入门之API(中)
环境搭建篇【appium】appium自动化入门之环境搭建(上)
下文链接【appium】appium自动化入门之元素篇
目录
- Appium API
-
- 前言
- 1.contexts (返回当前会话中的上下文,使用后可以识别 H5 页面的控件)
- 2.current_context (返回当前会话的当前上下文 )
- 3. context (返回当前会话的当前上下文)
- 4.find_element_by_ios_uiautomation(通过 iOS uiautomation 查找元素)
- 5.find_element_by_accessibility_id(通过 accessibility id 查找元素 )
- 6.scroll (从元素 origin_el 滚动至元素 destination_el)
- 7.drag_and_drop(将元素 origin_el 拖到目标元素 destination_el )
- 8.tap (模拟手指点击(最多五个手指),可设置按住时间长度(毫秒))
- 9.swipe (从 A 点滑动至 B 点,滑动时间为毫秒 )
- 10.flick (按住 A 点后快速滑动至 B 点 )
- 11.pinch (在元素上执行模拟双指捏(缩小操作))
- 12.zoom (在元素上执行放大操作)
- 13.reset (重置应用(类似删除应用数据) )
- 14 hide_keyboard (隐藏键盘,iOS 使用 key_name 隐藏,安卓不使用参数 )
- 15 keyevent (发送按键码(安卓仅有),按键码可以上网址中找到)
- 16 press_keycode (发送按键码(安卓仅有),按键码可以上网址中找到 )
- 17.long_press_keycode(发送一个长按的按键码(长按某键))
- 18.current_activity (获取当前的 activity )
- 19.wait_activity(等待指定的 activity 出现直到超时,interval 为扫描间隔 1 秒 即每隔几秒获取一次当前的 activity )
- 20.background_app (后台运行 app 多少秒 )
- 21.is_app_installed (检查 app 是否有安装)
- 22.install_app (安装 app,app_path 为安装包路径)
- 23.remove_app (删除 app)
- 24.launch_app(启动 app )
- 25.close_app (需要注意的是启动和关闭 app 运行好像会出错 )
- 26.start_activity (在测试过程中打开任意活动。如果活动属于另一个应用程序,该应用程序的启动和活动被打开。这是一个安卓的方法 )
- 27.lock (锁屏一段时间 iOS 专有)
- 28.shake (摇一摇手机 )
- 29.open_notifications (打系统通知栏(仅支持 API 18 以上的安卓系统))
- 30.network_connection(#返回网络类型数值)
- 31.set_network_connection (设置网络类型)
- 32.available_ime_engines(返回安卓设备可用的输入法)
- 33.is_ime_active i(检查设备是否有输入法服务活动。返回真/假)
- 34.activate_ime_engine (激活安卓设备中的指定输入法,设备可用输入法可以从 “available_ime_engines”获取)
- 35.deactivate_ime_engine (关闭安卓设备当前的输入法 )
- 36.active_ime_engine (返回当前输入法的包名)
- 37.toggle_location_services (打开安卓设备上的位置定位设置)
- 38.set_location (设置设备的经纬度 )
- 39.tag_name(返回元素的 tagName 属性)
- 40.text(返回元素的文本值 )
- 41.click (点击元素)
- 42.submit (提交表单 )
- 43.clear (清除输入的内容)
- 44.get_attribute
- 45.is_selected (返回元素是否选择)
- 46.is_enabled (返回元素是否可用)
- 47.find_element_by_id(通过元素的 ID 定位元素)
- 48.find_elements_by_id(通过元素 ID 定位,含有该属性的所有元素)
- 49.find_element_by_name (通过元素 Name 定位)
- 50.find_elements_by_name
- 51.find_element_by_link_text (通过元素可见链接文本定位)
- 52.find_elements_by_link_text
- 53.find_element_by_partial_link_text (通过元素部分可见链接文本定位)
- 54.find_elements_by_partial_link_text
- 55.find_element_by_tag_name
- 56.find_elements_by_tag_name
- 57.find_element_by_xpath(通过 Xpath 定位元素)
- 58.find_elements_by_xpath
- 59.find_element_by_class_name (通过元素 class name 属性定位元素)
- 60.find_elements_by_class_name (通过元素 class name 属性定位所有含有该属性的元素)
- 61.find_element_by_css_selector (通过 CSS 选择器定位元素)
- 62.send_keys(在元素中模拟输入)
- 63.is_displayed(此元素用户是否可见)
- 64.size (获取元素的大小)
- 65.value_of_css_property (CSS 属性)
- 66.location (获取元素左上角的坐标)
- 67.rect(元素的大小和位置的字典)
- 68.screenshot_as_base64 (获取当前元素的截图为 Base64 编码的字符串 )
- 69.execute_script (同步执行 javascript 代码)
- 70.execute_async_script (插入 javascript 代码)
- 71.current_url(获取当前页面的网址 )
- 72.page_source (获取当前页面的源 )
- 73.close(关闭当前窗口)
- 74.quit (退出脚本运行并关闭每个相关的窗口连接)
- 重要的话
Appium API
前言
Appium Python API 全集,可以查看所有的帮助文档
1.contexts (返回当前会话中的上下文,使用后可以识别 H5 页面的控件)
contexts(self):
Returns the contexts within the current session.
#返回当前会话中的上下文,使用后可以识别 H5 页面的控件
:Usage:
driver.contexts
用法 driver.contexts
2.current_context (返回当前会话的当前上下文 )
current_context(self):
Returns the current context of the current session.
#返回当前会话的当前上下文
:Usage:
driver.current_context
用法 driver. current_context
3. context (返回当前会话的当前上下文)
context(self):
Returns the current context of the current session.
#返回当前会话的当前上下文。
:Usage:
driver.context
用法 driver. Context
4.find_element_by_ios_uiautomation(通过 iOS uiautomation 查找元素)
find_element_by_ios_uiautomation(self, uia_string):
Finds an element by uiautomation in iOS.
#通过 iOS uiautomation 查找元素
:Args:
-uia_string - The element name in the iOS UIAutomation library
:Usage:
driver.find_element_by_ios_uiautomation('.elements()[1 ].cells()[2]')
用法 dr. find_element_by_ios_uiautomation(‘elements’)
5.find_element_by_accessibility_id(通过 accessibility id 查找元素 )
find_element_by_accessibility_id(self, id):
Finds an element by accessibility id.
#通过 accessibility id 查找元素
:Args:
-d - a string corresponding to a recursive element search using the
-Id/Name that the native Accessibility options utilize
:Usage:
driver.find_element_by_accessibility_id()
用法 driver.find_element_by_accessibility_id(‘id’)
6.scroll (从元素 origin_el 滚动至元素 destination_el)
scroll(self, origin_el, destination_el):
Scrolls from one element to another
#从元素 origin_el 滚动至元素 destination_el
:Args:
-originalEl - the element from which to being scrolling - destinationEl
-the element to scroll to
:Usage:
driver.scroll(el1, el2)
用法 driver.scroll(el1,el2)
7.drag_and_drop(将元素 origin_el 拖到目标元素 destination_el )
drag_and_drop(self, origin_el, destination_el):
Drag the origin element to the destination element
#将元素 origin_el 拖到目标元素 destination_el
:Args:
-originEl - the element to drag
-destinationEl - the element to drag to
用法 driver.drag_and_drop(el1,el2)
8.tap (模拟手指点击(最多五个手指),可设置按住时间长度(毫秒))
tap(self, positions, duration=None):
Taps on an particular place with up to five fingers, holding for a certain time
#模拟手指点击(最多五个手指),可设置按住时间长度(毫秒)
:Args: - positions
- an array of tuples representing the x/y coordinates of
the fingers to tap. Length can be up to five.
- duration - (optional) length of time to tap, in ms :Usage:
driver.tap([(100, 20), (100, 60), (100, 100)], 500)
用法 driver.tap([(x,y),(x1,y1)],500)
9.swipe (从 A 点滑动至 B 点,滑动时间为毫秒 )
swipe(self, start_x, start_y, end_x, end_y, duration=None):
Swipe from one point to another point, for an optional duration.
#从 A 点滑动至 B 点,滑动时间为毫秒
:Args:
- start_x - x-coordinate at which to start
- start_y - y-coordinate at which to start
- end_x - x-coordinate at which to stop
- end_y - y-coordinate at which to stop
- duration - (optional) time to take the swipe, in ms. :Usage: driver.swipe(100, 100, 100, 400)
用法 driver.swipe(x1,y1,x2,y2,500)
10.flick (按住 A 点后快速滑动至 B 点 )
flick(self, start_x, start_y, end_x, end_y):
Flick from one point to another point.
#按住 A 点后快速滑动至 B 点
:Args:
- start_x - x-coordinate at which to start
- start_y - y-coordinate at which to start
- end_x - x-coordinate at which to stop
- end_y - y-coordinate at which to stop
:Usage:
driver.flick(100, 100, 100, 400)
用法 driver.flick(x1,y1,x2,y2)
11.pinch (在元素上执行模拟双指捏(缩小操作))
pinch(self, element=None, percent=200, steps=50):
Pinch on an element a certain amount
#在元素上执行模拟双指捏(缩小操作)
:Args:
- element - the element to pinch
- percent - (optional) amount to pinch. Defaults to 200%
- steps - (optional) number of steps in the pinch action
:Usage:
driver.pinch(element)
用法 driver.pinch(element)
12.zoom (在元素上执行放大操作)
zoom(self, element=None, percent=200, steps=50):
Zooms in on an element a certain amount
#在元素上执行放大操作
:Args:
- element - the element to zoom - percent
- (optional) amount to zoom. Defaults to 200%
- steps - (optional) number of steps in the zoom action :Usage:
driver.zoom(element)
用法 driver.zoom(element)
13.reset (重置应用(类似删除应用数据) )
reset(self):
Resets the current application on the device.
重置应用(类似删除应用数据)
用法driver.reset()
14 hide_keyboard (隐藏键盘,iOS 使用 key_name 隐藏,安卓不使用参数 )
hide_keyboard(self, key_name=None, key=None, strategy=None):
Hides the software keyboard on the device. In iOS, use `key_name` to press a particular key, or `strategy`. In Android