APPIUM API整理(python)---其他辅助类

App运行类

1.current_activity

current_activity(self):

Retrieves the current activity on the device.
获取当前的activity
用法 print(driver.current_activity())

2. start_activity

start_activity(self, app_package, app_activity, **opts):

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)?
用法 driver.start_activity(app_package, app_activity)

3. wait_activity

wait_activity(self, activity, timeout, interval=1):

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
用法driver.wait_activity(‘.activity.xxx’,5,2)

4. background_app

background_app(self, seconds):

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
用法 driver.background_app(5)   置后台5秒后再运行

5.is_app_installed

is_app_installed(self, bundle_id):

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
用法 driver.is_app_installed(“com.xxxx”)

6.install_app

install_app(self, 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
用法 driver.install_app(app_path)
23.remove_app
remove_app(self, app_id):

Remove the specified application from the device.
    删除app
    :Args:
     - app_id - the application id to be removed
用法 driver.remove_app(“com.xxx.”)

7.launch_app

launch_app(self):

Start on the device the application specified in the desired capabilities.
启动app
用法 driver.launch_app()
25.close_app
close_app(self):

Stop the running application, specified in the desired capabilities, on the device.
关闭app
用法 driver.close_app()
启动和关闭app运行好像会出错

8.current_url

current_url(self):

    Gets the URL of the current page.
    获取当前页面的网址。
    :Usage:
        driver.current_url
用法 driver.current_url

9. page_source

page_source(self):

Gets the source of the current page.
获取当前页面的源。
:Usage:
    driver.page_source

10.close

close(self):

Closes the current window.
关闭当前窗口
:Usage:
    driver.close()

11.clear

clear(self):

Clears the text if it‘s a text entry element.
    清除输入的内容
用法 element.clear()

网络相关

12.network_connection

network_connection(self):

Returns an integer bitmask specifying the network connection type.
    Android only.
返回网络类型  数值
    Possible values are available through the enumeration `appium.webdriver.ConnectionType`

用法 driver.network_connection

13. set_network_connection

set_network_connection(self, connectionType):

Sets the network connection type. Android only.
    Possible values:
        Value (Alias)      | Data | Wifi | Airplane Mode
        -------------------------------------------------
        0 (None)           | 0    | 0    | 0
        1 (Airplane Mode)  | 0    | 0    | 1
        2 (Wifi only)      | 0    | 1    | 0
        4 (Data only)      | 1    | 0    | 0
        6 (All network on) | 1    | 1    | 0
    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 = 0
AIRPLANE_MODE = 1
WIFI_ONLY = 2
DATA_ONLY = 4
ALL_NETWORK_ON = 6

输入法相关

14. available_ime_engines

available_ime_engines(self):

Get the available input methods for an Android device. Package and activity are returned (e.g., [‘com.android.inputmethod.latin/.LatinIME‘])
    Android only.
返回安卓设备可用的输入法
用法print(driver.available_ime_engines)

15.is_ime_active

is_ime_active(self):

Checks whether the device has IME service active. Returns True/False.
    Android only.
检查设备是否有输入法服务活动。返回真/假。
安卓
用法 print(driver.is_ime_active())

16.activate_ime_engine

activate_ime_engine(self, engine):

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‘)

用法 driver.activate_ime_engine(“com.android.inputmethod.latin/.LatinIME”)

17.deactivate_ime_engine

deactivate_ime_engine(self):

Deactivates the currently active IME engine on the device.
    Android only.
关闭安卓设备当前的输入法
用法 driver.deactivate_ime_engine()
36.active_ime_engine
active_ime_engine(self):

Returns the activity and package of the currently active IME engine (e.g.,
    ‘com.android.inputmethod.latin/.LatinIME‘).
    Android only.
    返回当前输入法的包名
用法 driver.active_ime_engine

设备操作相关

18.open_notifications

open_notifications(self):

Open notification shade in Android (API Level 18 and above)
打系统通知栏(仅支持API 18 以上的安卓系统)
用法 driver.open_notifications()

19. toggle_location_services

toggle_location_services(self):

Toggle the location services on the device. Android only.
打开安卓设备上的位置定位设置
用法 driver.toggle_location_services()

20.set_location

set_location(self, latitude, longitude, altitude):

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
用法 driver.set_location(纬度,经度,高度)

元素操作相关

21.tag_name

tag_name(self):

This element‘s ``tagName`` property.
返回元素的tagName属性
经实践返回的是class name
用法 element.tag_name()

22.text

text(self):

The text of the element.
    返回元素的文本值
用法 element.text()

23.is_selected

is_selected(self):

Returns whether the element is selected.

    Can be used to check if a checkbox or radio button is selected.
返回元素是否选择。
可以用来检查一个复选框或单选按钮被选中。
用法 element.is_slected()

24.is_enabled

is_enabled(self):

Returns whether the element is enabled.
    返回元素是否可用True of False
用法 element.is_enabled()

25. is_displayed

is_displayed(self):

Whether the element is visible to a user.
此元素用户是否可见。简单地说就是隐藏元素和被控件挡住无法操作的元素(仅限 Selenium,appium是否实现了类似功能不是太确定)这一项都会返回 False

用法 driver.element.is_displayed()

26.size

size(self):

The size of the element.
获取元素的大小(高和宽)

new_size["height"] = size["height"]
new_size["width"] = size["width"]

用法 driver.element.size

27.location

location(self):

The location of the element in the renderable canvas.

