codeforequity-at / botium-core

The Selenium for Chatbots - Bots Testing Bots
https://www.botium.ai
MIT License
229 stars 64 forks source link

SimpleREST ContainerMode not working with SIMPLEREST_HEADERS_TEMPLATE #170

Closed staticdev closed 5 years ago

staticdev commented 5 years ago

Hello,

After many hours testing, I think it may be a bug: botium-cli --version: 0.0.38 node --version: v10.15.0

I have a simple bot (bot.py) that only answers the same string "Adeus, obrigado pelo contato =)" for POST requests passing the parameters user_id and message:

from flask import Flask, request, jsonify

def create_app(test_config=None):
    app = Flask(__name__)
    app.config['JSON_AS_ASCII'] = False # retrieve UTF-8 messages
    app.config['DEBUG'] = True

     @app.route('/reply', methods=['POST'])
     def reply():
         params = request.json
         if not params:
             return jsonify({
                 "status": "error",
                 "error": "Request must be of the application/json type!",
             })

         user_id = params.get("user_id")
         message  = params.get("message")

         # Make sure the required params are present.
         if not user_id or not message:
             return jsonify({
                 "status": "error",
                 "error": "user_id and message are required keys",
         })

         reply = "Adeus, obrigado pelo contato =)"

         # Send the response.
         return jsonify({
             "status": "ok",
             "reply": reply
         })

     return app

I can test it with a simple curl:

curl -X POST   http://localhost:5002/reply   -H 'content-type: application/json'   -d '{
    "message": "tchau",
    "user_id": "dummy123"
}'

Response:

{
  "reply": "Adeus, obrigado pelo contato =)", 
  "status": "ok"
}

I've made a simple convo file (despedida.convo.txt):

#me
tchau

#bot
Adeus, obrigado pelo contato =)

I've also made a simple config to match the curl (botium.json):

{
  "botium": {
    "Capabilities": {
      "PROJECTNAME": "First Test",
      "CONTAINERMODE": "simplerest",
      "SIMPLEREST_URL": "http://localhost:5002/reply",
      "SIMPLEREST_METHOD": "POST",
      "SIMPLEREST_HEADERS_TEMPLATE": { "content-type": "application/json" },
      "SIMPLEREST_BODY_TEMPLATE": { "message": "{{msg.messageText}}", "user_id": "{{context.conversation_id}}" },
      "SIMPLEREST_RESPONSE_JSONPATH": "$.reply.*"
    },
    "Sources": {},
    "Envs": {}
  }
}

But when I do the botium-cli run --verbose, I see my application returns an error that suggests SIMPLEREST_HEADERS_TEMPLATE is being ignored:

botium-SimpleRestContainer got response body: "{\n \"error\": \"Request must be of the application/json type!\", \n \"status\": \"error\"\n}\n" +32ms

And the normal outputs this:

  Botium Test-Suite
    1) convos/despedida.convo.txt

  0 passing (10s)
  1 failing

  1) Botium Test-Suite
       convos/despedida.convo.txt:
     AssertionError: convos/despedida.convo.txt/Line 5: bot says nothing
      at ScriptingProvider.compiler.scriptingEvents.fail (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/src/run/index.js:49:12)
      at scriptingEvents.onBotStart.then.then (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:179:40)

It seems to timeout in 10 seconds everytime, even though the application responds instantly to the curl command. I also tried to change the SIMPLEREST_HEADERS_TEMPLATE as in issue #162: "SIMPLEREST_HEADERS_TEMPLATE": "{ \"Content-Type\": \"application/json\"}"

