Transaction Scripting Reference
This article contains a reference of all namespaces, classes, modules and methods that are available for creating transaction tests.
For Selenium WebDriver documentation, visit this page
Hover over a keyword or method name in a script to see additional information, in both the ThousandEyes Recorder and the ThousandEyes platform on the test creation page.
Example Scripts
For quicker orientation, there is a comprehensive collection of script examples provided by the transaction scripting examples repository in the ThousandEyes GitHub account.
Getting Test Configuration Settings
Use test
to work with the ThousandEyes transaction test configuration, such as getting the target test URL (for example https://google.com/) or getting the test timeout setting.
Namespace |
|
Module |
|
Import Syntax |
|
Used Like |
|
Method |
|
Description | Returns an object with the current settings of the test. |
Parameters | None |
Returns | (object) with the following parameters: |
Sample Script 1: Obtain Test URL
Sample Script 2: Reduce Test Timeout Value
This snippet shows how to get the test timeout setting and set the implicit timeout in the transaction to half that value. On the ThousandEyes platform, this test timeout setting is found on the Advanced Settings tab for the transaction test you’re working with, on the Cloud & Enterprise Agents > Test Settings screen.
Why would you want to do this? The implicit timeout is the time that each transaction step will wait for a designated page element to appear before timing out. By default, the ThousandEyes Recorder sets the implicit step timeout value to 7 seconds. This per-step value may need to be increased for tests that take longer to complete.
Instead of statically increasing the implicit timeout value in the script, you can configure it to be a proportion (for example 50%) of the total test timeout value. This will ensure the implicit timeout value is always set to a reasonable value, regardless of the test timeout setting.
Controlling the Browser
ThousandEyes provides a wrapper of the Selenium WebDriver library for JavaScript. It contains methods for controlling the browser that is used to execute the test.
Namespace |
|
Module |
|
Import Syntax |
|
Used Like |
|
Supported methods |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
Reference | https://selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html |
Interacting with Page Elements
A set of methods for interacting with elements. Once the element is located and retrieved (by using the findElement()
function or similar), it can be managed using the following methods.
Namespace |
|
Module |
|
Find an element |
|
Supported methods |
|
| |
| |
| |
| |
| |
| |
| |
Reference | https://selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebElement.html |
Waiting for Events
Defines common conditions for use with WebDriver wait.
Namespace |
|
Module |
|
Import Syntax |
|
Used Like |
|
Supported methods |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
Reference | https://selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/lib/until.html |
Generating Keyboard Events
Representations of pressable keys that aren't text.
Namespace |
|
Module |
|
Import Syntax |
|
Used Like |
|
Supported methods |
|
Values | See the reference below |
Reference | https://selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_Key.html |
Taking Screenshots
Namespace |
|
Module |
|
Method |
|
Used Like |
|
Description | Takes a screenshot of the current page and stores it in memory. These screenshots are collected at the end of the test. A maximum of three screenshots is allowed; if this limit is exceeded, new screenshots replace the older ones. Also, by default, a screenshot is taken automatically if a transaction test has an error. |
Parameters | None |
Returns | None |
Handling Credentials
Namespace |
|
Module |
|
Import Syntax |
|
Used Like |
|
Method |
|
Description | Gets the stored credential value matching the supplied name. Only works if you have already associated the credential with the current test (Test settings page). |
Parameters |
|
Returns | (string) The password or sensitive value associated with the supplied credential name |
File Uploads
You can’t upload a pre-existing file, only a generated one. You can specify the file size and choose text or binary format.
Upload a Specified File
Namespace |
|
Module |
|
Import Syntax |
|
Used Like |
|
Method |
|
Description | Write a file to the file system with the given filename, and return a path to the generated file that can be referenced when populating a file upload field. |
Parameters |
|
|
Generate a Random Text File
Namespace |
|
Module |
|
Import Syntax |
|
Used Like |
|
Method |
|
Description | Create a file of the given size with the given filename, returning a path to the generated file. The generated file will be filled with randomly-generated alphanumeric characters. |
Parameters |
|
|
Generate a Random Binary File
Namespace |
|
Module |
|
Import Syntax |
|
Used Like |
|
Method |
|
Description | Create a file of the given size with the given filename, returning a path to the generated file. The generated file will be filled with randomly-generated bytes. |
Parameters |
|
|
File Downloads
For file downloads, you can get the file path, path length, hash, or extract text from a downloaded PDF.
Wait for a File to Download
Namespace |
|
Module |
|
Import Syntax |
|
Used Like |
|
Method |
|
Description | Waits for a download matching the supplied filename to appear and then to finish. If a file matching the supplied name has previously been downloaded within the current script, this function will complete immediately. If no file matching the supplied name has been or is currently downloading, it will wait for the supplied timeout amount of time for the file to appear and finish downloading. Downloaded files are saved in a temporary folder on the agent. All files from previous tests are deleted from the temporary folder before a transaction test is run. |
Parameters |
|
|
Show File Path
Namespace |
|
Module |
|
Import Syntax |
|
Used Like |
|
Method |
|
Description | Return the contents of the specified downloaded file's path. |
Parameters |
|
Get File Path Length
Namespace |
|
Module |
|
Import Syntax |
|
Used Like |
|
Method |
|
Description | Return the size of the specified downloaded file's path. |
Parameters |
|
Get File Hash
Namespace |
|
Module |
|
Import Syntax |
|
Used Like |
|
Method |
|
Description | Return the hash of the specified downloaded file's contents. |
Parameters |
|
Returns |
Extract Text from a Downloaded PDF
Namespace |
|
Module |
|
Import Syntax |
|
Used Like |
|
Method |
|
Description | Extract all text from a downloaded PDF file. You can use this to verify that the contents of a downloaded PDF file matches your expectations. |
Parameters |
|
Measuring Transaction Time(s)
ThousandEyes transactions support two types of measuring time:
Markers
Overall transaction time
Markers
Markers are custom time delimiters, enabling precise time measurements of smaller sections of the transaction. A maximum of 200 markers can be defined in a transaction script. The Waterfall tab displays the first ten markers, with a Show more link if more than ten markers are defined.
Start a marker:
Namespace |
|
Module |
|
Method |
|
Description | Starts a marker with the supplied name. This marker can later be stopped by calling the |
Parameters |
|
Returns | None. Will throw an error if attempting to start a previously started marker. |
Stop a marker:
Namespace |
|
Module |
|
Method |
|
Description | Stops the marker matching the supplied name. |
Parameters |
|
Returns | None. Will throw an error if attempting to stop a marker that hasn't been started yet or one that was already stopped. |
Set a marker:
Namespace |
|
Module |
|
Method |
|
Description | Creates a marker that spans from transaction start time to the time this method is called. Calling |
Parameters |
|
Returns | None. |
Overall Transaction Time
Running a transaction test implicitly causes the overall transaction time measurement, spanning from the moment the transaction test run starts and to the end of the transaction. However, if customization of overall transaction time's start and stop moments is required, the following methods can be used to such effect. |
Set the overall transaction time start moment:
Namespace |
|
Module |
|
Method |
|
Description | Sets the start time of the transaction. If not called, the transaction start time will default to the script start time. |
Parameters | None |
Returns | None |
Set the overall transaction time end moment:
Namespace |
|
Module |
|
Method |
|
Description | Sets the end time of the transaction. If not called, the transaction start time will default to the script end time. |
Parameters | None |
Returns | None |
Element Locators
Provided is a set of mechanisms dedicated to locating elements on the page.
Namespace |
|
Class |
|
Import Syntax |
|
Used Like |
|
Supported static methods |
|
| |
| |
| |
| |
| |
| |
| |
Reference | https://selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/lib/by_exports_By.html |
Assertions
The assert
module provides a set of assertion functions for verifying invariants.
NOTE: Only strict mode is supported.
Namespace |
|
Module |
|
Import Syntax |
|
Used Like |
|
Supported methods |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
Reference | https://nodejs.org/api/assert.html |
Authentication Module
Use the authentication
module to get a time-based one-time password (TOTP) for 2-factor authentication, as in this scripting example: usingTOTPTwoFactorAuth.js.
Namespace |
|
Module |
|
Import Syntax |
|
Used Like |
|
Method |
|
Description | Generates a 6-digit temporary authentication code to be used in conjunction with a password on sites that support 2 factor authentication with time-based one-time passwords (TOTPs). |
Parameters |
|
Returns | (string) One-time password. |
Further Information
For further information about transaction testing, refer to the collection of documentation pages under Transaction Tests.
If you have any questions, contact ThousandEyes Support as described on Getting Support from ThousandEyes.
Last updated