Appium(Python)API

來源:互聯網
上載者:User

標籤:可見   隱藏   screen   form   事件   exe   相等   load   上下文   

1、
建立新的會話
desired_caps = desired_caps = {
  ‘platformName‘: ‘Android‘,
  ‘platformVersion‘: ‘7.0‘,
  ‘deviceName‘: ‘Android Emulator‘,
  ‘automationName‘: ‘UiAutomator2‘,
  ‘app‘: PATH(‘/path/to/app‘)
}
self.driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub‘, desired_caps)

2、
結束會話
self.driver.quit()

3、
擷取會話功能
desired_caps = self.driver.desired_capabilities()

4、
回退(僅限Web上下文)
self.driver.back()

5、

screenshotBase64 = self.driver.get_screenshot_as_base64()

6、
逾時

設定逾時
self.driver.set_page_load_timeout(5000)

設定隱式等待逾時
self.driver.implicitly_wait(5000)

設定指令碼逾時
設定的時間量,
以毫秒為單位,
通過執行非同步指令碼,
執行非同步允許運行它們都將立即中止之前(僅限於Web上下文)
self.driver.set_script_timeout(5000)

7、
方向

擷取定位
orientation = self.driver.orientation()

設定方向
driver.orientation = "LANDSCAPE"

8、
地理物質

擷取地理位置
location = self.driver.location()

設定地理位置
self.driver.set_location(49, 123, 10)

9、
日誌

擷取可用的日誌類型
log_types = driver.log_types()

擷取日誌
logs = driver.get_log(‘driver‘)

10、
設定

更新裝置設定
# Python不支援

檢索裝置設定
# Python不支援

 

11、
活動

開始活動
self.driver.start_activity("com.example", "ActivityName")

擷取當前活動
activity = self.driver.current_activity()

擷取當前包
package = self.driver.current_package()

12、
應用

安裝應用程式
self.driver.install_app(‘/Users/johndoe/path/to/app.apk‘)

應用程式已安裝
self.driver.is_app_installed(‘com.example.AppName‘)

啟動應用程式
self.driver.launch_app()

背景應用程式
將當前正在啟動並執行應用程式發送到後台
self.driver.background_app(10)

關閉應用程式
self.driver.close_app()

重設應用程式
self.driver.reset()

刪除應用程式
self.driver.remove_app(‘com.example.AppName‘)

擷取應用程式字串
appStrings = self.driver.app_strings("en", "/path/to/file")

擷取測試覆蓋率資料
self.driver.end_test_coverage("Intent", "/path")


13、
檔案

推送檔案
self.driver.push_file(‘/path/to/device/foo.bar‘, ‘QXJlIHlvdXIgYmVlcnMgb2theT8=‘)

拉檔案
file_base64 = self.driver.pull_file(‘/path/to/device/foo.bar‘)

拉檔案夾
folder_base64 = self.driver.pull_folder(‘/path/to/device/foo.bar‘)

14、
動作

搖晃
self.driver.shake()

鎖定
self.driver.lock()

解鎖
self.driver.unlock()

裝置是否被鎖定
# Python不支援

旋轉
# Python不支援

15、
按鍵

按鍵代碼
self.driver.press_keycode(10)

長按鍵代碼
self.driver.long_press_keycode(10)

隱藏鍵盤
self.driver.hide_keyboard()

顯示鍵盤
# Python不支援

 

16、
網路

切換飛航模式
# Python不支援

切換資料服務
# Python不支援

切換WiFi
# Python不支援

切換位置服務的狀態
self.driver.toggle_location_services()

類比簡訊(僅適用於模擬器)
# Python不支援

撥打GSM電話(僅限Emulator)
# Python不支援

設定GSM訊號強度(僅限模擬器)
# Python不支援

設定GSM語音狀態(僅適用於模擬器)
# Python不支援

17、
效能資料

擷取效能資料
返回支援讀取的系統狀態資訊,如CPU,記憶體,網路流量和電池
# Python不支援

擷取效能資料類型
# Python不支援

 

18、
模擬器

執行Touch ID
類比Touch ID事件(僅適用於iOS模擬器)
self.driver.touch_id(false)
# 類比失敗的觸摸
self.driver.touch_id(true)
# 類比通過的觸摸

切換正在註冊的模擬器以接受Touch ID(僅適用於iOS模擬器)
self.driver.toggle_touch_id_enrollment()