But then I get the instant error:

  Botium Test-Suite
    1) convos/despedida.convo.txt

  0 passing (118ms)
  1 failing

  1) Botium Test-Suite
       convos/despedida.convo.txt:
     Error: convos/despedida.convo.txt/Line 4: error sending to bot { AssertionError: Error: convos/despedida.convo.txt/Line 4: error sending to bot Error: composing headers from SIMPLEREST_HEADERS_TEMPLATE failed (TypeError: Invalid template! Template should be a "string" but "object" was given as the first argument for mustache#render(template, view, partials)
    at Object.render (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/mustache/mustache.js:598:13)
    at SimpleRestContainer._buildRequest (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:270:54)
    at Promise (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:145:35)
    at new Promise (<anonymous>)
    at SimpleRestContainer._doRequest (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:144:12)
    at SimpleRestContainer.UserSays (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:101:17)
    at scriptingEvents.onMeStart.then.then (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:150:32))
    at SimpleRestContainer._buildRequest (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:272:15)
    at Promise (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:145:35)
    at new Promise (<anonymous>)
    at SimpleRestContainer._doRequest (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:144:12)
    at SimpleRestContainer.UserSays (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:101:17)
    at scriptingEvents.onMeStart.then.then (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:150:32)
    at ScriptingProvider.compiler.scriptingEvents.fail (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/src/run/index.js:49:12)
    at scriptingEvents.onMeStart.then.then.then.then.catch (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:159:38)
  message:
   Error: convos/despedida.convo.txt/Line 4: error sending to bot Error: composing headers from SIMPLEREST_HEADERS_TEMPLATE failed (TypeError: Invalid template! Template should be a "string" but "object" was given as the first argument for mustache#render(template, view, partials)
       at Object.render (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/mustache/mustache.js:598:13)
       at SimpleRestContainer._buildRequest (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:270:54)
       at Promise (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:145:35)
       at new Promise (<anonymous>)
       at SimpleRestContainer._doRequest (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:144:12)
       at SimpleRestContainer.UserSays (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:101:17)
       at scriptingEvents.onMeStart.then.then (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:150:32))
       at SimpleRestContainer._buildRequest (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:272:15)
       at Promise (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:145:35)
       at new Promise (<anonymous>)
       at SimpleRestContainer._doRequest (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:144:12)
       at SimpleRestContainer.UserSays (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:101:17)
       at scriptingEvents.onMeStart.then.then (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:150:32)
       at scriptingEvents.onMeStart.then.then.then.then.catch (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:159:43),
  showDiff: false,
  actual: null,
  expected: null,
  operator: undefined }
      at scriptingEvents.onMeStart.then.then.then.then.catch (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:163:33)
codeforequity-at commented 5 years ago

please replace $.reply.* with $.reply and try again

Am Do., 27. Dez. 2018, 06:04 hat staticdev notifications@github.com geschrieben:

Hello,

After many hours testing, I think it may be a bug: botium-cli --version: 0.0.38 node --version: v10.15.0

I have a bot that only answers the same string "Adeus, obrigado pelo contato =)" for POST requests passing the parameters user_id and message:

from flask import Flask, request, jsonify ...

@app.route('/reply', methods=['POST'])
def reply():
    params = request.json
    if not params:
        return jsonify({
            "status": "error",
            "error": "Request must be of the application/json type!",
        })

    user_id = params.get("user_id")
    message  = params.get("message")

    # Make sure the required params are present.
    if not user_id or not message:
        return jsonify({
            "status": "error",
            "error": "user_id and message are required keys",
    })

    #reply = text_message(user_id, message)
    reply = "Adeus, obrigado pelo contato =)"

    # Send the response.
    return jsonify({
        "status": "ok",
        "reply": reply
    })

return app

I can test it with a simple curl:

curl -X POST http://localhost:5002/reply -H 'content-type: application/json; charset=utf-8' -d '{ "message": "tchau", "user_id": "dummy123" }'

Response:

{ "reply": "Adeus, obrigado pelo contato =)", "status": "ok" }

I've made a simple convo file (despedida.convo.txt):

me

tchau

bot

Adeus, obrigado pelo contato =)

I've also made a simple config to match the curl (botium.json):

{ "botium": { "Capabilities": { "PROJECTNAME": "First Test", "CONTAINERMODE": "simplerest", "SIMPLEREST_URL": "http://localhost:5002/reply", "SIMPLEREST_METHOD": "POST", "SIMPLEREST_HEADERS_TEMPLATE": { "content-type": "application/json; charset=utf-8" }, "SIMPLEREST_BODY_TEMPLATE": { "message": "{{msg.messageText}}", "user_id": "{{context.conversation_id}}" }, "SIMPLEREST_RESPONSE_JSONPATH": "$.reply.*" }, "Sources": {}, "Envs": {} } }

But when I do the botium-cli run, my application doesn't even get a request on the log and outputs this:

Botium Test-Suite 1) convos/despedida.convo.txt

0 passing (10s) 1 failing

1) Botium Test-Suite convos/despedida.convo.txt: AssertionError: convos/despedida.convo.txt/Line 5: bot says nothing at ScriptingProvider.compiler.scriptingEvents.fail (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/src/run/index.js:49:12) at scriptingEvents.onBotStart.then.then (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:179:40)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/codeforequity-at/botium-core/issues/170, or mute the thread https://github.com/notifications/unsubscribe-auth/AZEdT_MZy8GpMYXNk2Me6OtQRJPBusl9ks5u9FTWgaJpZM4ZiVKp .

