Generating Dynamic UUID with a Javascript Data Source - Web Performance
Menu

Generating Dynamic UUID with a Javascript Data Source

We recently had a customer question on how to dynamically generate UUIDs during a load test, and the answer illustrates two interesting techniques in Load Tester:

  1. How to use javascript to dynamically generate data during a test.
  2. How to make call outs to the more extensive Java functions within javascript.

In this example let’s assume the UUID is being used as a path element that you want to dynamically replace during a test like this:

http://mysite/path1/123e4567-e89b-12d3-a456-426614174000

Like much of the test case configuration in Load Tester, the process to edit the dynamic behavior starts in the Fields View.   Click on the URL to select what you’re editing, and then navigate to the Fields View.

 

If you’re editing a regular field then you can proceed directly to editing the field, but since this example is using a PATH element then you’ll need to put the Fields View into PATH view mode by selecting a pulldown on the right:


The different PATH elements in the URL you selected are now broken out so you can configure them separately.  Double click on the PATH element you want to configure and select a datasource of type “script” as shown below:

The return value for the function getValue(user_state) will be substituted every time this URL is called during the load test.  You can use any valid javascript for that function, or even add additional helper functions, etc, as long as the values you want are being returned from getValue().  The javascript dialog dynamically executes the javascript for you as you type, placing the return value in the results box as shown.

The trick shown here for the UUID is that javascript doesn’t have a UUID function, but Java does.   Luckily javascript can call the Java UUID function by using java.util as a prefix:

function getValue(user_state)
{
return java.util.UUID.randomUUID();
}

This technique is quite powerful and can be a big help with all sorts of tricky situations with the more complex web-based applications.

 

Add Your Comment

You must be logged in to post a comment.

Resources

Copyright © 2024 Web Performance, Inc.

A Durham web design company

×

(1) 919-845-7601 9AM-5PM EST

Just complete this form and we will get back to you as soon as possible with a quote. Please note: Technical support questions should be posted to our online support system.

About You
How Many Concurrent Users