Appium常用API(二)

时间:2023-05-16 20:51:14

接前面的常用API(一),本文接着介绍如下:

1.press_keycode

press_keycode(self, keycode, metastate=None):

 Sends a keycode to the device. Android only. Possible keycodes can be found in http://developer.android.com/reference/android/view/KeyEvent.html

发送按键码(安卓仅有),模拟点击相应铵键,按键码可以上网址中找到

:Args:

- keycode - the keycode to be sent to the device

- metastate - meta information about the keycode being sent

  Usage:

 driver.press_ keycode(‘4’)      #按返回键

2.long_press_keycode

long_press_keycode(self, keycode, metastate=None):

 Sends a long press of keycode to the device. Android only.

发送一个长按的按键码(长按某键)

:Args:

- keycode - the keycode to be sent to the device

- metastate - meta information about the keycode being sent

  Usage:

  driver.long_press_keycode(‘4’)    #长按返回键

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

  Usage:

 driver.is_app_installed(“com.xxxx”)     #app包名

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

  Usage:

 driver.install_app(app_path)

5.remove_app

remove_app(self, app_id):

 Remove the specified application from the device.

删除app

:Args:

- app_id - the application id to be removed

 Usage:

driver.remove_app(“com.xxx.”)   #app包名

6.open_notifications

open_notifications(self):

 Open notification shade in Android (API Level 18 and above)

 打系统通知栏(仅支持API 18 以上的安卓系统)

 Usage:

 driver.open_notifications()    ##打开系统通知栏

7.launch_app

launch_app(self):

 Start on the device the application specified in the desired capabilities.

 启动app

 Usage:

 driver.launch_app()     #启动应用,一般与close_app配合使用

8.close_app

close_app(self):

 Stop the running application, specified in the desired capabilities, on the device.

 关闭app

 Usage:

 driver.close_app()    #关闭应用,此方法并非真正的关闭应用,相当于按home键将应用置于后台,可以通过launch_app()再次启动

9.is_selected

is_selected(self):

 Returns whether the element is selected.

Can be used to check if a checkbox or radio button is selected.

 可以用来检查一个复选框或单选按钮被选中,返回元素是否选择 True of False

 Usage:

 element.is_slected()

10.is_enabled

is_enabled(self):

 Returns whether the element is enabled.

返回元素是否可用True of False

 Usage:

 element.is_enabled()

11.is_displayed

is_displayed(self):

 Whether the element is visible to a user.

 判断此元素用户是否可见。返回True of False

 Usage:

 driver.element.is_displayed()   #判断是否显示

12.close

close(self):

Closes the current window.

关闭当前窗口

Usage:

driver.close()