Creating JS Snippets in your Workspace
From here, you can type the code that you would like to save for future use. The code is already wrapped in a function, so it is not necessary to define the function in the editor, but you may define additional functions as needed.
Once done, click the Add button on the bottom of the screen.
Inserting a JS Snippet into a Test Scenario
Once your snippet is saved, you can add it to any Scenario when in the Scenario Details page. To do so, click the + button between steps at the point you want to insert the snippet. Then select Insert JS Step From Snippets. And finally, select the snippet which you want to insert.
If your JS snippet is interacting with a specific element(s), it is important to note that you will want to add the snippet at the point where that element(s) is accessible on the webpage.
After selecting your snippet, the JS step will be successfully inserted into your Test Scenario. Just as with any other JS step, you have the ability to use the return value in subsequent steps.