staticdev commented 5 years ago

@codeforequity-at changing the SIMPLEREST_RESPONSE_JSONPATH doesn't have any effect since the request doesn't respond because of the error:

botium-SimpleRestContainer got response body: "{\n \"error\": \"Request must be of the application/json type!\", \n \"status\": \"error\"\n}\n" +32ms

To solve this, the header need to have 'content-type: application/json'. The same occurs if I make a curl without this header:

curl -X POST   http://localhost:5002/reply -d '{
    "message": "tchau",
    "user_id": "dummy123"
}'

I get the response:

{
  "error": "Request must be of the application/json type!", 
  "status": "error"
}

I have also noticed from the botium-cli run --verbose, that SIMPLEREST_HEADERS_TEMPLATE is not being added in botium-BotDriver:

  botium-cli Using Botium configuration file ./botium.json +0ms
  botium-cli-run command options: { _: [ 'run' ],
  botium-cli-run   help: false,
  botium-cli-run   h: false,
  botium-cli-run   version: false,
  botium-cli-run   V: false,
  botium-cli-run   verbose: true,
  botium-cli-run   v: true,
  botium-cli-run   convos: [ '.' ],
  botium-cli-run   C: [ '.' ],
  botium-cli-run   config: './botium.json',
  botium-cli-run   c: './botium.json',
  botium-cli-run   output: 'spec',
  botium-cli-run   testsuitename: 'Botium Test-Suite',
  botium-cli-run   n: 'Botium Test-Suite',
  botium-cli-run   expandutterances: false,
  botium-cli-run   timeout: 60,
  botium-cli-run   '$0': '/home/01677387637/.npm-global/bin/botium-cli',
  botium-cli-run   filter: undefined,
  botium-cli-run   'reporter-options': undefined } +0ms
  botium-cli-run Mocha Reporter "spec", options: undefined +0ms
  botium-BotDriver Loaded Botium configuration file ./botium.json +0ms
  botium-BotDriver Loaded Botium configuration file ./botium.json +0ms
  botium-BotDriver Changed capability CONFIG to "./botium.json" using environment variables. +0ms
  botium-BotDriver BuildCompiler: Capabilites: { PROJECTNAME: 'First Test',
  botium-BotDriver   TEMPDIR: 'botiumwork',
  botium-BotDriver   CLEANUPTEMPDIR: true,
  botium-BotDriver   WAITFORBOTTIMEOUT: 10000,
  botium-BotDriver   SIMULATE_WRITING_SPEED: false,
  botium-BotDriver   DOCKERCOMPOSEPATH: 'docker-compose',
  botium-BotDriver   DOCKERMACHINEPATH: 'docker-machine',
  botium-BotDriver   DOCKERMACHINE: false,
  botium-BotDriver   DOCKERIMAGE: 'node:boron',
  botium-BotDriver   DOCKERUNIQUECONTAINERNAMES: false,
  botium-BotDriver   DOCKERSYSLOGPORT_RANGE: '47100-47299',
  botium-BotDriver   BOT_HEALTH_STATUS: 200,
  botium-BotDriver   SLACK_PUBLISHPORT_RANGE: '46100-46299',
  botium-BotDriver   FACEBOOK_PUBLISHPORT_RANGE: '46300-46499',
  botium-BotDriver   FACEBOOK_SEND_DELIVERY_CONFIRMATION: true,
  botium-BotDriver   BOTFRAMEWORK_PUBLISHPORT_RANGE: '46500-46699',
  botium-BotDriver   BOTFRAMEWORK_WEBHOOK_PORT: 3978,
  botium-BotDriver   BOTFRAMEWORK_WEBHOOK_PATH: 'api/messages',
  botium-BotDriver   BOTFRAMEWORK_CHANNEL_ID: 'facebook',
  botium-BotDriver   SIMPLEREST_METHOD: 'POST',
  botium-BotDriver   WEBSPEECH_SERVER_PORT: 46050,
  botium-BotDriver   WEBSPEECH_LANGUAGE: 'en-US',
  botium-BotDriver   WEBSPEECH_CLOSEBROWSER: true,
  botium-BotDriver   SCRIPTING_TXT_EOL: '\n',
  botium-BotDriver   SCRIPTING_XLSX_EOL_SPLIT: '\r',
  botium-BotDriver   SCRIPTING_XLSX_EOL_WRITE: '\r\n',
  botium-BotDriver   SCRIPTING_XLSX_STARTROW: 1,
  botium-BotDriver   SCRIPTING_XLSX_STARTCOL: 'A',
  botium-BotDriver   SCRIPTING_NORMALIZE_TEXT: true,
  botium-BotDriver   SCRIPTING_ENABLE_MEMORY: false,
  botium-BotDriver   SCRIPTING_MATCHING_MODE: 'includeLowerCase',
  botium-BotDriver   SCRIPTING_UTTEXPANSION_MODE: 'all',
  botium-BotDriver   SCRIPTING_UTTEXPANSION_RANDOM_COUNT: 1,
  botium-BotDriver   SCRIPTING_UTTEXPANSION_INCOMPREHENSION: 'INCOMPREHENSION',
  botium-BotDriver   ASSERTERS: [],
  botium-BotDriver   LOGIC_HOOKS: [],
  botium-BotDriver   CONTAINERMODE: 'simplerest',
  botium-BotDriver   SIMPLEREST_URL: 'http://localhost:5002/reply',
  botium-BotDriver   SIMPLEREST_RESPONSE_JSONPATH: '$.reply',
  botium-BotDriver   CONFIG: './botium.json' } +1ms
  botium-ScriptingProvider Using matching mode: includeLowerCase +0ms
  botium-asserterUtils Loaded Default asserter - [ 'BUTTONS', 'MEDIA' ] +0ms
  botium-asserterUtils Loaded Default logic hook - [ 'PAUSE' ] +0ms
  botium-ScriptingProvider ReadConvosFromDirectory(.) found filenames: convos/despedida.convo.txt +5ms
  botium-ScriptingProvider ReadConvosFromDirectory(.) found convos:
  botium-ScriptingProvider  1 convos/despedida.convo.txt ({ filename: 'convos/despedida.convo.txt' }): Line 4: #me - tchau   | Line 5: #bot - Adeus, obrigado pelo contato =)   +3ms
  botium-ScriptingProvider ReadConvosFromDirectory(.) found utterances:
  botium-ScriptingProvider   +0ms
  botium-cli-run ready reading convos (1), expanding convos ... +267ms
  botium-ScriptingProvider ExpandConvos - Using utterances expansion mode: all +0ms
  botium-cli-run ready expanding convos and utterances, number of test cases: (1). +1ms
  botium-cli-run adding test case convos/despedida.convo.txt (from: { filename: 'convos/despedida.convo.txt' }) +1ms
  botium-BotDriver Build - Capabilites: { PROJECTNAME: 'First Test',
  botium-BotDriver   TEMPDIR: 'botiumwork',
  botium-BotDriver   CLEANUPTEMPDIR: true,
  botium-BotDriver   WAITFORBOTTIMEOUT: 10000,
  botium-BotDriver   SIMULATE_WRITING_SPEED: false,
  botium-BotDriver   DOCKERCOMPOSEPATH: 'docker-compose',
  botium-BotDriver   DOCKERMACHINEPATH: 'docker-machine',
  botium-BotDriver   DOCKERMACHINE: false,
  botium-BotDriver   DOCKERIMAGE: 'node:boron',
  botium-BotDriver   DOCKERUNIQUECONTAINERNAMES: false,
  botium-BotDriver   DOCKERSYSLOGPORT_RANGE: '47100-47299',
  botium-BotDriver   BOT_HEALTH_STATUS: 200,
  botium-BotDriver   SLACK_PUBLISHPORT_RANGE: '46100-46299',
  botium-BotDriver   FACEBOOK_PUBLISHPORT_RANGE: '46300-46499',
  botium-BotDriver   FACEBOOK_SEND_DELIVERY_CONFIRMATION: true,
  botium-BotDriver   BOTFRAMEWORK_PUBLISHPORT_RANGE: '46500-46699',
  botium-BotDriver   BOTFRAMEWORK_WEBHOOK_PORT: 3978,
  botium-BotDriver   BOTFRAMEWORK_WEBHOOK_PATH: 'api/messages',
  botium-BotDriver   BOTFRAMEWORK_CHANNEL_ID: 'facebook',
  botium-BotDriver   SIMPLEREST_METHOD: 'POST',
  botium-BotDriver   WEBSPEECH_SERVER_PORT: 46050,
  botium-BotDriver   WEBSPEECH_LANGUAGE: 'en-US',
  botium-BotDriver   WEBSPEECH_CLOSEBROWSER: true,
  botium-BotDriver   SCRIPTING_TXT_EOL: '\n',
  botium-BotDriver   SCRIPTING_XLSX_EOL_SPLIT: '\r',
  botium-BotDriver   SCRIPTING_XLSX_EOL_WRITE: '\r\n',
  botium-BotDriver   SCRIPTING_XLSX_STARTROW: 1,
  botium-BotDriver   SCRIPTING_XLSX_STARTCOL: 'A',
  botium-BotDriver   SCRIPTING_NORMALIZE_TEXT: true,
  botium-BotDriver   SCRIPTING_ENABLE_MEMORY: false,
  botium-BotDriver   SCRIPTING_MATCHING_MODE: 'includeLowerCase',
  botium-BotDriver   SCRIPTING_UTTEXPANSION_MODE: 'all',
  botium-BotDriver   SCRIPTING_UTTEXPANSION_RANDOM_COUNT: 1,
  botium-BotDriver   SCRIPTING_UTTEXPANSION_INCOMPREHENSION: 'INCOMPREHENSION',
  botium-BotDriver   ASSERTERS: [],
  botium-BotDriver   LOGIC_HOOKS: [],
  botium-BotDriver   CONTAINERMODE: 'simplerest',
  botium-BotDriver   SIMPLEREST_URL: 'http://localhost:5002/reply',
  botium-BotDriver   SIMPLEREST_RESPONSE_JSONPATH: '$.reply',
  botium-BotDriver   CONFIG: './botium.json' } +275ms
  botium-BotDriver Build - Sources : { LOCALPATH: '.',
  botium-BotDriver   GITPATH: 'git',
  botium-BotDriver   GITBRANCH: 'master',
  botium-BotDriver   GITDIR: '.' } +0ms
  botium-BotDriver Build - Envs : { IS_BOTIUM_CONTAINER: true } +0ms
  botium-cli-run running testcase convos/despedida.convo.txt +54ms
  botium-Convo convos/despedida.convo.txt/Line 4: user says {
  botium-Convo   "sender": "me",
  botium-Convo   "channel": null,
  botium-Convo   "messageText": "tchau",
  botium-Convo   "stepTag": "Line 4",
  botium-Convo   "not": false,
  botium-Convo   "asserters": [],
  botium-Convo   "logicHooks": []
  botium-Convo } +0ms
  botium-SimpleRestContainer constructed requestOptions {
  botium-SimpleRestContainer   "uri": "http://localhost:5002/reply",
  botium-SimpleRestContainer   "method": "POST"
  botium-SimpleRestContainer } +0ms
  botium-SimpleRestContainer got response body: "{\n  \"error\": \"Request must be of the application/json type!\", \n  \"status\": \"error\"\n}\n" +16ms
  botium-SimpleRestContainer eval json path $.reply +2ms
  botium-SimpleRestContainer found response texts: [] +4ms
  botium-Convo convos/despedida.convo.txt wait for bot null +25ms
