Can we add Javascript hook after connecting to chat in

Hello Florian,

I am using “E2E UI/UX Testing” connector with automation technology “Selenium”. In my project we have condition to perform some action on input data after connecting to bot. Can we add Javascript Hook and perform task in between after connecting to chat bot.

Regards,
Deepak Kumar

More details please. There are several Javascript hooks already available, but from your description I cannot tell if your case is covered.

When we successfully connect to chatbot and able to start conversation. In between of conversation we have a situation of changing an option say mobile number, for that we need to select one element from chatbot and open a dialog box which needs to be handled. This dialog box have a text area and submit button that need to handle as well. For all this we are looking for javascript hook to handle element after chatbot connection.

This should be doable with a Logic Hook - docs in the Botium Wiki.

The logic hook should implement the logic of

  • getting access to the current Connector handle (container.pluginInstance)
  • doing the things like clicking button and making selection

In the BotiumScript it will look like this:

LH_SELECT_MOBILE_NUMBER 056346444

In the botium.json, it will look like this:

{
  "botium": {
    "Capabilities": {
      ...
      "LOGIC_HOOKS": [
        {
          "ref": "LH_SELECT_MOBILE_NUMBER",
          "src": "src/lh_select_mobile_number.js"
        }
      ]
    }
  }
}

And the file src/lh_select_mobile_number.js will look something like:

module.exports = class MyCustomLogicHook {
  constructor (context, caps, globalArgs) {
    this.context = context
    this.caps = caps
    this.globalArgs = globalArgs
  }

  onMeStart ({ container, args }) {
   container.pluginInstance._runInQueue(async () => {
      //this is the WebdriverIO browser instance if needed
      const browser = container.pluginInstance.browser
     
      const myBtn = await this.findElement('.my-button')
      await myBtn.click()
      // and here some more WebdriverIO code ...
    })
  }
}

The _runInQueue is needed to not interfere with other Selenium calls that might happen the same time, like checking for chatbot response

Hi,

In the botium Box, Settings → FileBrowser options don’t see a folder for resources or src and there is no option provided to create any new folders, can you please help on how we can have this fixed?

As a alternative tried to add the Javascript hook functions in the botium.json as below,
“LOGIC_HOOKS”: [
{
“ref”: “DUMMYHOOK”,
“src”: {
“onConvoBegin”: “const browser = container.pluginInstance.browser; const topBtn = await browser.$(‘#top_window’);//Exception is thrown while trying to find the component. console.log(await topBtn.getText());//just print or update the value here”,
},
“global”: false
}
]
Comments in Javascript is provided for explanation purpose only, and is not part of the botium.json file.

When I try to search the HTML tag it always results in “Running Convo “Sample1TC” failed: Sample1TC/Line 3: assertion error - Unexpected identifier”.

Can you please help guide us.

Thanks,
Sunil

File browser is only accessible for users having the permission FILESYSTEM_WRITE - by default Botium Box role management only assigned this permission to the Administrator role.

1 Like

I am surprised by the “assertion error” output, as this step shouldnt have been reached and failed earlier.

It is not possible to have “async/await” code directly in the main flow of the script, this is not valid Javascript code.

it should be something like this:

“onConvoBegin”: “new Promise(async (resolve, reject) => { const browser = container.pluginInstance.browser; const topBtn = await browser.$(’#top_window’); console.log(await topBtn.getText()); })”,

1 Like