获取元素左上角的坐标

用法 driver.element.location
‘‘‘返回element的x坐标, int类型‘‘‘
driver.element.location.get(‘x‘)
‘‘‘返回element的y坐标, int类型‘‘‘
driver.element.location.get(‘y‘)

28.rect

rect(self):

A dictionary with the size and location of the element.
    元素的大小和位置的字典

29. screenshot_as_base64

screenshot_as_base64(self):

Gets the screenshot of the current element as a base64 encoded string.
    获取当前元素的截图为Base64编码的字符串
    :Usage:
        img_b64 = element.screenshot_as_base64

其他

30.get_attribute

get_attribute(self, name):

详见@chenhengjie123 https://testerhome.com/topics/2606

Gets the given attribute or property of the element.
1、获取 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")

31. 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.
    暂不知道用法

32. value_of_css_property

value_of_css_property(self, property_name):

The value of a CSS property.
CSS属性

用法 暂不知

33.execute_script

execute_script(self, script, *args):

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.

    :Usage:
        driver.execute_script(‘document.title‘)

34.execute_async_script

execute_async_script(self, script, *args):

Asynchronously Executes JavaScript in the current window/frame.
插入 javascript 代码,只是这个是异步的,也就是如果你的代码是睡眠5秒,那么你只是自己在睡,页面的其他 javascript 代码还是照常执行
    :Args:
     - script: The JavaScript to execute.
     - \*args: Any applicable arguments for your JavaScript.

    :Usage:
        driver.execute_async_script(‘document.title‘)
时间: 2024-10-08 03:38:43

APPIUM API整理(python)---其他辅助类的相关文章

APPIUM API整理(python)---元素查找

最近在学习自动化框架appium,网上找一些API相关资料整理了一下 1.find_element_by_id find_element_by_id(self, id_): Finds element within this element's children by ID(通过元素的ID定位元素) :Args: - id_ - ID of child element to locate. 用法 driver. find_element_by_id("id") find_element

APPIUM API整理(python)---操作类

APPIUM 常用API介绍(1) 前言:android手机大家都很熟悉,操作有按键.触摸.点击.滑动等,各种操作方法可以通过api的方法来实现.参考博文:http://blog.csdn.net/bear_w/article/details/50330565 1.click click(self):Clicks the element(点击元素 )用法 element.click() driver.find_element_by_id('com.huawei.camera:id/shutter

中文Appium API 文档

该文档是Testerhome官方翻译的源地址:https://github.com/appium/appium/tree/master/docs/cn官方网站上的:http://appium.io/slate/cn/master/?ruby#about-appium 中文Appium API 文档 第一章:关于appium1.1 appium客户端客户端类库列表及Appium服务端支持 这些类库封装了标准Selenium客户端类库,为用户提供所有常见的JSON 格式selenium命令以及额外的

Appium appium+Android+selenium+python web 自动化 / 手机自动化 [分享] (windows)

前期准备 1.windows操作系统2.python3.53.selenium4.chrome浏览器5.chrome浏览器驱动6.pycharm7.appium8.JDK9.SDK10.安卓模拟器(genymotion)或真机11.任意apk12.使用安卓模拟器genymotion需要virtual box(个别的会补充,软件版本自己随意) 一.知识补充(1) Appium介绍 Appium是一个开源.跨平台的测试框架,可以用来测试原生及混合的移动端应用.Appium支持iOS.Android及

metaweblog API csdn python 实现

layout: post author: "kele" title: "metaweblog API csdn python实现" tags: python metaweblog date: "2018-02-14 22:15:32" --- metaweblog API csdn python 实现 一直想同步三个博客,梦想很大,一直在找各种工具,但是一个也没有遇到,今天突然发现了一个叫作open live writer的东西,仔细研究了一下发

Bootstrap FileInput 上传 中文 API 整理

Bootstrap FileInput 上传  中文 API 整理 上传插件有很多 但是公司用的就是 Bootstrap FileInput 自己就看了看  会用就行 自己都不知道每个值是干嘛用的就问大佬 总结一下 1 一. 引入文件 2 <link href="../css/bootstrap.min.css"rel="stylesheet"> 3 <link href="../css/fileinput.css" media

appium API接口

appium API接口 标签(空格分隔): appium常用api 1.contexts contexts(self) 返回当前会话的上下文,使用可以识别H5页面的控件: driver.contexts 2.current_context 返回当前会话的当前上下文: 用法:driver.current_context 3.context 返回当前会话的当前上下文: 用法:driver.context find_element_by_ios_uiautomation(self,uia_strin

调用百度ocr的API,python简易版本

调用百度ocr的API,python简易版本 https://www.jianshu.com/p/e10dc43c38d0 1. 注册 百度云注册账号 https://cloud.baidu.com/?from=console 管理应用 https://console.bce.baidu.com/ai/#/ai/ocr/overview/index 创建一个 图1登陆之后的界面 进入链接之后创建应用,由于是从文字识别点进去的,所以默认选中的就是ocr相关内容,填好表格确认. 图2 创建应用之后的

Macaca的Python的api整理

整理了下Macaca的API,做成思维脑图,方便阅览. WebDriver 安装 pip install wd git clone https://github.com/macacajs/wd.py.git 初始化WebDriver driver.init() 停止WebDriver driver.quit() 附加到现有会话 driver.attach('012-345-678-9') 方法 driver.get('https://www.google.com') driver.refresh