Solved

How to buffer JS Executed return value in Tosca

  • 23 November 2023
  • 3 replies
  • 61 views

Userlevel 2
Badge

In Tosca there are two native Modules to work with JavaScript:

  1. “Execute JavaScript”
  2. “Verify JavaScript Result”

The first one executes the script

 

While the second one executes and verifies the returned result 

 

The question is how to get the result from JS execution and store in the buffer?

For example, I want to take the active tab title by executing this JS command which works in browser console

document.querySelector('html head title').textContent;
 

 

Now, how to store the value of that command in the buffer?

icon

Best answer by brendon.russell 3 December 2023, 23:03

View original

3 replies

Userlevel 2

Two things to get this to work:
1. Add “return “ at the beginning of the JavaScript as shown in the manual for the Verify Javascript module, i.e.

return document.querySelector('html head title').textContent;

(Note that in your example here this simpler version should also work:
return document.title;)

  1. Use {XB[Your Buffer Name]} in the Result to save the entire output into a buffer. (This is a workaround with the Verify action mode since for some reason the module has been built in such a way that it doesn’t directly support the Buffer action mode.)
Userlevel 2
Badge

Hi Nissyan,

Please find the below example for the same.

https://support-hub.tricentis.com/open?id=kb_article_view&sys_kb_id=78d438a637ab3a44a30fa16043990e34

Thanks,

Harish n

Userlevel 2
Badge

Thank you both 👍👍 for your answers.

So there was a trick which was not obvious from the module description.

Reply