codeforequity-at / botium-bindings

The Selenium for Chatbots
http://www.botium.at
MIT License
108 stars 33 forks source link

Overriding botium.json config inside botium.spec.js file #115

Open piotrjak opened 5 years ago

piotrjak commented 5 years ago

Hi! First let me tell you that I've searched through FAQ and both closed and open github issues here and I haven't found an answer to my question.

Case: I have an authentication token that expires after a specific amount of time so I'd like to set this token inside botium.spec.json file, before any of the convos tests run.

Question 1 In https://botium.atlassian.net/wiki/spaces/BOTIUM/pages/360603/Botium+Configuration+-+Capabilities -> Configuration Source -> fourth dot. You write that it's possible to overwrite a specific CAPABILITY config setting with env variable e.g. if I want to override PROJECT_NAME then I set env variable BOTIUM_PROJECT_NAME="My ProjectName". But what about SIMPLEREST_HEADERS_TEMPLATE CAPABILITY which is a JSON object? How can I changeSIMPLEREST_HEADERS_TEMPLATE: { "Authorization": "Bearer MYTOKEN" } with env variable? I can't see any example.

Question 2 As I said - I'd like to fetch a token from a server BEFORE any of the tests run and set it on botium object. How can I do it in botium.spec.js file which contains:

const bb = require('botium-bindings');
bb.helper.jest().setupJestTestSuite();

I found that I can modify the header setting inside custom asserter

  assertConvoBegin({ convo, container, args }) {
    console.log(`MyAsserter assertConvoBegin: ${convo.header.name}`);
    return Promise.resolve();
  }

in container desctructured parameter, but I don't want to bind changing the header to a specific test - I'd like to do it before the test. Can I use BotDriver to do it? How to import this object into this botium.spec.js file?

Looking forward to the response and thank you for your work in botium-bindings. It looks like writing convos files will improve integration testing with our chatbot.

codeforequity-at commented 5 years ago

Question 1 Just convert JSON to string:

process.env.BOTIUM_SIMPLEREST_HEADERS_TEMPLATE = JSON.stringify({ "Authorization": "Bearer MYTOKEN" })

Question 2 Several options available. You can use a request hook:

"SIMPLEREST_REQUEST_HOOK": "requestOptions.headers.Authorization = 'Bearer ' + process.env.MY_TOKEN"

Or you can use Scripting functions in Moustache template:

"SIMPLEREST_HEADERS_TEMPLATE:" { "Authorization": "Bearer {{#fnc.func}}process.env.MY_TOKEN{{/fnc.func}}" }

Both should work.