收藏
回答

小程序自动化测试,调用自定义组件中的方法出错?

根据https://developers.weixin.qq.com/miniprogram/dev/devtools/auto/element.html中的文档说明,可以通过element.callMethod()来调用自定义组件中的方法。

不过在写测试用例的时候,发现调用不了自定义组件的方法。

const fapiaoList = await page.$('fapiao-list')

await fapiaoList.callMethod('connectWebSocketIfNeed')

程序报错。

component.connectWebSocketIfNeed not exists

      at Transport.Connection.onMessage (node_modules/miniprogram-automator/out/Connection.js:1:957)

      at WebSocket.<anonymous> (node_modules/miniprogram-automator/out/Transport.js:1:246)

      at WebSocket.onMessage (node_modules/ws/lib/event-target.js:120:16)

      at Receiver.receiverOnMessage (node_modules/ws/lib/websocket.js:789:20)

      at Receiver.dataMessage (node_modules/ws/lib/receiver.js:422:14)

      at Receiver.getData (node_modules/ws/lib/receiver.js:352:17)

      at Receiver.startLoop (node_modules/ws/lib/receiver.js:138:22)

      at Receiver._write (node_modules/ws/lib/receiver.js:74:10)

      at Socket.socketOnData (node_modules/ws/lib/websocket.js:864:35)


connectWebSocketIfNeed 这个方法在代码中是有的,在小程序中也可以运行,请帮忙看看,多谢!


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

2 个回答

  • RedHood
    RedHood
    2019-11-29

    我这边试是可以的,可能是某些情况才失败。能否给个可以复现的代码片段?

    2019-11-29
    有用
    回复 2
    • lxl
      lxl
      2019-12-02
      我后来发现,在wxml文件中绑定的方法是可以通过这个方法调用的。比如
                 
                     
                          {{item.$original.text}}
                     

                 

             

      这里面的"handleClick"是可以调用的。


      非常感谢。
      2019-12-02
      回复
    • Dragon
      Dragon
      2021-07-30
      你好,我现在在项目中用到了uniapp,也出现了这个问题,如何解决呢
      2021-07-30
      回复
  • lxl
    lxl
    2019-12-02

     <block wx:if="{{anonymousState__temp7}}">

                <swipe-action-options compid="{{$compid__55}}">

                    <view wx:key="key" style="{{item.$loopState__temp4}}" bindtap="handleClick" class="{{item.$loopState__temp6}}" wx:for="{{loopArray8}}" wx:for-item="item" wx:for-index="key" data-e-tap-so="this" data-e-tap-a-a="{{item.$original}}" data-e-tap-a-b="{{key}}">

                        <at-icon compid="{{item.$compid__54}}"></at-icon><text class="option__text">{{item.$original.text}}</text>

                    </view>

                </swipe-action-options>

            </block>

    贴上去是代码看不见,重新贴一次。。。

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