- Print
- DarkLight
Reusable JS Steps (JavaScript Snippets)
If there are JavaScript code snippets which you find yourself using often, you can save those custom snippets in Autify and insert them into any Scenario.
Creating JS Snippets in your Workspace
In your Workspace Settings, you will find a section labeled JavaScript Snippets. This is where all of your saved JS snippets can be found. To create a new snippet, click the Add button.
This will bring you to the JavaScript Snippets editor. You will first need to give a name for the Snippet you create.
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 can 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.
If you want to rename or delete arguments, you must create a new JavaScript Snippet.
Once done, click the Add button at 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.
Autify JavaScript Snippets
Autify JavaScript Snippets is a library of commonly used JavaScript snippets created by Autify, and provided in the form of templates. Please feel free to edit and use them for your own needs.
If you have any opinions or requests regarding the library, please contact us via the Autify chat window!