APPIUM API整理(python)---其餘輔助類

App運行類

1.current_activityjavascript

current_activity(self):css

用法: print(driver.current_activity())java

Retrieves the current activity on the device.
獲取當前的activity 

 2. start_activityandroid

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

用法: driver.start_activity(app_package, app_activity)web

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_activitycanvas

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

用法:driver.wait_activity(‘.activity.xxx’,5,2)app

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

輸入法相關

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 18 and above) 打系統通知欄(僅支持API 18 以上的安卓系統)

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/2606 
Gets the given attribute or property of the element.
1、獲取 content-desc 的方法爲 get_attribute("name") ,並且還不能保證返回的必定是 content-desc (content-desc 爲空時會返回 text 屬性值)
二、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屬性 用法 暫不知
相關文章
相關標籤/搜索