收藏
回答

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

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


回答关注问题邀请回答
收藏

3 个回答

  • RedHood
    RedHood
    2019-11-20

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

    2019-11-20
    有用
    回复
  • 悠'然
    悠'然
    2021-03-31

    请问这个问题解决了吗?我也遇到了同样的问题

    2021-03-31
    有用
    回复
  • lxl
    lxl
    2019-11-20

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

    2019-11-20
    有用
    回复
登录 后发表内容
问题标签