APPIUM API整理(python)---其他辅助类
App运行类
1.current_activity
current_activity(self):
用法: print(driver.current_activity())
Retrieves the current activity on the device.
获取当前的activity
2. start_activity
start_activity(self, app_package, app_activity, **opts):
用法: driver.start_activity(app_package, app_activity)
Opens an arbitrary activity during a test. If the activity belongs to another application, that application is started and the activity is opened. This is an Android-only method.
在测试过程中打开任意活动。如果活动属于另一个应用程序,该应用程序的启动和活动被打开。
这是一个安卓的方法
:Args: - app_package - The package containing the activity to start.
- app_activity - The activity to start.
- app_wait_package
- Begin automation after this package starts (optional).
- app_wait_activity - Begin automation after this activity starts (optional).
- intent_action - Intent to start (optional). - intent_category
- Intent category to start (optional).
- intent_flags
- Flags to send to the intent (optional).
- optional_intent_arguments - Optional arguments to the intent (optional).
- stop_app_on_reset
- Should the app be stopped on reset (optional)?
3. wait_activity
wait_activity(self, activity, timeout, interval=1):
用法:driver.wait_activity(‘.activity.xxx’,5,2)
Wait for an activity: block until target activity presents or time out. This is an Android-only method.
等待指定的activity出现直到超时,interval为扫描间隔1秒 即每隔几秒获取一次当前的activity 返回的True 或 False :
Agrs: - activity
- target activity
- timeout
- max wait time, in seconds
- interval
- sleep interval between retries, in seconds
4. background_app
background_app(self, seconds):
用法 :driver.background_app(5) 置后台5秒后再运行
Puts the application in the background on the device for a certain duration. 后台运行app多少秒
:Args:
- seconds
- the duration for the application to remain in the background
5.is_app_installed
is_app_installed(self, bundle_id):
用法: driver.is_app_installed(“com.xxxx”)
Checks whether the application specified by `bundle_id` is installed on the device. 检查app是否有安装 返回 True or False
:Args:
- bundle_id
- the id of the application to query
6.install_app
install_app(self, app_path):
用法: driver.install_app(app_path)
Install the application found at `app_path` on the device. 安装app,app_path为安装包路径
:Args:
- app_path
- the local or remote path to the application to install
7.remove_app
remove_app(self, app_id):
用法 :driver.remove_app(“com.xxx.”)
Remove the specified application from the device. 删除app
:Args:
- app_id
- the application id to be removed
8.launch_app
launch_app(self):
用法: driver.launch_app()
Start on the device the application specified in the desired capabilities. 启动app
9.close_app
close_app(self):
用法: driver.close_app() 启动和关闭app运行好像会出错
Stop the running application, specified in the desired capabilities, on the device. 关闭app
10.current_url
current_url(self):
用法 :driver.current_url()
Gets the URL of the current page. 获取当前页面的网址。
11. page_source
page_source(self):
用法: driver.page_source()
Gets the source of the current page. 获取当前页面的源。
12.close
close(self):
Usage: driver.close()
Closes the current window. 关闭当前窗口
13.clear
clear(self):
用法: element.clear()
Clears the text if it's a text entry element. 清除输入的内容
网络相关
14.network_connection
network_connection(self):
用法: driver.network_connection
Returns an integer bitmask specifying the network connection type. Android only. 返回网络类型 数值 Possible values are available through the enumeration `appium.webdriver.ConnectionType`
16. set_network_connection
set_network_connection(self, connectionType):
用法 :dr.set_network_connection(ConnectionType.WIFI_ONLY)
Sets the network connection type. Android only.
Possible values: Value (Alias) | Data | Wifi | Airplane Mode
-------------------------------------------------
(None) | | |
(Airplane Mode) | | |
(Wifi only) | | |
(Data only) | | |
(All network on) | | |
These are available through the enumeration `appium.webdriver.ConnectionType`
设置网络类型
:Args: - connectionType
- a member of the enum appium.webdriver.ConnectionType
用法 先加载
from appium.webdriver.connectiontype import ConnectionType
dr.set_network_connection(ConnectionType.WIFI_ONLY)
ConnectionType的类型有
NO_CONNECTION =
AIRPLANE_MODE =
WIFI_ONLY =
DATA_ONLY =
ALL_NETWORK_ON =
输入法相关
17. available_ime_engines
available_ime_engines(self):
用法:print(driver.available_ime_engines)
Get the available input methods for an Android device.
Package and activity are returned (e.g., ['com.android.inputmethod.latin/.LatinIME']) Android only.
返回安卓设备可用的输入法
18.is_ime_active
is_ime_active(self):
用法: print(driver.is_ime_active())
Checks whether the device has IME service active. Returns True/False.
Android only.
检查设备是否有输入法服务活动。返回真/假。
安卓
19.activate_ime_engine
activate_ime_engine(self, engine):
用法 :driver.activate_ime_engine(“com.android.inputmethod.latin/.LatinIME”)
Activates the given IME engine on the device.
Android only.
激活安卓设备中的指定输入法,设备可用输入法可以从“available_ime_engines”获取
:Args: - engine
- the package and activity of the IME engine to activate (e.g., 'com.android.inputmethod.latin/.LatinIME')
20.deactivate_ime_engine
deactivate_ime_engine(self):
用法: driver.deactivate_ime_engine()
Deactivates the currently active IME engine on the device.
Android only.
关闭安卓设备当前的输入法
21.active_ime_engine
active_ime_engine(self):
用法:driver.active_ime_engine
Returns the activity and package of the currently active IME engine (e.g., 'com.android.inputmethod.latin/.LatinIME').
Android only.
返回当前输入法的包名
设备操作相关
22.open_notifications
open_notifications(self):
用法 :driver.open_notifications()
Open notification shade in Android (API Level and above) 打系统通知栏(仅支持API 以上的安卓系统)
23. toggle_location_services
toggle_location_services(self):
用法 :driver.toggle_location_services()
Toggle the location services on the device. Android only. 打开安卓设备上的位置定位设置
24.set_location
set_location(self, latitude, longitude, altitude):
用法: driver.set_location(纬度,经度,高度)
Set the location of the device 设置设备的经纬度
:Args:
- latitude纬度
- String or numeric value between -90.0 and 90.00
- longitude经度 - String or numeric value between -180.0 and 180.0
- altitude海拔高度- String or numeric value
元素操作相关
25.tag_name
tag_name(self):
用法 :element.tag_name()
This element's ``tagName`` property.
返回元素的tagName属性
经实践返回的是class name
26.text
text(self):
用法 element.text()
The text of the element. 返回元素的文本值
27.is_selected
is_selected(self):
用法 :element.is_slected()
Returns whether the element is selected.
Can be used to check if a checkbox or radio button is selected.
返回元素是否选择。
可以用来检查一个复选框或单选按钮被选中。
28.is_enabled
用法 element.is_enabled()
is_enabled(self): Returns whether the element is enabled.
返回元素是否可用True of False
29. is_displayed
is_displayed(self):
用法: driver.element.is_displayed()
Whether the element is visible to a user.
此元素用户是否可见。
简单地说就是隐藏元素和被控件挡住无法操作的元素(仅限 Selenium,appium是否实现了类似功能不是太确定)
这一项都会返回 False
30.size
size(self):
用法 :driver.element.size
The size of the element.
获取元素的大小(高和宽)
new_size["height"] = size["height"]
new_size["width"] = size["width"]
31.location
location(self):
用法 :driver.element.location
The location of the element in the renderable canvas.
获取元素左上角的坐标 '''返回element的x坐标, int类型'''
driver.element.location.get('x')
'''返回element的y坐标, int类型'''
driver.element.location.get('y')
32.rect
rect(self):
A dictionary with the size and location of the element.
元素的大小和位置的字典
33. screenshot_as_base64
screenshot_as_base64(self):
用法:img_b64 = element.screenshot_as_base64
Gets the screenshot of the current element as a base64 encoded string.
获取当前元素的截图为Base64编码的字符串
其他
34.execute_script
execute_script(self, script, *args):
用法 :driver.execute_script('document.title')
Synchronously Executes JavaScript in the current window/frame.
在当前窗口/框架(特指 Html 的 iframe )同步执行 javascript 代码。你可以理解为如果这段代码是睡眠5秒,这五秒内主线程的 javascript 不会执行
:Args:
- script: The JavaScript to execute.
- \*args: Any applicable arguments for your JavaScript.
35.execute_async_script
execute_async_script(self, script, *args):
用法:driver.execute_async_script('document.title')
Asynchronously Executes JavaScript in the current window/frame.
插入 javascript 代码,只是这个是异步的,也就是如果你的代码是睡眠5秒,那么你只是自己在睡,页面的其他 javascript 代码还是照常执行
:Args:
- script: The JavaScript to execute.
- \*args: Any applicable arguments for your JavaScript.
36.get_attribute
get_attribute(self, name):
详见@chenhengjie123 https://testerhome.com/topics/
Gets the given attribute or property of the element.
、获取 content-desc 的方法为 get_attribute("name") ,而且还不能保证返回的一定是 content-desc (content-desc 为空时会返回 text 属性值)
2、get_attribute 方法不是我们在 uiautomatorviewer 看到的所有属性都能获取的(此处的名称均为使用 get_attribute 时使用的属性名称):
可获取的:
字符串类型: name(返回 content-desc 或 text)
text(返回 text)
className(返回 class,只有 API=>18 才能支持)
resourceId(返回 resource-id,只有 API=>18 才能支持)
This method will first try to return the value of a property with the given name.
If a property with that name doesn't exist, it returns the value of the attribute with the same name.
If there's no attribute with that name, ``None`` is returned.
Values which are considered truthy, that is equals "true" or "false", are returned as booleans.
All other non-``None`` values are returned as strings.
For attributes or properties which do not exist, ``None`` is returned.
:Args:
- name
- Name of the attribute/property to retrieve.
Example::
# Check if the "active" CSS class is applied to an element.
is_active = "active" in target_element.get_attribute("class")
37. location_once_scrolled_into_view
location_once_scrolled_into_view(self):
THIS PROPERTY MAY CHANGE WITHOUT WARNING.
Use this to discover where on the screen an element is so that we can click it.
This method should cause the element to be scrolled into view.
Returns the top lefthand corner location on the screen, or ``None`` if the element is not visible.
暂不知道用法
38. value_of_css_property
value_of_css_property(self, property_name):
The value of a CSS property. CSS属性 用法 暂不知
APPIUM API整理(python)---其他辅助类的更多相关文章
- APPIUM API整理(python)---元素查找
最近在学习自动化框架appium,网上找一些API相关资料整理了一下 1.find_element_by_id find_element_by_id(self, id_): Finds element ...
- APPIUM API整理(python)---操作类
前言:android手机大家都很熟悉,操作有按键.触摸.点击.滑动等,各种操作方法可以通过api的方法来实现. 参考博文:http://blog.csdn.net/bear_w/article/det ...
- 移动端自动化测试(二)之 Appium常用的API(python)函数介绍
上一章节已经介绍了Appium的环境搭建,其实只要掌握了Appium的工作原理,前期的准备工作和安装过程是比较简单的.那么当我们搭建好Appium环境后接下来做些什么呢?通常思路是开始appium的第 ...
- 篇4 安卓app自动化测试-Appium API进阶
篇4 安卓app自动化测试-Appium API进阶 --lamecho辣么丑 1.1概要 大家好! 我是lamecho(辣么丑),今天是<安卓app自动化测试& ...
- (转载)中文Appium API 文档
该文档是Testerhome官方翻译的源地址:https://github.com/appium/appium/tree/master/docs/cn官方网站上的:http://appium.io/s ...
- 中文Appium API 文档
该文档是Testerhome官方翻译的源地址:https://github.com/appium/appium/tree/master/docs/cn官方网站上的:http://appium.io/s ...
- appium(6)-parts of appium api
parts of appium api Lock Lock the screen.//锁屏. // java driver.lockScreen(3); // objective c [driver ...
- canvas学习之API整理笔记(二)
前面我整理过一篇文章canvas学习之API整理笔记(一),从这篇文章我们已经可以基本了解到常用绘图的API.简单的变换和动画.而本篇文章的主要内容包括高级动画.像素操作.性能优化等知识点,讲解每个知 ...
- 安卓自动化测试:Android studio 自带的 Record Espresso Test || [ Appium & (Android studio || Python|| Eclipse ) ]
1.Android studio 自带的 Record Espresso Test https://developer.android.com/studio/test/espresso-test-r ...
随机推荐
- Node.js模块 require和 exports
https://liuzhichao.com/p/1669.html http://www.cnblogs.com/pigtail/archive/2013/01/14/2859555.html
- cocos2d-x-3.6 引擎基础概念
先讲一下引擎里面几个重要的基础概念:导演.节点,场景.层,精灵. 当然实际开发人员会碰到非常多其它概念,不过不要紧.有了这些基础概念,后面自己学习起来就easy多了. 节点(Node)是cocos2d ...
- Duilib教程-非DUI控件
DUILIB并不是真正的DUI,至少有部分控件不是完全DUI的.其实包括: 1.EDIT. 它的实现原理是,CEditUI包含一个窗口CEditWnd,流程如下: 1)鼠标单击,创建窗口见 EditU ...
- NATS源代码之logger目录
nats的logger目录文件如下 log.go syslog.go syslog_windows.go 基于golang语言的logger包实现日志功能. Golang的log包短小精悍,可以非常轻 ...
- Android 触摸及手势操作GestureDetector
现在的智能手机不敢说百分百的都是触摸屏,也应该是百分之九九以上为触摸屏了,触摸屏为我们操作无键盘.无鼠标的手机系统带来了很多的便利.当用户触摸屏幕时会产生很多的触摸事件,down.up.move等等. ...
- Codeforces Round #365 (Div. 2) D.Mishka and Interesting sum
题目链接:传送门 题目大意:给n个数,m次询问,每次询问区间 l,r 内出现偶数次数的异或和 题目思路:前缀和+离线处理+树状数组 首先可以知道, l,r 内出现奇数次的数的和,就是把 l,r内所有数 ...
- Caused by: java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected
需要注意的是ComponentScan 不能扫描 org.springframework 否则会报错,要扫描指定的package才行
- MySQL 索引设计概要
在关系型数据库中设计索引其实并不是复杂的事情,很多开发者都觉得设计索引能够提升数据库的性能,相关的知识一定非常复杂. 然而这种想法是不正确的,索引其实并不是一个多么高深莫测的东西,只要我们掌握一定的方 ...
- 巨蟒python全栈开发flask4
1.偏函数 2.ThreadingLocal线程安全 空间换取时间 3.LocalStack 4.RunFlask+request 5.请求上文 6.请求下文
- Struts 2.0 入门
1. Struts2.0 概述 Struts 2.0 是以 WebWork 为核心,采用拦截器的机制来处理用户的请求; Struts 2.0 是一个基于 MVC 设计模式的 Web 层框架; Stru ...