19、
系統

開啟Android通知(僅適用於模擬器)
self.driver.open_notifications()

擷取系統欄
檢索狀態和導覽列的可見度和邊界資訊
# Python不支援

擷取系統時間
time = self.driver.device_time()

20、
尋找元素
el = self.driver.find_element_by_accessibility_id(‘SomeAccessibilityID‘)

21、
操作

點擊
el = self.driver.find_element_by_accessibility_id(‘SomeId‘)
el.click()

輸入
self.driver.find_element_by_accessibility_id(‘SomeAccessibilityID‘).send_keys(‘Hello world!‘)

清除元素的值
self.driver.find_element_by_accessibility_id(‘SomeAccessibilityID‘).clear()

22、
屬性

擷取元素文本
el = self.driver.find_element_by_accessibility_id(‘SomeAccessibilityID‘)
text = el.text

擷取標籤名稱
tagName = self.driver.find_element_by_accessibility_id(‘SomeAccessibilityID‘).tag_name

擷取元素屬性
tagName = self.driver.find_element_by_accessibility_id(‘SomeAccessibilityID‘).get_attribute(‘content-desc‘)

元素被選中
確定是否選擇了表單或表單類元素(複選框,選擇等)
self.driver.find_element_by_accessibility_id(‘SomeAccessibilityID‘).is_selected()

元素已啟用
確定元素當前是否啟用
self.driver.find_element_by_accessibility_id(‘SomeAccessibilityID‘).is_enabled()

擷取元素位置
確定元素在頁面或螢幕上的位置
location = self.driver.find_element_by_accessibility_id(‘SomeAccessibilityID‘).location

擷取元素大小
以像素為單位確定元素的大小
size = self.driver.find_element_by_accessibility_id(‘SomeAccessibilityID‘).size

擷取元素矩形
擷取元素的尺寸和座標
# Python不支援

擷取元素CSS值
查詢Web元素的計算CSS屬性的值
cssProperty = self.driver.find_element_by_accessibility_id(‘SomeId‘).value_of_css_property("style")

在視圖中擷取元素位置
一旦將元素滾動到視圖中,確定元素在螢幕上的位置(主要是內部命令並且不被所有用戶端支援)
# Python不支援

23、
提交表單
提交一個FORM元素
el = self.driver.find_element_by_accessibility_id(‘SomeAccessibilityID‘)
el.submit();

24、
擷取使用中的元素
element = driver.switch_to.active_element

25、
元素是否相等
# Python不支援

 

26、
上下文

擷取當前上下文
context = driver.current_context
或者
context = driver.context

擷取所有上下文
contexts = driver.contexts

設定當前上下文
webview = driver.contexts[1]
driver.switch_to.context(webview)
# ...
driver.switch_to.context(‘NATIVE_APP‘)

27、
滑鼠

將滑鼠移至
actions = ActionChains(driver)
actions.move_to(element, 10, 10)
actions.perform()

在當前滑鼠座標點擊任意滑鼠按鍵
actions = ActionChains(driver)
actions.move_to_element(element)
actions.click()
actions.perform()

雙擊當前滑鼠座標(由moveto設定)
actions = ActionChains(driver)
actions.move_to_element(element)
actions.double_click()
actions.perform()

按鈕關閉
在當前的滑鼠座標上單擊並按住滑鼠左鍵
actions = ActionChains(driver)
actions.move_to_element(element)
actions.click_and_hold()
actions.perform()

扣緊
釋放先前保持的滑鼠按鍵
actions = ActionChains(driver)
actions.move_to_element(element)
actions.click_and_hold()
actions.move_to_element(element, 10, 10)
action.release()
actions.perform()

28、
觸摸

單擊輕觸裝置
actions = TouchActions(driver)
actions.tap(element)
actions.perform()

雙擊
使用手指動作事件雙擊觸控螢幕
actions = TouchActions(driver)
actions.double_tap(element)
actions.perform()

移動
手指在螢幕上移動
actions = TouchActions(driver)
actions.tap_and_hold(element)
actions.move(50, 50)
actions.perform()

觸摸下來
手指在螢幕上
actions = TouchActions(driver)
actions.tap_and_hold(element)
actions.move(50, 50)
actions.perform()

