这是一个示例test.convo.text:
Test asserter
#me
Show my json
#bot
$json
MY-CUSTOM-ASSERTER $json
断言器选择“$json”字符串作为参数。
我希望机器人回复的 JSON 作为参数传递。
有没有一种方法可以像我们访问process.env
一样访问脚本变量?
最佳答案
编写断言器时,传递给断言器函数的参数之一是“botMsg”,它实际上包含聊天机器人响应(在 botMsg.messageText 中) - 所以我认为使用此 $json 执行此操作没有任何意义脚本变量。您可以在 Botium Wiki 中找到自定义断言器的详细参数列表。 .
您的自定义断言器可能如下所示:
module.exports = class CustomAsserter {
assertConvoStep ({args, scriptingMemory, botMsg}) {
// do whatever you want with botMsg and scriptingMemory
if (botMsg.messageText !== 'HUGO') return Promise.reject('Expected HUGO')
return Promise.resolve()
}
}
您可以使用 $func 将环境变量作为脚本变量访问
#me
add to my cart $func(process.env.BOTIUM_PRODUCT)
关于javascript - 将 Botium 脚本内存变量传递到断言器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58336284/