Botium绑定完成后运行其他声明代码

时间:2019-10-07 03:51:44

标签: javascript node.js mocha

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

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

// TODO: GET request to an external API.

1 个答案:

答案 0 :(得分:1)

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

  1. 创建文件 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()
  }
}
  1. botium.json
  2. 中注册
{
  "botium": {
    "Capabilities": {
      ...
      "ASSERTERS": [
        {
          "ref": "MY-ASSERTER-NAME",
          "src": "./MyCustomAsserter.js",
          "global": false,
          "args": {
            "my-arg-1": "something"
          }
        }
      ]
    }
  }
}

  1. 在convo文件中使用此断言器:
my-test-case

#me
hi

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