codeforequity-at commented 5 years ago

i should have read the provided log in detail. you have to quote the SIMPLEREST_BODY_TEMPLATE and SIMPLEREST_HEADERS_TEMPLATE capabilities to be handled as json string, not as json object - do you know what i mean ? there is a pull request on the way which will make your current configuration work, but until then you have to quote it.

codeforequity-at commented 5 years ago

ah one moment, what version of the botium cli are you using ?

staticdev commented 5 years ago

@codeforequity-at I am using version 0.0.38 of botium-cli. I tried to configure the JSON as in https://github.com/codeforequity-at/botium-core/wiki/operation-mode-simplerest. But ok, I've also tried this quoted SIMPLEREST_BODY_TEMPLATE and SIMPLEREST_HEADERS_TEMPLATE configuration:

{
  "botium": {
    "Capabilities": {
      "PROJECTNAME": "First Test",
      "CONTAINERMODE": "simplerest",
      "SIMPLEREST_URL": "http://localhost:5000/reply",
      "SIMPLEREST_METHOD": "POST",
      "SIMPLEREST_HEADERS_TEMPLATE": "{ \"content-type\": \"application/json\" }",
      "SIMPLEREST_BODY_TEMPLATE": "{ \"message\": \"{{msg.messageText}}\", \"user_id\": \"{{context.conversation_id}}\" }",
      "SIMPLEREST_RESPONSE_JSONPATH": "$.reply"
    },
    "Sources": {},
    "Envs": {}
  }
}

