小程序自动化测试该如何模拟触摸事件?
发布于 5 年前 作者 ping05 4517 次浏览 来自 官方Issues

在小程序自动化测试的文档中(https://developers.weixin.qq.com/miniprogram/dev/devtools/auto/element.html)提到了用element.touchstart, element.touchmove and element.touchend来模拟滑动操作,不过我在写自动化用例的时候发现它并不能工作。具体测试代码如下:

it(' swipe action'async () => {

const swipeActions = await page.$$('swipe-action')

const swipeAction = swipeActions[0]

console.log(offsetawait swipeAction.wxml())

await swipeAction.touchstart({

touches: [

{

identifier: 0,

pageX: 350,

pageY: 97,

},

],

changedTouches: [

{

identifier: 0,

pageX: 350,

pageY: 97,

},

],

})


await swipeAction.touchmove({

touches: [

{

identifier: 0,

pageX: 306,

pageY: 97,

},

],

changedTouches: [

{

identifier: 0,

pageX: 306,

pageY: 97,

},

],

})

await swipeAction.touchend({

touches: [],

changedTouches: [

{

identifier: 0,

pageX: 139,

pageY: 97,

},

],

})

await page.waitFor(500)

})

请问该如何模拟滑动事件?这上面的pageX和pageY是我抓取手动操作时获取的数据。

2 回复

bindtouchstart 对应的处理函数没触发吗?

我打印了一下log,这个处理函数是触发了的。包括bindtouchstart, bindtouchmove 和bindtouchend.

回到顶部