跳至主要內容

touchAction

棄用警告

touchAction 命令已棄用,並將在未來版本中移除。 我們建議改用具有指標類型 touchaction 命令,例如:

await browser.action('pointer', {
parameters: { pointerType: 'touch' }
})

觸控動作 API 提供了所有可以在 Appium 中自動化的手勢的基礎。 它目前僅適用於原生應用程式,不能用於與網頁應用程式互動。 它的核心是能夠將個別動作串聯在一起,然後將這些動作應用於裝置上應用程式中的元素。 可以使用的基本動作有:

  • press (傳遞元素或 (x, y) 或兩者)
  • longPress (傳遞元素或 (x, y) 或兩者)
  • tap (傳遞元素或 (x, y) 或兩者)
  • moveTo (傳遞絕對 x, y 座標)
  • wait (傳遞 ms(以毫秒為單位))
  • release (無參數)
用法
browser.touchAction(action)
參數
名稱類型詳細資訊
actionTouchActions要執行的動作
範例
touchAction.js
it('should do a touch gesture', async () => {
const screen = await $('//UITextbox');

// simple touch action on element
await browser.touchAction({
action: 'tap',
element: screen
});

// simple touch action x y variables
// tap location is 30px right and 20px down relative from the viewport
await browser.touchAction({
action: 'tap',
x: 30,
y:20
})

// simple touch action x y variables
// tap location is 30px right and 20px down relative from the center of the element
await browser.touchAction({
action: 'tap',
x: 30,
y:20,
element: screen
})

// multi action on an element
// drag&drop from position 200x200 down 100px on the screen
await browser.touchAction([
{ action: 'press', x: 200, y: 200 },
{ action: 'moveTo', x: 200, y: 300 },
'release'
])
});

歡迎! 我能幫您什麼嗎?

WebdriverIO AI Copilot