But this returns the error:

  1) Botium Test-Suite
       convos/despedida.convo.txt:
     Error: convos/despedida.convo.txt/Line 4: error sending to bot { AssertionError: Error: convos/despedida.convo.txt/Line 4: error sending to bot Error: composing headers from SIMPLEREST_HEADERS_TEMPLATE failed (TypeError: Invalid template! Template should be a "string" but "object" was given as the first argument for mustache#render(template, view, partials)
    at Object.render (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/mustache/mustache.js:598:13)
    at SimpleRestContainer._buildRequest (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:270:54)
    at Promise (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:145:35)
    at new Promise (<anonymous>)
    at SimpleRestContainer._doRequest (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:144:12)
    at SimpleRestContainer.UserSays (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:101:17)
    at scriptingEvents.onMeStart.then.then (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:150:32))
    at SimpleRestContainer._buildRequest (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:272:15)
    at Promise (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:145:35)
    at new Promise (<anonymous>)
    at SimpleRestContainer._doRequest (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:144:12)
    at SimpleRestContainer.UserSays (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:101:17)
    at scriptingEvents.onMeStart.then.then (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:150:32)
    at ScriptingProvider.compiler.scriptingEvents.fail (/home/01677387637/.npm-global/lib/node_modules/botium-cli/src/run/index.js:49:12)
    at scriptingEvents.onMeStart.then.then.then.then.catch (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:159:38)
  message:
   Error: convos/despedida.convo.txt/Line 4: error sending to bot Error: composing headers from SIMPLEREST_HEADERS_TEMPLATE failed (TypeError: Invalid template! Template should be a "string" but "object" was given as the first argument for mustache#render(template, view, partials)
       at Object.render (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/mustache/mustache.js:598:13)
       at SimpleRestContainer._buildRequest (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:270:54)
       at Promise (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:145:35)
       at new Promise (<anonymous>)
       at SimpleRestContainer._doRequest (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:144:12)
       at SimpleRestContainer.UserSays (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:101:17)
       at scriptingEvents.onMeStart.then.then (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:150:32))
       at SimpleRestContainer._buildRequest (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:272:15)
       at Promise (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:145:35)
       at new Promise (<anonymous>)
       at SimpleRestContainer._doRequest (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:144:12)
       at SimpleRestContainer.UserSays (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/containers/SimpleRestContainer.js:101:17)
       at scriptingEvents.onMeStart.then.then (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:150:32)
       at scriptingEvents.onMeStart.then.then.then.then.catch (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:159:43),
  showDiff: false,
  actual: null,
  expected: null,
  operator: undefined }
      at scriptingEvents.onMeStart.then.then.then.then.catch (/home/01677387637/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:163:33)
