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.
You also have the ability to add arguments to your function by clicking on the + button within the parenthesis. You can then input the argument values on the right-hand side of your screen. Arguments make your code snippets much more dynamic and flexible. You can find more information on arguments in the JS Steps section of Autify University.
Renaming and deleting arguments once saved is not allowed as it may break existing scenarios.
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.