Webdriverio touchAction与touchPerform API未实现报错求助
Webdriverio touchAction/touchPerform 报错:unknown method: Not implemented
环境配置
- uiautomator2版本:2.35.0
- Appium版本:2.3.0
- Webdriverio版本:8.15.0
- Node版本:16.18.0
报错代码
1. touchAction API
browser.touchAction([ { action: "press", x: xStart, y: yStart }, { action: "wait", ms: speed }, { action: "moveTo", x: xFinish, y: yFinsh }, { action: "release" } ])
2. touchPerform API
browser.touchPerform([ { action: "press", options: { x: xStart, y: yStart } }, { action: "wait", options: { ms: speed } }, { action: "moveTo", options: { x: xFinish, y: yFinsh } }, { action: "release", options: {} } ])
错误栈
VError: a BeforeAll hook errored, process exiting: node_modules/test-package/dist/test-steps.js:66: Not implemented at Runtime.runTestRunHooks (/tmp/scratchTyFrlT.scratch/test-packageo45mGa/node_modules/test-package/node_modules/@cucumber/cucumber/lib/runtime/run_test_run_hooks.js:23:23) at runMicrotasks (<anonymous>) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async Runtime.start (/tmp/scratchTyFrlT.scratch/test-packageo45mGa/node_modules/test-package/node_modules/@cucumber/cucumber/lib/runtime/index.js:53:9) at async runCucumber (/tmp/scratchTyFrlT.scratch/test-packageo45mGa/node_modules/test-package/node_modules/@cucumber/cucumber/lib/api/run_cucumber.js:106:21) { jse_shortmsg: 'a BeforeAll hook errored, process exiting: node_modules/test-package/dist/test-steps.js:66', jse_cause: unknown method: Not implemented at getErrorFromResponseBody (file:///tmp/scratchTyFrlT.scratch/test-packageo45mGa/node_modules/test-package/node_modules/webdriver/build/utils.js:194:12) at NodeJSRequest._request (file:///tmp/scratchTyFrlT.scratch/test-packageo45mGa/node_modules/test-package/node_modules/webdriver/build/request/index.js:164:23) at runMicrotasks (<anonymous>) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async Browser.wrapCommandFn (file:///tmp/scratchTyFrlT.scratch/test-packageo45mGa/node_modules/test-package/node_modules/@wdio/utils/build/shim.js:72:29) at async Browser.wrapCommandFn (file:///tmp/scratchTyFrlT.scratch/test-packageo45mGa/node_modules/test-package/node_modules/@wdio/utils/build/shim.js:72:29), jse_info: {}, cause: [Function: ve_cause] }
解决方案
原因
Appium 2.x搭配uiautomator2 2.35.0时,旧的touchAction/touchPerform API已被移除,这些属于Appium 1.x的遗留接口,当前uiautomator2驱动不再支持,需改用W3C标准的Actions API。
替代实现代码
使用Webdriverio 8.x支持的Actions API实现滑动操作:
// 实现从(xStart,yStart)滑动到(xFinish,yFinsh)的触摸操作 const actions = await browser.action('pointer'); await actions .pointerMove({ x: xStart, y: yStart }) // 移动到起始点 .pointerDown({ button: 0 }) // 按下(模拟触摸按下) .pause(speed) // 等待指定时长 .pointerMove({ x: xFinish, y: yFinsh }) // 滑动到终点 .pointerUp({ button: 0 }) // 松开(模拟触摸抬起) .perform(); // 执行操作
其他注意事项
- 若必须使用旧API,可尝试回退uiautomator2驱动到2.34.0版本,但不推荐,因为旧版本可能存在兼容性或安全问题
- Webdriverio 8.x完全兼容W3C Actions API,这是当前移动端自动化触摸操作的标准方案,建议优先采用
内容的提问来源于stack exchange,提问作者Aduait Pokhriyal
相关产品推荐
相关产品推荐