codeforequity-at commented 5 years ago

sorry please wait a few hours until i publish a new build. the botium cli is not using the latest botium core build. the failure is not on your side, you did everything correct.

staticdev commented 5 years ago

Nice! =)

codeforequity-at commented 5 years ago

So the latest botium-cli 0.0.39 includes the latest botium-core version. please tell me if it works for you now (the response json path has to be corrected as well in your config, otherwise you won't receive any answer again).

staticdev commented 5 years ago

Thanks, I will make some tests ASAP.

staticdev commented 5 years ago

I've updated the botium-cli to 0.0.39, now the header is correct but there is a problem with the SIMPLEREST_BODY_TEMPLATE. The body is also getting the content-type, instead of the configured body template.

My botium.json:

{
  "botium": {
    "Capabilities": {
      "PROJECTNAME": "First Test",
      "CONTAINERMODE": "simplerest",
      "SIMPLEREST_URL": "http://localhost:5000/reply",
      "SIMPLEREST_METHOD": "POST",
      "SIMPLEREST_HEADERS_TEMPLATE": "{ \"content-type\": \"application/json\" }",
      "SIMPLEREST_BODY_TEMPLATE": "{ \"message\": \"{{msg.messageText}}\", \"user_id\": \"{{context.conversation_id}}\" }",
      "SIMPLEREST_RESPONSE_JSONPATH": "$.reply"
    },
    "Sources": {},
    "Envs": {}
  }
}

The new output with verbose:

botium-BotDriver CONTAINERMODE: 'simplerest',
botium-BotDriver SIMPLEREST_URL: 'http://localhost:5002/reply',
botium-BotDriver SIMPLEREST_HEADERS_TEMPLATE: { 'content-type': 'application/json' },
botium-BotDriver SIMPLEREST_BODY_TEMPLATE:
botium-BotDriver { message: '{{msg.messageText}}',
botium-BotDriver user_id: '{{context.conversation_id}}' },
botium-BotDriver SIMPLEREST_RESPONSE_JSONPATH: '$.reply',
botium-BotDriver CONFIG: './botium.json' } +272ms
botium-BotDriver Build - Sources : { LOCALPATH: '.',
botium-BotDriver GITPATH: 'git',
botium-BotDriver GITBRANCH: 'master',
botium-BotDriver GITDIR: '.' } +1ms
botium-BotDriver Build - Envs : { IS_BOTIUM_CONTAINER: true } +0ms
botium-cli-run running testcase convos/despedida.convo.txt +53ms
botium-Convo convos/despedida.convo.txt/Line 4: user says {
botium-Convo "sender": "me",
botium-Convo "channel": null,
botium-Convo "messageText": "tchau",
botium-Convo "stepTag": "Line 4",
botium-Convo "not": false,
botium-Convo "asserters": [],
botium-Convo "logicHooks": []
botium-Convo } +0ms
botium-SimpleRestContainer constructed requestOptions {
botium-SimpleRestContainer "uri": "http://localhost:5002/reply",
botium-SimpleRestContainer "method": "POST",
botium-SimpleRestContainer "headers": {
botium-SimpleRestContainer "content-type": "application/json"
botium-SimpleRestContainer },
botium-SimpleRestContainer "body": {
botium-SimpleRestContainer "content-type": "application/json"
botium-SimpleRestContainer },
botium-SimpleRestContainer "json": true
botium-SimpleRestContainer } +0ms
botium-SimpleRestContainer got response body: {
botium-SimpleRestContainer "error": "user_id and message are required keys",
botium-SimpleRestContainer "status": "error"
botium-SimpleRestContainer } +17ms
botium-SimpleRestContainer eval json path $.reply +1ms
botium-SimpleRestContainer found response texts: [] +2ms
botium-Convo convos/despedida.convo.txt wait for bot null +23ms
botium-BaseContainer WaitBotSays error Error: Queue.pop timeout after 10000
botium-BaseContainer at timeoutRequest (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/helpers/Queue.js:46:18)
botium-BaseContainer at Timeout.timeoutCallback [as _onTimeout] (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/async/dist/async.js:4936:13)
botium-BaseContainer at ontimeout (timers.js:436:11)
botium-BaseContainer at tryOnTimeout (timers.js:300:5)
botium-BaseContainer at listOnTimeout (timers.js:263:5)
botium-BaseContainer at Timer.processTimers (timers.js:223:10) +0ms
botium-Convo convos/despedida.convo.txt: bot says undefined +10s
botium-Convo Error: convos/despedida.convo.txt/Line 5: bot says nothing
botium-Convo at scriptingEvents.onBotStart.then.then (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:244:33) +1ms
botium-cli-run convos/despedida.convo.txt failed: { TranscriptError: Error: convos/despedida.convo.txt/Line 5: bot says nothing
botium-cli-run at async.waterfall (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:159:25)
botium-cli-run at /home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/async/dist/async.js:473:16
botium-cli-run at next (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/async/dist/async.js:5329:29)
botium-cli-run at /home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/async/dist/async.js:969:16
botium-cli-run at runConversation (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:143:15)
botium-cli-run at async.mapSeries (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:314:9)
botium-cli-run at /home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/async/dist/async.js:1140:9
botium-cli-run at /home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/async/dist/async.js:473:16
botium-cli-run at iterateeCallback (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/async/dist/async.js:988:17)
botium-cli-run at /home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/async/dist/async.js:969:16
botium-cli-run name: 'TranscriptError',
botium-cli-run transcript:
botium-cli-run Transcript {
botium-cli-run steps: [ [TranscriptStep], [TranscriptStep] ],
botium-cli-run scriptingMemory: {},
botium-cli-run convoBegin: 2018-12-27T19:38:55.074Z,
botium-cli-run convoEnd: 2018-12-27T19:39:05.103Z,
botium-cli-run err:
botium-cli-run Error: convos/despedida.convo.txt/Line 5: bot says nothing
botium-cli-run at scriptingEvents.onBotStart.then.then (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:244:33) } } +10s
1) convos/despedida.convo.txt
botium-BaseContainer Cleanup rimrafing temp dir /home/thiagoc/workspace/botium/botiumwork/First-Test-20181227-173855-AnPhL +10ms

