{"id":6290,"date":"2020-05-18T11:46:20","date_gmt":"2020-05-18T15:46:20","guid":{"rendered":"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/?p=6290"},"modified":"2025-04-04T10:02:52","modified_gmt":"2025-04-04T14:02:52","slug":"generating-dynamic-uuid-with-a-javascript-data-source","status":"publish","type":"post","link":"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/2020\/05\/generating-dynamic-uuid-with-a-javascript-data-source\/","title":{"rendered":"Generating Dynamic UUID with a Javascript Data Source"},"content":{"rendered":"<p>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:<\/p>\n<ol>\n<li>How to use javascript to dynamically generate data during a test.<\/li>\n<li>How to make call outs to the more extensive Java functions within javascript.<\/li>\n<\/ol>\n<p>In this example let&#8217;s assume the UUID is being used as a path element that you want to dynamically replace during a test like this:<\/p>\n<p><code>http:\/\/mysite\/path1\/123e4567-e89b-12d3-a456-426614174000<\/code><\/p>\n<p>Like much of the test case configuration in Load Tester, the process to edit the dynamic behavior starts in the Fields View. \u00a0 Click on the URL to select what you&#8217;re editing, and then navigate to the Fields View.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2020\/05\/Screen-Shot-2020-05-18-at-10.27.45-AM-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6292\" src=\"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2020\/05\/Screen-Shot-2020-05-18-at-10.27.45-AM-1.png\" alt=\"\" width=\"600\" height=\"230\" \/><\/a><\/p>\n<p>If you&#8217;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&#8217;ll need to put the Fields View into PATH view mode by selecting a pulldown on the right:<\/p>\n<p><a href=\"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2020\/05\/Screen-Shot-2020-05-18-at-10.31.40-AM.png\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6293\" src=\"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2020\/05\/Screen-Shot-2020-05-18-at-10.31.40-AM.png\" alt=\"\" width=\"600\" height=\"188\" \/><\/a><\/p>\n<p>The different PATH elements in the URL you selected are now broken out so you can configure them separately. \u00a0Double click on the PATH element you want to configure and select a datasource of type &#8220;script&#8221; as shown below:<\/p>\n<p><a href=\"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2020\/05\/Screen-Shot-2020-05-18-at-10.36.05-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6294\" src=\"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2020\/05\/Screen-Shot-2020-05-18-at-10.36.05-AM.png\" alt=\"\" width=\"600\" height=\"459\" \/><\/a><\/p>\n<p>The return value for the function getValue(user_state) will be substituted every time this URL is called during the load test. \u00a0You 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(). \u00a0The javascript dialog dynamically executes the javascript for you as you type, placing the return value in the results box as shown.<\/p>\n<p>The trick shown here for the UUID is that javascript doesn&#8217;t have a UUID function, but Java does. \u00a0 Luckily javascript can call the Java UUID function by using java.util as a prefix:<\/p>\n<p>function getValue(user_state)<br \/>\n{<br \/>\nreturn java.util.UUID.randomUUID();<br \/>\n}<\/p>\n<p>This technique is quite powerful and can be a big help with all sorts of tricky situations with the more complex web-based applications.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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:<\/p>\n<p>How to use javascript to dynamically generate data during a test.<br \/>\nHow to make call outs to the more extensive Java functions within javascript.<\/p>\n<p>In this example let&#8217;s assume the UUID is being used as a path element that you want to dynamically replace during a test like this:<br \/>\nhttp:\/\/mysite\/path1\/123e4567-e89b-12d3-a456-426614174000<br \/>\nLike much of the test case configuration in Load Tester, the process to edit the dynamic behavior starts in the Fields View. \u00a0 Click on the URL to select &hellip; <a href=\"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/2020\/05\/generating-dynamic-uuid-with-a-javascript-data-source\/\">Continue reading &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,8,42],"tags":[332,334,239,237,338,336],"class_list":["post-6290","post","type-post","status-publish","format-standard","hentry","category-ajax","category-load-testing","category-load-tester-software","tag-data-source","tag-datasource","tag-javascript","tag-load-testing","tag-scripted-data-source","tag-scripted-datasource"],"_links":{"self":[{"href":"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-json\/wp\/v2\/posts\/6290","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-json\/wp\/v2\/comments?post=6290"}],"version-history":[{"count":4,"href":"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-json\/wp\/v2\/posts\/6290\/revisions"}],"predecessor-version":[{"id":6298,"href":"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-json\/wp\/v2\/posts\/6290\/revisions\/6298"}],"wp:attachment":[{"href":"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-json\/wp\/v2\/media?parent=6290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-json\/wp\/v2\/categories?post=6290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-json\/wp\/v2\/tags?post=6290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}