Botium绑定完成后如何运行其他断言?

const bb = new BotiumBindings({ convodirs: ['/spec'] })
BotiumBindings.helper.mocha().setupMochaTestSuite({ bb })

// TODO: GET request to an external API.

最佳答案

向Botium添加自定义断言逻辑的推荐方法是向Botium添加自己的断言模块。您可以找到详细信息here,但总之:


创建一个文件MyCustomAsserter.js:


module.exports = class CustomAsserter {
  constructor (context, caps, globalArgs) {
    this.context = context
    this.caps = caps
    this.globalArgs = globalArgs
  }
  assertConvoStep ({convo, convoStep, args, isGlobal, botMsg}) {
    if (botMsg.message !== 'hugo') throw new Error('expected hugo')
    return Promise.resolve()
  }
}



在botium.json中注册


{
  "botium": {
    "Capabilities": {
      ...
      "ASSERTERS": [
        {
          "ref": "MY-ASSERTER-NAME",
          "src": "./MyCustomAsserter.js",
          "global": false,
          "args": {
            "my-arg-1": "something"
          }
        }
      ]
    }
  }
}




在convo文件中使用此断言器:


my-test-case

#me
hi

#bot
hi
MY-ASSERTER-NAME some-arg1|some-arg2

10-04 11:09