日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

appium2.0+ 单点触控和多点触控新的解决方案

發(fā)布時間:2023/12/16 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 appium2.0+ 单点触控和多点触控新的解决方案 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

在 appium2.0 之前,在移動端設(shè)備上的觸屏操作,單手指觸屏和多手指觸屏分別是由 TouchAction 類,Multiaction 類實現(xiàn)的。

在 appium2.0 之后,這 2 個方法將會被舍棄。

"[Deprecated] 'TouchAction' action is deprecated. Please use W3C actions instead."

1、w3c action 是什么?

在 w3c 的 actions 當中,將輸入源分為了三類:

鍵盤類 - Key

指針類 - Pointer

None

對于 Pointer 指針類輸入源,共有 3 種:Mouse 鼠標、Touch 觸屏、Pen 筆觸

輸入源,是提供輸入事件的虛擬設(shè)備。

每一個輸入源,都是一個輸入 id,輸入源 type。與真實設(shè)備一樣,每一個輸入源都有狀態(tài)的,有輸入事件。

在 python selenium 的源碼當中,selenium/common/actions/input_devices.py 里 InputDevices 類定義了輸入源類。

1、空輸入源(null input source)

提供以下行為:

pause:不做任何操作一段時間,或者動作的持續(xù)時間

2、鍵盤輸入源(key input source)

提供以下行為:

KeyDown:按下某個鍵

KeyUp:釋放某個鍵

在 python selenium 的源碼當中,selenium/common/actions/key_input.py 里 KeyInput 類定義了按鈕輸入源類。

3、指針輸入源(pointer input source),提供以下行為:

PointerDown:按下鼠標鍵,或者觸屏或者觸屏筆觸屏

PointerUp:松開鼠標鍵,或者手離開屏幕,或者觸屏筆離開屏幕

PointerMove:移動到屏幕某個點

PointerCancel:刪除某個指針操作

在 python selenium 的源碼當中,selenium/common/actions/pointer_input.py 里 PointerInput 類定義了指針輸入源類。

4、在輸入源基礎(chǔ)上,定義了鍵盤操作類 KeyActions

在 python selenium 的源碼當中,selenium/common/actions/key_actions.py 里 KeyActions 類定義了鍵盤操作類。

5、在輸入源基礎(chǔ)上,定義了鼠標/觸屏操作 PointerActions 類:

在 python selenium 的源碼當中,selenium/common/actions/pointer_actions.py 里 PointerActions 類定義了鼠標/觸屏操作類。

匯總一下上面幾個類:

6、ActionBuilder 類

初始化方法:

輸入源設(shè)備列表,會放 2 個輸入源:鼠標輸入源、鍵盤輸入源。

有 2 個私有屬性:鍵盤操作對象(KeyActions 類實例化**)**,鼠標/觸屏操作對象(PointerActions 類實例化)

屬性:key_action,pointer_action

在 ActionChains 類當中,就是通過這 2 個屬性來調(diào)用鼠標和鍵盤的操作的。

添加新的輸入源:add_key_input,add_pointer_input

2、ActionChains 類

selenium 中的鼠標操作類,鼠標行為都是使用的 ActionBuilder 類。

初始化:

3、單點觸控 - ActionChains 類

直接使用 ActionChains 類里的,w3c_actions 去實現(xiàn)。

比如 appium 當中的 swipe 滑屏方法:

移動到某一個坐標點 → 按下 → 移動到另一個坐標點 → 釋放

4、多點觸控 - ActionChains 類

多點觸控,是個單點觸控操作同時發(fā)生,比如 2 個手指,同時在屏幕上進行滑動操作。

仍然是 ActionChains 類,不過需要在里面,添加新的單點觸控操作。

actions = ActionChains(driver) # 輸入源設(shè)備列表為空 actions.w3c_actions.devices = []# 添加一個新的輸入源到設(shè)備到中,輸入源類型為Touch new_input = actions.w3c_actions.add_pointer_input('touch', f'finger{finger}') # 輸入源的動作:移動到某個點,按下,移動到另外一點,釋放 new_input.create_pointer_move(x=start_x, y=start_y) new_input.create_pointer_down(MouseButton.LEFT) new_input.create_pause(duration / 1000) new_input.create_pointer_move(x=end_x, y=end_y) new_input.create_pointer_up(MouseButton.LEFT)# 以此類推,可以添加多個輸入源操作到設(shè)備當中。可以是鼠標操作,也可以是觸屏,按鍵等操作

比如,對百度地圖 app 進行放大操作的代碼如下:

from time import sleep from appium import webdriverfrom selenium.webdriver import ActionChains from selenium.webdriver.common.actions.mouse_button import MouseButton#我要在android7.1.2設(shè)備上,打開百度地圖app desired_caps = { "automationName":"UiAutomator2", "platformName":"Android", "platformVersion":"7.1.2", "deviceName":"HuaWei", "noReset":True, "appPackage":"com.baidu.BaiduMap", "appActivity":"com.baidu.baidumaps.WelcomeScreen", "systemPort": 8225, "newCommandTimeout": 1200 }#先連接appium server。傳遞指令。appium server連接地址 driver = webdriver.Remote('<http://127.0.0.1:4723/wd/hub>', desired_caps)sleep(20)#獲取設(shè)備的大小 - size size_dict = driver.get_window_size()# ==========放大地圖:從地圖中心分別向?qū)蔷€滑動放大 - 2個手指同時執(zhí)行滑動操作 ================== actions = ActionChains(driver) #輸入源設(shè)備列表為空 actions.w3c_actions.devices = []# ========== 第1個手指:從正中心向右上角滑動 ================== #添加一個新的輸入源到設(shè)備到中,輸入源類型為Touch,id為finger0 new_input = actions.w3c_actions.add_pointer_input('touch','finger0') #輸入源的動作:移動到某個點,按下,移動到另外一點,釋放 new_input.create_pointer_move(x=size_dict["width"] * 0.5, y=size_dict["height"] * 0.5) new_input.create_pointer_down(MouseButton.LEFT) new_input.create_pause(0.2) # 200ms new_input.create_pointer_move(x=size_dict["width"] * 0.9, y=size_dict["height"] * 0.1) new_input.create_pointer_up(MouseButton.LEFT)# ========== 第2個手指:從正中心向左下角滑動 ================== #添加一個新的輸入源到設(shè)備到中,輸入源類型為Touch。id為finger1 new_input = actions.w3c_actions.add_pointer_input('touch','finger1') #輸入源的動作:移動到某個點,按下,移動到另外一點,釋放 new_input.create_pointer_move(x=size_dict["width"] * 0.5, y=size_dict["height"] * 0.5) new_input.create_pointer_down(MouseButton.LEFT) new_input.create_pause(0.2) # 200ms new_input.create_pointer_move(x=size_dict["width"] * 0.1, y=size_dict["height"] * 0.9) new_input.create_pointer_up(MouseButton.LEFT)#執(zhí)行動作 actions.perform()


資源分享

下方這份完整的軟件測試視頻學(xué)習(xí)教程已經(jīng)上傳CSDN官方認證的二維碼,朋友們?nèi)绻枰梢宰孕忻赓M領(lǐng)取 【保證100%免費】

總結(jié)

以上是生活随笔為你收集整理的appium2.0+ 单点触控和多点触控新的解决方案的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。