html52.com
我爱小程序-开发者交流社区

小程序自动化测试该如何模拟触摸事件?

在小程序自动化测试的文档中(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是我抓取手动操作时获取的数据。


网友回复

红帽:

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

lxl:

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

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付