appium action

使用 Appium Python Client進行測試。https://github.com/appium/python-client
python查看appium webdriver help.

$ from appium import webdriver
$ help(webdriver)

PACKAGE CONTENTS
    common (package)
    connectiontype
    errorhandler
    mobilecommand
    switch_to
    webdriver
    webelement

Api: 元素定位

說明 用法
id定位 driver.find_element_by_id(element)
xpath定位 driver.find_element_by_xpath(element)

Api: 應用安裝卸載

說明 用法
安裝應用 driver.install_app('/path/xxxxxx.apk')
檢查應用是否安裝 driver.is_app_installed("packagename")
卸載應用 driver.remove_app('packagename.apk')

Api: 應用操作相關

說明 用法
啓動應用 driver.launch_app()
關閉應用 driver.close_app()
重置應用 driver.reset()
把當前應用放到app後臺 driver.background_app(10)
打開通知欄 driver.open_notifications()

打開通知欄功能只有Android可用

Api: 文件操作相關

說明 用法
從設備拉出文件 driver.pull_file('path/filename')
向設備推送文件 driver.push_file(path,data.encode('base64'))
截圖 driver.get_screenshot_as_file('login.png')

Api: 屏幕、手勢操作相關

說明 用法
鎖定屏幕 drvier.lock(10)
滑動屏幕 driver.swipe(75,500,75,0,0.8)
driver.pinch(element=e1)
屏幕放大 driver.zoom(element=e1)
長按 long_press()
短按 press()
點擊 tap()
移動到 move_to()
執行手勢操作 perform()
釋放操作 release()
等待 wait()

TouchAction:觸摸操作

.. code-block:: python

from appium.webdriver.common.touch_action import TouchAction

# 錄製小視頻的時候,長按錄製10s
action = TouchAction(driver)
action.long_press(element,None,None,10000).release().perform()

Api: 鍵盤操作相關

說明 用法
在ios上收起鍵盤 driver.hide_keyboard()
發送鍵盤事件 driver.keyevent(176)
搖晃設備 driver.shake()

Api: 應用上下文

說明 用法
列出所有的可用上下文 driver.contexts
列出當前上下文 driver.current_context
將上下文切換到默認上 driver.switch_to.context(None)
應用的字符串 driver.app_strings

Api: Activity相關

說明 用法
獲得activity driver.current_activity



作者:一直小魚
鏈接:https://www.jianshu.com/p/4b4a35b89e2b
來源:簡書
簡書著作權歸作者所有,任何形式的轉載都請聯繫作者獲得授權並註明出處。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章