Execute Script gives the tester access to the Selenium/WebDriver Java APIs in a JavaScript environment.
When adding or editing a step, change the action type to Execute Script. This action has a single datasource, which contains the script. Press the datasource edit button to edit the script.
The script will be pre-populated with a simple example and a little documentation to help you get started.
We find real examples to be more helpful than pages of verbiage, so we’ll maintain a list of scripts that we’ve found useful for your reference:
JavaScript is a great choice for a scripting language – as it is the de-facto standard for web scripting and most web developers and testers are familiar with it. However, because Load Tester is a Java application and uses the Java APIs for Selenium/WebDriver, it exposes the Java APIs through a translation layer into JavaScript. For the most part, this translation is seamless. If you are familiar with the Java WebDriver APIs, you will find working in JavaScript is fairly easy. We hope that if you are familiar with one of the JavaScript Selenium/WebDriver APIs, you will also find the transition painless. In either case, we’d love to hear your feedback, so please relay your experiences to our support engineers.
The scripting environment gives the tester a lot of power. Including the ability to hang the virtual user in a loop, consume all the available memory, and maybe even crash Load Tester. Please be careful!
Load Tester needs to know what DataSets are used by the testcase – which means that it needs to know what DataSets are used by each step. This is needed to distribute the right DataSets to the load engines. Under normal use, this is completely seamless. But because a script could reference a DataSet in a way that Load Tester cannot detect, the required DataSets must be explicitly declared.
To do this, implement the getDatasetsRequired() method. If no DataSets are used by the script, the getDatasetsRequired() function can be omitted or return null. Otherwise the function should return the name of the required DataSet (or an array of names) used by the script. This will ensure that the correct DataSets are sent to the load engines, but it does NOT support automatic renaming of DataSets. The scripts must be updated manually.