biz.neustar.wpm.api
Interface Test


public interface Test

The main control interface for Neustar Web Performance Management scripts - All scripts must start here first.

This object is available as the variable test from within the a JavaScript-enabled script. This object is effectively the "starting point" for all other scripts, as it serves as the interface for interacting with web sites (via openBrowser() and openHttpClient() as well as the mechanism for controlling transactions and steps (via beginTransaction() and beginStep(String)).

For automating real and headless browsers, scripts can use Selenium WebDriver (See openBrowser()).

In this example we open a browser and perform a google search using Selenium WebDriver:

 var driver = test.openBrowser();
 test.beginTransaction();
   test.beginStep("Navigate to google.com");
     driver.get("http://www.google.com");
   test.endStep();

   test.beginStep("Search for Cheese!");
     // Find the text input element by its name
     var element = driver.findElement(By.name("q"));

     // Enter something to search for
     element.sendKeys("Cheese!");

     // Now submit the form. WebDriver will find the form for us from the element
     element.submit();

     test.waitFor(function() {
       return driver.getTitle().toLowerCase().startsWith("cheese!")
     }, 2000);
   test.endStep();
 test.endTransaction();
 

A Selenese API that is also available for users more comfortable with scripts recorded with the Selenium IDE.

In example we navigate to google and do a search using the Selenese API:

 var driver = test.openBrowser();
 var selenium = driver.getSelenium();

 test.beginTransaction();
   test.beginStep("Navigate to google.com");
     selenium.open("http://www.google.com");
   test.endStep();

   test.beginStep("Search for Cheese!");
      // Type Cheese into the search box
      selenium.type("name=q", "cheese!");

      // Submit the search form
      selenium.submit("name=gs");

      // Wait for the cheese.com to show up in the search results
      selenium.waitForTextPresent("CHEESE.COM - All about cheese!")
   test.endStep();
 test.endTransaction();
 

This object also provides other useful functions, such as assistance with file uploads (filePath(String)), simulating "user think time" (pause(long)), and parameterizing tests with unique data (getUserNum() and getTxCount()).


Method Summary
 void assertEquals(java.lang.Object expected, java.lang.Object actual)
          Assert that two values are equal.
 void assertEquals(java.lang.Object expected, java.lang.Object actual, java.lang.String message)
          Assert that two values are equal.
 void assertFalse(boolean assertion)
          Assert that the given condition is false.
 void assertFalse(boolean assertion, java.lang.String message)
          Assert that the given condition is false.
 void assertNotEquals(java.lang.Object expected, java.lang.Object actual)
          Assert that two values are not equal.
 void assertNotEquals(java.lang.Object expected, java.lang.Object actual, java.lang.String message)
          Assert that two values are not equal.
 void assertThrown(NativeFunction function)
          Assert that the running the JS function threw an exception when run, otherwise an exception is thrown.
 void assertThrown(java.lang.String exceptionMessage, NativeFunction function)
          Assert that the running the JS function threw an exception when run.
 void assertTrue(boolean assertion)
          Assert that the given condition is true.
 void assertTrue(boolean assertion, java.lang.String message)
          Assert that the given condition is true.
 TransactionStep beginStep()
          Starts a new step (must be called from within a transaction).
 TransactionStep beginStep(NativeFunction stepFunction)
          Starts a new step (must be called from within a transaction) by calling the given function, and automatically end the step when the function has finished running.
 TransactionStep beginStep(java.lang.String stepLabel)
          Starts a new step (must be called from within a transaction).
 TransactionStep beginStep(java.lang.String stepLabel, int timeoutMilliseconds, NativeFunction stepFunction)
          Starts a new step (must be called from within a transaction) with a timeout specified in milliseconds by calling the given function, and automatically end the step when the function has finished running.
 TransactionStep beginStep(java.lang.String stepLabel, NativeFunction stepFunction)
          Starts a new step (must be called from within a transaction) with a timeout specified in milliseconds by calling the given function, and automatically end the step when the function has finished running.
 Transaction beginTransaction()
          Starts a new transaction.
 Transaction beginTransaction(NativeFunction transactionFunction)
          Starts a new transaction that runs the given transaction function, and automatically ends the transaction when the function has completed.
 Transaction beginTransaction(NativeFunction transactionFunction, NativeObject params)
          Starts a new transaction that runs the given transaction function, and automatically ends the transaction when the function has completed.
 void closeBrowser()
          Terminates the active Selenium browser session.
 DataFile datafile(java.lang.String name)
          Returns a wrapped handle to an uploaded file.
 void endStep()
          Stops the current step.
 void endTransaction()
          Ends the current transaction.
 void endTransaction(NativeObject params)
          Ends the current transaction.
 void fail()
          Fails the test by throwing an exception.
 void fail(java.lang.String message)
          Fails the test with a message by throwing exception with the given message.
 java.lang.String filePath(java.lang.String name)
          Returns the local path for the specified file name.
 CSVTable fileToCSV(DataFile dataFile)
          Creates and returns a table of data backed by a Comma Separated Value File.
 java.lang.String[] findRegexMatches(java.lang.String content, java.lang.String regex)
          A simple way to find one or more regular expression matches against some content.
 void forEach(java.lang.Object o, NativeFunction function)
          Loops through a list/map, applying the function to each element.
 TransactionStep getActiveStep()
          Returns the currently active step, which is useful for advanced use cases where the step object is being manipulated directly.
 Transaction getActiveTransaction()
          Returns the currently active transaction, which is useful for advanced use cases where the transaction object is being manipulated directly.
 CSVTable getCSV(java.lang.String name)
          Creates and returns a table of data backed by a Comma Separated Value file.
 java.lang.String getLocation()
          Returns the location that the script is running from.
 int getTxCount()
          Returns the count of transactions that have been completed (regardless of success or failure) in the current script.
 int getUserNum()
          Returns the unique number for each independent script executed during a load test.
 java.lang.String getVersion()
          Return the Test Scripts API version.
 void globalPause(long pauseTimeInMs)
          Sleep between steps for the duration passed in param.
 void globalPause(long minTimeInMS, long maxTimeInMS)
          Sleep between steps.
 void include(java.lang.String className)
          Includes a JavaScript file into the current script's top level scope.
 boolean isLoadTesting()
          Indicates whether the current execution context is within a load test.
 boolean isScriptValidator()
          Indicates if the current execution environment is the local script validator.
 boolean isValidation()
          Indicates if the current execution environment is an actual real time script playback or if this is simply a script validation run that is used during script development.
 LoadTestSettings loadTestSettings()
          Get load testing specific settings, these settings have no effect while monitoring.
 void log(java.lang.String log)
          Logs some text to the log buffer.
 long nextSequence(java.lang.String sequenceName)
          Retrieves the next non-zero, positive integer in a particular sequence.
 WebDriver openBrowser()
          Starts a Selenium WebDriver browser session.
 HttpClient openHttpClient()
          Starts a basic HTTP client that is capable of GET and POST requests, allowing the script author to simulate real web browsers.
 WebSocket openWebSocket(java.lang.String url)
          Opens a W3C WebSocket at the give URL.
 WebSocket openWebSocket(java.lang.String url, java.lang.String version)
          Opens a W3C WebSocket at the give URL.
 void pause(long pauseTimeInMs)
          Instructs the script to pause for a specified amount of time.
 void pause(long pauseTimeInMs, boolean includeInTimeActive)
          Instructs the script to pause for a specified amount of time.
 void quickStop()
          Normally when a load test is paused or the load level drops to fewer concurrent users, the actively running scripts are allowed to finish executing and complete the current transaction.
 void setBandwidthLimitMode(java.lang.String mode)
          Turn on/off bandwidth limiting.
 void setDownstreamKbps(long downstreamKbps)
          Sets an artificial kilobits-per-second value for all data downloaded.
 void setLatency(long latency)
          Sets an artificial latency simulation for sending one full MTU (~1500 bytes on the internet).
 void setUpstreamKbps(long upstreamKbps)
          Sets an artificial kilobits-per-second value for all data upload from the script (including headers).
 void startTimeoutTimer(long timeoutInMs)
          Starts a timer that runs until timeoutInMs is reached, and if it has been reached, will terminate the running script.
 void stopExpected()
          Indicate that the script is expecting that it could be stopped at any time and that if that happens, it should not be considered an error.
 void stopTimeoutTimer()
          Stops the timeout timer, if it was started.
 void time(java.lang.String name)
          Starts a timer you can use to track how long an operation takes.
 long timeEnd(java.lang.String name)
          Ends and logs a timer if it exists
 boolean waitFor(NativeFunction callback, long timeoutInMs)
          Wait for the user specified function to return true.
 void waitForNetworkTrafficToStop(long quietPeriodInMs, long timeoutInMs)
          Waits until no HTTP traffic associated with the current test has taken place for at least quietPeriodInMs.
 void chromeoptions()
          Options that you can use to customize and configure a ChromeDriver session.
 void firefoxoptions()
           It is used to control the behaviour of Firefox.
 

Method Detail

openBrowser

WebDriver openBrowser()
Starts a Selenium WebDriver browser session. A call to this function indicates that the script is a real browser script and will be billed accordingly. Only one browser is allowed to be open at a time, so any additional call to this function will automatically close the previous browser.

Returns:
an object representing the WebDriver browser

openHttpClient

HttpClient openHttpClient()
Starts a basic HTTP client that is capable of GET and POST requests, allowing the script author to simulate real web browsers. A call to this function indicates that the script is a virtual user script and will be billed accordingly.

Returns:
an object representing a virtual user, capable of issuing HTTP requests.

include

void include(java.lang.String className)
Includes a JavaScript file into the current script's top level scope. There are some rules for JS inclusion:

Parameters:
className - The name of the data file to include, minus the ".js" extension.

openWebSocket

WebSocket openWebSocket(java.lang.String url)
Opens a W3C WebSocket at the give URL. A call to this function indicates that the script is a virtual user script and will be billed accordingly.

Checkout the WebSocket class for details.

The other overload can be used to specific the websocket version to use.

Parameters:
url - URL to a websocket server (i.e. "ws://example-websocket.com:8765")
Returns:
an object that implements the W3C WebSocket interface

openWebSocket

WebSocket openWebSocket(java.lang.String url,
                        java.lang.String version)
Opens a W3C WebSocket at the give URL. A call to this function indicates that the script is a virtual user script and will be billed accordingly.

Checkout the WebSocket class for details.

The WebSocket version should be one of:

"8" - which will give you WebSockets Hybi 10

"13" - which will give you WebSockets Hybi 17 / RFC 6455 (default)

Parameters:
url - URL to a websocket server (i.e. "ws://example-websocket.com:8765")
version - The protocol version to connect using
Returns:
an object that implements the W3C WebSocket interface

getLocation

java.lang.String getLocation()
Returns the location that the script is running from. Returns 'local' if running in the local script validator.

Returns:
the location string, such as sanfrancisco or washingtondc.

beginTransaction

Transaction beginTransaction()
Starts a new transaction. For load testing scripts all transactions are recorded. For monitoring scripts only the final transaction is recorded.

Returns:
a handle to the transaction object, which can be further manipulated for advanced use cases.

beginTransaction

Transaction beginTransaction(NativeFunction transactionFunction)
Starts a new transaction that runs the given transaction function, and automatically ends the transaction when the function has completed. For load testing scripts all transactions are recorded. For monitoring scripts only the final transaction is recorded.
     beginTransaction(function(transaction) {
         // steps
     });
 

Parameters:
transactionFunction - the function to call for the transaction
Returns:
a handle to the transaction object, which can be further manipulated for advanced use cases.

beginTransaction

Transaction beginTransaction(NativeFunction transactionFunction,
                             NativeObject params)
Starts a new transaction that runs the given transaction function, and automatically ends the transaction when the function has completed. For load testing scripts all transactions are recorded. For monitoring scripts only the final transaction is recorded.
     beginTransaction(function(transaction) {
         // steps
     }, {persist: false, abortActiveRequests: false});
 

Parameters:
transactionFunction - the function to call for the transaction
params - A JavaScript object that contains key/value pairs for specific options when stopping the transaction
Returns:
a handle to the transaction object, which can be further manipulated for advanced use cases.

beginStep

TransactionStep beginStep()
Starts a new step (must be called from within a transaction).

Use the override to set a step label and step timeout if required.

Returns:
the transaction step

beginStep

TransactionStep beginStep(java.lang.String stepLabel)
Starts a new step (must be called from within a transaction).

Use the override to set a step timeout if required.

Parameters:
stepLabel - a description of the step, to be used for various reporting.
Returns:
a handle to the step object, which can be further manipulator for advanced use cases.

beginStep

TransactionStep beginStep(NativeFunction stepFunction)
Starts a new step (must be called from within a transaction) by calling the given function, and automatically end the step when the function has finished running.
     beginStep(function(step) {
         // do stuff
     });
 

Parameters:
stepFunction - the function to call for the step
Returns:
a handle to the step object, which can be further manipulator for advanced use cases.

beginStep

TransactionStep beginStep(java.lang.String stepLabel,
                          NativeFunction stepFunction)
Starts a new step (must be called from within a transaction) with a timeout specified in milliseconds by calling the given function, and automatically end the step when the function has finished running.
     beginStep("Step 1", function(step) {
         // do stuff
     });
 

Parameters:
stepLabel - the step's label
stepFunction - the function to call for the step
Returns:
a handle to the step object, which can be further manipulator for advanced use cases.

beginStep

TransactionStep beginStep(java.lang.String stepLabel,
                          int timeoutMilliseconds,
                          NativeFunction stepFunction)
Starts a new step (must be called from within a transaction) with a timeout specified in milliseconds by calling the given function, and automatically end the step when the function has finished running.
     beginStep("Step 1", 30000, function(step) {
         // do stuff
     });
 

Parameters:
stepLabel - the step's label
timeoutMilliseconds - the step timeout in milliseconds
stepFunction - the function to call for the step
Returns:
a handle to the step object, which can be further manipulator for advanced use cases.

endStep

void endStep()
Stops the current step. Any activity will not be recorded until a new step is started.


pause

void pause(long pauseTimeInMs)
           throws java.lang.InterruptedException
Instructs the script to pause for a specified amount of time. If we are in an active step and/or transaction, the pause time is added to those for reporting purposes automatically. Pause times are limited to 30 seconds during script validation, though the full time is honored during a real test playback, such as a load test.

Parameters:
pauseTimeInMs - the time to pause (in milliseconds).
Throws:
java.lang.InterruptedException - if the script is paused, stopped, or aborted during execution

pause

void pause(long pauseTimeInMs,
           boolean includeInTimeActive)
           throws java.lang.InterruptedException
Instructs the script to pause for a specified amount of time. If includeInTimeActive is true, the pause time is considered part of the active transaction time. If includeInTimeActive is false and we are in an active step and/or transaction, the pause time is added to those for reporting purposes automatically. Pause times are limited to 30 seconds during script validation, though the full time is honored during a real test playback, such as a load test.

Parameters:
pauseTimeInMs - the time to pause (in milliseconds).
includeInTimeActive - true to include in tx time, false otherwise
Throws:
java.lang.InterruptedException - if the script is paused, stopped, or aborted during execution

endTransaction

void endTransaction()
Ends the current transaction. Any activity will not be recorded until a new transaction is started. For load testing scripts all transactions are recorded. For monitoring scripts only the final transaction is recorded. This function is the same as calling #endTransaction(org.mozilla.javascript.NativeObject) with all the defaults.


endTransaction

void endTransaction(NativeObject params)
Ends the current transaction. Any activity will not be recorded until a new transaction is started. For load testing scripts all transactions are recorded. For monitoring scripts only the final transaction is recorded.

The possible parameters that can be supplied are:

 test.endTransaction({persist: true/false (default is true),
                      abortActiveRequests: true/false (default is true)});
 

The persist parameter controls whether the raw results will be saved to disk. The results will always be included in the aggregate results, but in some situations such as extremely large load tests, it is desirable to only store a small sampling of the raw results, ensuring that you aren't overwhelmed with raw data.

The abortActiveRequests parameter controls whether any open HTTP requests should be cut off while cleaning up the transaction that is ending. By default this is the preferred way to go, however in some rare cases, especially when looping multiple transactions in a load test, it is desirable to leave open connections, especially "long polling" and WebSocket requests that should maintain connectivity between transactions.

Parameters:
params - A JavaScript object that contains key/value pairs for specific options when stopping the transaction

getActiveTransaction

Transaction getActiveTransaction()
Returns the currently active transaction, which is useful for advanced use cases where the transaction object is being manipulated directly.

Returns:
the currently active transaction (or null if no transaction is active).

getActiveStep

TransactionStep getActiveStep()
Returns the currently active step, which is useful for advanced use cases where the step object is being manipulated directly.

Returns:
the currently active step (or null if no step is active).

closeBrowser

void closeBrowser()
Terminates the active Selenium browser session.


setDownstreamKbps

void setDownstreamKbps(long downstreamKbps)
Sets an artificial kilobits-per-second value for all data downloaded.

If setBandwidthLimitMode() is not set, the setting "perSocket" will be used.

Parameters:
downstreamKbps - the kilobits-per-second to simulate.

setUpstreamKbps

void setUpstreamKbps(long upstreamKbps)
Sets an artificial kilobits-per-second value for all data upload from the script (including headers). Typically this value should be less than the downstream value to reflect a real internet user.

If setBandwidthLimitMode() is not set, the setting "perSocket" will be used.

Parameters:
upstreamKbps - the kilobits-per-second to simulate.

setLatency

void setLatency(long latency)
Sets an artificial latency simulation for sending one full MTU (~1500 bytes on the internet).

For high speed connections, such as FIOS, 1ms is fine. To simulate a slower ADSL connection, 50ms might make sense. For really slow connections, 200ms or more may be appropriate.

If setBandwidthLimitMode() is not set, the setting "perSocket" will be used.

Parameters:
latency - the latency in milliseconds.

setBandwidthLimitMode

void setBandwidthLimitMode(java.lang.String mode)
Turn on/off bandwidth limiting. Calling setDownstreamKbps() or setUpstreamKbps() will enable bandwidth limiting if it is not already.

Possible values are "on", "perSocket" or "off".

"on" limits the overall bandwidth used by the script. Default speeds are 10Mb per second download and 5Mb per second upload. Call setDownstreamKbps() and setUpstreamKbps() to adjust the default values.

"perSocket" limits the bandwidth used on a per socket basis.

"off" turns off the bandwidth limiting.

Parameters:
mode - Either "on", "perSocket" or "off". By default is bandwidth limiting is "off".

getUserNum

int getUserNum()
Returns the unique number for each independent script executed during a load test. The sequence starts at 1 and goes up to the max number of users participating in a load test. This function is especially useful for situations where data parameterization is required, such as typing an email address such as "test_user_X@example.com", where X is the user number.

Returns:
a number representing a unique script execution thread in a load test.

getTxCount

int getTxCount()
Returns the count of transactions that have been completed (regardless of success or failure) in the current script.

Note for load testing: This count is not the total transaction count currently completed in the load test. It is only the number of transaction recorded in the currently executing script.

Returns:
the total number of transactions run so far.

filePath

java.lang.String filePath(java.lang.String name)
Returns the local path for the specified file name. This path will resolve to a file on the local system that can be used for file uploads in a transaction.

Parameters:
name - the name of the file used by the script - usually a simple name like "foo.txt".
Returns:
the path on the local system.

log

void log(java.lang.String log)
Logs some text to the log buffer. Logs are only accessible for transactions run during development (such as script validation) and not during an actual load test.

Parameters:
log - the text to log.

isValidation

boolean isValidation()
Indicates if the current execution environment is an actual real time script playback or if this is simply a script validation run that is used during script development. This allows scripts to have slightly different behavior during validation than during a real playback, such as a during a load test. A common use for this function is to limit the "think time" simulated by the pause(long) function to a shorter time period when validating the script.

Note: this method will return true also if isScriptValidator() returns true!

Returns:
true if the current context is a script validation, false otherwise.

isScriptValidator

boolean isScriptValidator()
Indicates if the current execution environment is the local script validator. This allows scripts to have slightly different behavior depending on where they are executed. A common use for this function is to limit the "think time" simulated by the pause(long) function to a shorter time period when validating the script.

Returns:
true if the current context is the local script validator, false otherwise.

isLoadTesting

boolean isLoadTesting()
Indicates whether the current execution context is within a load test. This allows scripts to have slightly different behaviour during a load test (as opposed to, for example, validation or monitoring). A common use for this function is to determine whether you can invoke other load testing specific functions like nextSequence(String)

Returns:
true if the current execution context is a load test, false otherwise

nextSequence

long nextSequence(java.lang.String sequenceName)
Retrieves the next non-zero, positive integer in a particular sequence.

The number is guaranteed to be unique within the current load test.

The first number returned by this method for a particular sequence is 1. Subsequent calls return 2, 3, 4, etc.

This function is only available when the isLoadTesting() function returns true. A common use-case for this function is to use it in conjunction with an external data file. If you have a data file with username/password records and each pair can only be used once, you could use this function to guarantee that each user within the load test retrieves a unique record in the data file.

A load test may have multiple sequences. A sequence is no longer valid after the load test ends.

If this method is invoked outside of the context of a load test, then the implementation will return 0 although this behaviour should not be relied upon as it may change in the future.

Parameters:
sequenceName - the name of the sequence (up to 255 characters), must not be null
Returns:
the next non-zero, positive integer in a particular sequence, starting with 1

stopExpected

void stopExpected()
Indicate that the script is expecting that it could be stopped at any time and that if that happens, it should not be considered an error. This is most commonly used in conjunction with quickStop().


quickStop

void quickStop()
Normally when a load test is paused or the load level drops to fewer concurrent users, the actively running scripts are allowed to finish executing and complete the current transaction. Sometimes, especially for very long running scripts, such as testing a streaming video, it is desirable to interrupt the script immediately. Calls to this function tell Load Testing that when a "stop" event (such as a pause, ramp down, or end of a test) occur, the script should attempt to stop executing as quickly as possible. This is most commonly used in conjunction with $stopExpected().


getCSV

CSVTable getCSV(java.lang.String name)
Creates and returns a table of data backed by a Comma Separated Value file. This allows scripts to depend on data sets that can be helpful for more realistic testing, such as using a different username/password to login to a website each time the script runs.

Parameters:
name - the name of the CSV file, which you will be asked to upload upon saving your script.
Returns:
an object that represents the CSV table.

fileToCSV

CSVTable fileToCSV(DataFile dataFile)
Creates and returns a table of data backed by a Comma Separated Value File. This allows scripts to depend on data sets that can be helpful for more realistic testing, such as using a different username/password to login to a website each time the script runs.

Parameters:
dataFile - the name of the CSV file, which you will be asked to upload upon saving your script.
Returns:
an object that represents the CSV table.

datafile

DataFile datafile(java.lang.String name)
Returns a wrapped handle to an uploaded file. This is useful for reading file contents in scripts and for use in multipart post requests. For details on adding the file to a post request, see HttpRequest.addFileUpload(String, DataFile).

Parameters:
name - the filename, which you will be asked to upload upon saving your script.
Returns:
an object that represents the file.

startTimeoutTimer

void startTimeoutTimer(long timeoutInMs)
                       throws java.lang.Exception
Starts a timer that runs until timeoutInMs is reached, and if it has been reached, will terminate the running script.

Future calls to this function does nothing to the timer; it must be stopped and started again.

A timeoutInMs that is 0 or negative will stop the timer.

Parameters:
timeoutInMs - the total time the script should wait before timing out
Throws:
java.lang.Exception - thrown when timeoutInMs is non-positive.

stopTimeoutTimer

void stopTimeoutTimer()
Stops the timeout timer, if it was started.


waitForNetworkTrafficToStop

void waitForNetworkTrafficToStop(long quietPeriodInMs,
                                 long timeoutInMs)
Waits until no HTTP traffic associated with the current test has taken place for at least quietPeriodInMs. If this function has to wait for longer than timeoutInMs an error will be thrown, causing the transaction to fail.

This function will generally, but not always, result in a pause time equal to the length of quietPeriodInMs, since it will need to wait that long to determine if no network traffic has taken place.

Parameters:
quietPeriodInMs - the period of time that we expect to not see any HTTP traffic.
timeoutInMs - the total time the function should wait before giving up and throwing an error.

findRegexMatches

java.lang.String[] findRegexMatches(java.lang.String content,
                                    java.lang.String regex)
A simple way to find one or more regular expression matches against some content. For example, the following code will extract all the text between any span tag that has a class of "foo":
 var matches = test.findRegexMatches(resp.getBody(), '<span class="foo">([^<]*)<span>');
 

Parameters:
content - the content to match against.
regex - the regular expression to match, which should include one and only one regular expression group.
Returns:
an array of sub-strings from the content that match the supplied regular expression

time

void time(java.lang.String name)
Starts a timer you can use to track how long an operation takes. If a timer has already started, it cannot be stopped. At the moment, no more than 25 timers can be started.

Usage:


 

Parameters:
name - the name of the timer

timeEnd

long timeEnd(java.lang.String name)
Ends and logs a timer if it exists

Parameters:
name - the timer's name
Returns:
the timing, or -1 if no timer was ever started.

waitFor

boolean waitFor(NativeFunction callback,
                long timeoutInMs)
Wait for the user specified function to return true. If this function has to wait longer than timeoutInMs then false will be returned. The arguments passed in must be in in this form:
 test.waitFor(function() {
     // Determine if the waitFor condition is satisfied and return a boolean value
     return isConditionSatisfied;
 }, 3000);
 

Parameters:
callback - the javascript function, in the form of function() { ... }
timeoutInMs - the total time the function should wait before giving up and returning false.
Returns:
true if the condition is met before the timeout, false if the timeout is reached

assertTrue

void assertTrue(boolean assertion,
                java.lang.String message)
Assert that the given condition is true. If the condition is false the script will throw an exception and an error will be logged.
   test.assertTrue(webElement != null, "Element not found");
 

Parameters:
assertion - the condition
message - the script error message to be logged when the condition is false.

assertTrue

void assertTrue(boolean assertion)
Assert that the given condition is true. If the condition is false the script will throw an exception and an error will be logged.
   test.assertTrue(webElement != null);
 

Parameters:
assertion - the condition

assertFalse

void assertFalse(boolean assertion,
                 java.lang.String message)
Assert that the given condition is false. If the condition is true the script will throw an exception and an error will be logged.
   test.assertFalse(webElement != null, "Element found when it should be removed");
 

Parameters:
assertion - the condition
message - the script error message to be logged when the condition is false.

assertFalse

void assertFalse(boolean assertion)
Assert that the given condition is false. If the condition is true the script will throw an exception and an error will be logged.
   test.assertFalse(webElement != null);
 

Parameters:
assertion - the condition

fail

void fail()
Fails the test by throwing an exception.

See Also:
   test.fail();
 
Similar to:
     throw "script failed!";
 

fail

void fail(java.lang.String message)
Fails the test with a message by throwing exception with the given message.

Parameters:
message - the script error message to be logged.
See Also:
   test.fail("cache is not cleared!");
 
Similar to:
     throw "script failed! cache is not cleared!";
 

assertEquals

void assertEquals(java.lang.Object expected,
                  java.lang.Object actual)
Assert that two values are equal. If the expected value does not match the actual value the script will throw an exception and an error will be logged.
   test.assertEquals("Swiss Cheese", webElement.getText());
 
The order of the expected and actual values matter for the error message:
   test.assertEquals("hello1", "hello2");
 
Produces the error message:
   assertEquals() failed! Expected 'hello1' but was 'hello2'.
 

Parameters:
expected - the expected value
actual - the actual value

assertEquals

void assertEquals(java.lang.Object expected,
                  java.lang.Object actual,
                  java.lang.String message)
Assert that two values are equal. If the expected value does not match the actual value the script will throw an exception and an error will be logged.
   test.assertEquals("Swiss Cheese", webElement.getText(), "They're not equal!");
 

Parameters:
expected - the expected value
actual - the actual value
message - the script error message to be logged.

assertNotEquals

void assertNotEquals(java.lang.Object expected,
                     java.lang.Object actual)
Assert that two values are not equal. If the expected value matches the actual value the script will throw an exception and an error will be logged.

Parameters:
expected - the expected value
actual - the actual value

assertNotEquals

void assertNotEquals(java.lang.Object expected,
                     java.lang.Object actual,
                     java.lang.String message)
Assert that two values are not equal. If the expected value matches the actual value the script will throw an exception and an error will be logged.

Parameters:
expected - the expected value
actual - the actual value
message - the script error message to be logged.

assertThrown

void assertThrown(NativeFunction function)
Assert that the running the JS function threw an exception when run, otherwise an exception is thrown.
   test.assertThrown(function() {
       throw "foo bar baz"
   });
 

Parameters:
function - the js function

assertThrown

void assertThrown(java.lang.String exceptionMessage,
                  NativeFunction function)
Assert that the running the JS function threw an exception when run. If the exception does not contain the given message or was not thrown, an exception will be thrown.
   test.assertThrown(function() {
       throw "foo bar baz"
   }, "bar");
 

Parameters:
exceptionMessage - the message to check in the exception
function - the js function

loadTestSettings

LoadTestSettings loadTestSettings()
Get load testing specific settings, these settings have no effect while monitoring.

Returns:
the load test settings.

globalPause

void globalPause(long minTimeInMS,
                 long maxTimeInMS)
Sleep between steps. Sleep time would be a random number of milliseconds between the parameters 'min' and 'max.

Parameters:
minTimeInMS - minimum pause duration in ms
maxTimeInMS - maximum pause duration in ms

globalPause

void globalPause(long pauseTimeInMs)
Sleep between steps for the duration passed in param.

Parameters:
pauseTimeInMs - duration in ms

getVersion

java.lang.String getVersion()
Return the Test Scripts API version.

Returns:
the version of the scripting API

forEach

void forEach(java.lang.Object o,
             NativeFunction function)
Loops through a list/map, applying the function to each element.
     test.forEach([1, 2, 3], function(element) {
        // do something with each element
     });
 
     test.forEach({hello: 'world', foo: 'bar'}, function(key, value) {
        // do something with each key/value
     });
 

Parameters:
o - the list/map
function - the function

chromeoptions

BrowserchromeOptions chromeOptions()
Options that you can use to customize and configure a ChromeDriver session.

Returns:

firefoxoptions

BrowserfirefoxOptions firefoxOptions()
It is used to control the behaviour of Firefox.

Returns:


Copyright © 2020 Neustar, Inc. All Rights Reserved.