0 passing (10s)
1 failing

1) Botium Test-Suite
convos/despedida.convo.txt:
TranscriptError: Error: convos/despedida.convo.txt/Line 5: bot says nothing
at async.waterfall (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:159:25)
at /home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/async/dist/async.js:473:16
at next (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/async/dist/async.js:5329:29)
at /home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/async/dist/async.js:969:16
at runConversation (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:143:15)
at async.mapSeries (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/botium-core/src/scripting/Convo.js:314:9)
at /home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/async/dist/async.js:1140:9
at /home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/async/dist/async.js:473:16
at iterateeCallback (/home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/async/dist/async.js:988:17)
at /home/thiagoc/.npm-global/lib/node_modules/botium-cli/node_modules/async/dist/async.js:969:16
codeforequity-at commented 5 years ago

The last pull request unfortunately had a quality problems, it was also lacking unit tests for the code changes (and this case shows the importance of unit tests ...). I fixed it myself now, it will work with the latest build (0.0.40)

staticdev commented 5 years ago

@codeforequity-at New test done on version 0.0.40. Now the SIMPLEREST_HEADERS_TEMPLATE and SIMPLEREST_BODY_TEMPLATE are being passed. But, context.conversation_id is going blank inside the body:

botium-BotDriver   CONTAINERMODE: 'simplerest',
  botium-BotDriver   SIMPLEREST_URL: 'http://localhost:5000/reply',
  botium-BotDriver   SIMPLEREST_HEADERS_TEMPLATE: { 'content-type': 'application/json' },
  botium-BotDriver   SIMPLEREST_BODY_TEMPLATE:
  botium-BotDriver    { message: '{{msg.messageText}}',
  botium-BotDriver      user_id: '{{context.conversation_id}}' },
  botium-BotDriver   SIMPLEREST_RESPONSE_JSONPATH: '$.reply',
  botium-BotDriver   CONFIG: './botium.json' } +267ms
  botium-BotDriver Build - Sources : { LOCALPATH: '.',
  botium-BotDriver   GITPATH: 'git',
  botium-BotDriver   GITBRANCH: 'master',
  botium-BotDriver   GITDIR: '.' } +1ms
  botium-BotDriver Build - Envs : { IS_BOTIUM_CONTAINER: true } +0ms
  botium-cli-run running testcase convos/despedida.convo.txt +52ms
  botium-Convo convos/despedida.convo.txt/Line 4: user says {
  botium-Convo   "sender": "me",
  botium-Convo   "channel": null,
  botium-Convo   "messageText": "tchau",
  botium-Convo   "stepTag": "Line 4",
  botium-Convo   "not": false,
  botium-Convo   "asserters": [],
  botium-Convo   "logicHooks": []
  botium-Convo } +0ms
  botium-SimpleRestContainer constructed requestOptions {
  botium-SimpleRestContainer   "uri": "http://localhost:5000/reply",
  botium-SimpleRestContainer   "method": "POST",
  botium-SimpleRestContainer   "headers": {
  botium-SimpleRestContainer     "content-type": "application/json"
  botium-SimpleRestContainer   },
  botium-SimpleRestContainer   "body": {
  botium-SimpleRestContainer     "message": "tchau",
  botium-SimpleRestContainer     "user_id": ""
  botium-SimpleRestContainer   },
  botium-SimpleRestContainer   "json": true
  botium-SimpleRestContainer } +0ms
  botium-SimpleRestContainer got response body: {
  botium-SimpleRestContainer   "error": "user_id and message are required keys",
  botium-SimpleRestContainer   "status": "error"
  botium-SimpleRestContainer } +17ms
codeforequity-at commented 5 years ago

The context (and the conversation_id) is not filled out of the box. If you need it depends on your chatbot. I think you can just hand over a user_id of your choice.

staticdev commented 5 years ago

From the Wiki I though conversation_id is automatic (https://github.com/codeforequity-at/botium-core/wiki/operation-mode-simplerest).

I used "SIMPLEREST_INIT_CONTEXT": "{ \"conversation_id\": \"botium\" }" and it worked!

I think you can close this issue then. Thanks a lot! Botium is a very nice product and I will make good marketing with my fellow developer friends.

codeforequity-at commented 5 years ago

Thanks In two weeks we will publish Botium Stack (free) and Botium Platform (commercial), which includes Botium Box as user interface and test management based on Botium Core. You can drop us a line at info@botium.at if you are interested in notification.