潤色(做小的修改)
手指在螢幕上
actions = TouchActions(driver)
actions.tap_and_hold(20, 20)
actions.release(50, 50)
actions.perform()

長按
使用手指運動事件長按觸控螢幕
actions = TouchActions(driver)
actions.long_press(element)
actions.perform()

滾動
使用基於手指的動作事件在觸控螢幕上滾動
actions = TouchActions(driver)
actions.scroll_from_element(element, 10, 100)
actions.scroll(10, 100)
actions.perform()

拂去
使用手指運動事件輕擊觸控螢幕
actions = TouchActions(driver)
actions.flick_element(element, 1, 10, 10)
actions.perform()

多點觸摸執行
執行多點觸摸動作序列
from appium.webdriver.common.touch_action import TouchAction
from appium.webdriver.common.multi_action import MultiAction

a1 = TouchAction()
a1.press(10, 20)
a1.move_to(10, 200)
a1.release()

a2 = TouchAction()
a2.press(10, 10)
a2.move_to(10, 100)
a2.release()

ma = MultiAction(self.driver)
ma.add(a1, a2)
ma.perform()

觸摸執行
執行一個觸摸動作序列
from appium.webdriver.common.touch_action import TouchAction

actions = TouchAction(driver)
actions.tap_and_hold(20, 20)
actions.move_to(10, 100)
actions.release()
actions.perform()

29、
視窗

切換到視窗
將焦點更改為另一個視窗(僅限Web上下文)
self.driver.switch_to.window("handle")

關閉視窗
關閉當前視窗(僅限Web上下文)
self.driver.close()

擷取視窗控制代碼
檢索當前視窗控制代碼(僅限Web上下文)
window_handle = self.driver.current_window_handle()

擷取所有視窗控制代碼
檢索可用於會話的所有視窗控制代碼的列表(僅限Web上下文)
window_handles = self.driver.window_handles()

擷取標題
擷取當前頁面標題(僅限Web上下文)
title = self.driver.title()

擷取視窗大小
擷取指定視窗的大小(僅限Web上下文)
handle_one_size = self.driver.get_window_size()
handle_two_size = self.driver.get_window_size("handleName")

設定視窗大小
更改指定視窗的大小(僅限Web上下文)
self.driver.set_window_size(10, 10)

擷取視窗位置
擷取指定視窗的位置(僅限Web上下文)
handle_one_position = self.driver.get_window_position()
handle_two_position = self.driver.get_window_position("handleName")

設定視窗位置
更改指定視窗的位置(僅限Web上下文)
self.driver.set_window_position(10, 10)

已最大化的視窗
最大化指定的視窗(僅限Web上下文)
self.driver.maximize_window()

30、
導航

導航到URL
導航到新的URL(僅限Web上下文)
self.driver.get("http://appium.io/")

擷取URL
檢索當前頁面的URL(僅限Web上下文)
url = self.driver.current_url()

回去
如果可能,在瀏覽器記錄中向後瀏覽(僅限Web上下文)
self.driver.back()

前進
如果可能,在瀏覽器記錄中向前瀏覽(僅限Web上下文)
self.driver.forward()

重新整理
重新整理當前頁面(僅限Web上下文)
self.driver.refresh()

31、
Cookie

擷取所有Cookie
檢索當前頁面可見的所有cookie(僅限Web上下文)
cookies = self.driver.get_cookies()

設定Cookie
設定一個cookie(僅限Web上下文)
self.driver.add_cookie({name: ‘foo‘, value: ‘bar‘})

刪除Cookie
刪除具有給定名稱的cookie(僅限Web上下文)
self.driver.delete_cookie("cookie_name")

刪除所有Cookie
刪除當前頁面可見的所有cookie(僅限Web上下文)
self.driver.delete_all_cookies()

32、
Frame

切換到frame
將焦點更改為頁面上的其他frame(僅限Web上下文)
self.driver.switch_to.frame(3)

切換到父frame
將焦點更改為父上下文(僅限Web上下文)
self.driver.switch_to.parent()

33、
執行非同步JavaScript
將JavaScript片段注入頁面以在當前選定架構的上下文中執行(僅限Web上下文)
self.driver.execute_async_script(‘document.title’)

34、
執行JavaScript
將JavaScript片段注入頁面以在當前選定架構的上下文中執行(僅限Web上下文)
self.driver.execute_script(‘document.title’)

Appium(Python)API

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.