{"id":243,"date":"2009-06-09T09:03:09","date_gmt":"2009-06-09T13:03:09","guid":{"rendered":"http:\/\/www.webperformanceinc.com\/load_testing\/blog\/?p=243"},"modified":"2010-08-19T16:27:21","modified_gmt":"2010-08-19T20:27:21","slug":"how-to-dynamic-field-names-and-multi-variable-extractors","status":"publish","type":"post","link":"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/2009\/06\/how-to-dynamic-field-names-and-multi-variable-extractors\/","title":{"rendered":"How-To: Dynamic Field Names and Multi-Variable Extractors"},"content":{"rendered":"<p><strong>Overview<\/strong><\/p>\n<p>You&#8217;re recording test cases, configuring them, replaying them, and running load tests.\u00a0 One day, you attempt to test a new web application.\u00a0 However, every time you attempt to run a replay, the replay throws an extractor error; it is unable to find a field in the page content of the replay to extract.\u00a0 ASM configured this field automatically, so why isn&#8217;t it working?\u00a0 You look at the replay content &#8230; and the field name isn&#8217;t there.<\/p>\n<p>The usual culprit that causes this problem is a <em>dynamic field name<\/em>: a variable in a dynamic web page that not only changes in value, but also varies in name.\u00a0 For example, on one page the first row of data includes a field named &#8220;Item45&#8221;, while in the replay with a different user and a different search term, that field is named &#8220;Item56&#8221;.\u00a0 This name and the value are then resubmitted to the webserver as a JSON field or a query parameter in the next request, so it must be extracted &#8211; but ASM doesn&#8217;t do it, because it can&#8217;t find the original field name.\u00a0 Dynamic field names are very common in applications that handle lists of data that are generated on the fly from a database query.<\/p>\n<p>In such a case, Load Tester must be configured to deal with the situation by extracting the name of the field <em>and<\/em> the value of the field into user-created variables.\u00a0 Before tackling this tutorial, you should already be familiar with Load Tester&#8217;s recording process and test case customization, and you should be familiar with regular expressions. There are a series of steps involved in the process of configuring Load Tester to handle dynamic field names.<\/p>\n<p><strong>Step 1: Stop ASM from handling these fields<\/strong><\/p>\n<p>First, you need to identify and disable the ASM automated processing of the problem fields.\u00a0 So &#8230; how do you tell which of these fields are problems?\u00a0 One way is to simply replay the test case until you get an extractor error.\u00a0 If you compare the content from the recording with the content from the replay and the field names change, then you have a strong candidate on your hands.\u00a0 For example, if in the recording the field name is &#8220;Item45&#8221;, and in the replay the field name is &#8220;Item56&#8221;, then there is a good chance the field name is dynamic, and you&#8217;ll need to stop ASM from trying to extract it.<\/p>\n<p>This is accomplished by selecting the &#8220;Expert Options&#8221; checkbox when configuring a test case for replay, and then choosing the &#8220;Guided Configuration&#8221; radio button under Application State Management.\u00a0 (You can also reach this screen by running ASM by itself.)\u00a0 The analysis will complete, and then a list of fields will be displayed.\u00a0 Select one or more fields, and then select the &#8220;Never Extract&#8221; radio button on the right.\u00a0 The icon next to the field will change and indicate that the field will not be handled automatically.\u00a0 ASM will not retain this information unless you completely configure the fields using an extractor and setting the field name and value; you will get a warning in the next run of ASM that there are pre-configured fields that it thinks it should ignore.\u00a0 If you configure fields to be ignored, but you don&#8217;t finish the configuration, you will have to reset the &#8220;Never Extract&#8221; flag the next time you run ASM on the test case.<\/p>\n<div id=\"attachment_298\" style=\"width: 500px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-298\" class=\"size-full wp-image-298\" title=\"asm_wizard1\" src=\"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2009\/06\/asm_wizard1.png\" alt=\"Configuring ASM to ignore fields\" width=\"490\" height=\"411\" srcset=\"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2009\/06\/asm_wizard1.png 490w, https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2009\/06\/asm_wizard1-300x251.png 300w\" sizes=\"auto, (max-width: 490px) 100vw, 490px\" \/><p id=\"caption-attachment-298\" class=\"wp-caption-text\">Configuring ASM to ignore fields<\/p><\/div>\n<p><strong>Step 2: Set up an extractor to get the field name and the field value<\/strong><\/p>\n<p>Next, set up an extractor to get the field name and the value.\u00a0 You can do this with two extractors; however, it is quicker and easier to use a multi-variable extractor to get them both at the same time.<\/p>\n<p>A multi-variable extractor must use regular expressions, as we will need to specify two or more selection groups.\u00a0 Here&#8217;s an example of a configured multi-variable extractor:<\/p>\n<div id=\"attachment_259\" style=\"width: 564px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-259\" class=\"size-full wp-image-259\" title=\"extractor_dialog\" src=\"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2009\/06\/extractor_dialog.png\" alt=\"Configuring a a multi-variable extractor\" width=\"554\" height=\"709\" srcset=\"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2009\/06\/extractor_dialog.png 554w, https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2009\/06\/extractor_dialog-234x300.png 234w\" sizes=\"auto, (max-width: 554px) 100vw, 554px\" \/><p id=\"caption-attachment-259\" class=\"wp-caption-text\">Configuring a a multi-variable extractor<\/p><\/div>\n<p>This can initially be confusing, so lets go over it piece by piece.\u00a0 First, you select Regular Expressions as your extractor type (highlight 1).\u00a0 Then, you enter in the regular expression to identify your field name and value (highlight 2).\u00a0 A full discussion of regular expressions is beyond the scope of this post, but I want to point out two important things:\u00a0 first,\u00a0 notice the escape codes for DOS line termination in the regular expression (\\r\\n).\u00a0 Which ones you might have to use will depend on what software created the document, and it may not be immediately obvious.\u00a0 Second, when you set up a regular expression like this, note in highlight 3 that there is an instance number.\u00a0 If your regular expression has more than one match in the page content, the instance number is how you control which values are extracted.\u00a0 This is an important time-saver: if you build the regular expression correctly, you can cut and paste extractors (using the Edit menu) and simply change the instance number and variable names to get the next set of values that match.\u00a0 Conversely, don&#8217;t try to be too general &#8211; if you have two significantly different instances to extract, simply create another extractor.<\/p>\n<div id=\"attachment_299\" style=\"width: 560px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-299\" class=\"size-full wp-image-299\" title=\"extractor_dialog_highlighted1\" src=\"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2009\/06\/extractor_dialog_highlighted1.png\" alt=\"Details of extractor configuration\" width=\"550\" height=\"706\" srcset=\"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2009\/06\/extractor_dialog_highlighted1.png 550w, https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2009\/06\/extractor_dialog_highlighted1-233x300.png 233w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><p id=\"caption-attachment-299\" class=\"wp-caption-text\">Details of extractor configuration<\/p><\/div>\n<p>In highlight 4, you can see that two variables names are entered with a space between them.\u00a0 These variables will be matched up to the regular expression selection groups; the first selection group goes to the first variable, the second selection group goes to the second variable, etc.\u00a0 What values are actually selected by the combination of instance number and selection group is shown in highlights 5, 6, and 7, with 5 and 6 identifying the match inside the content and highlight 7 giving you a summary list of everything being extracted.<\/p>\n<p><strong>Step 3: Inserting extracted data back into the test case<\/strong><\/p>\n<p>Next, you need to insert the extracted data into the fields that we told ASM not to automate.\u00a0 This is done by double clicking the M? cell in the Fields view, and then setting <em>both<\/em> the field name and the variable name in the dialog.\u00a0 The highlight below shows the example fields.\u00a0 The M? cell would be blank for a field that has not been configured; the green arrow icon indicates that the field has been automated.\u00a0 Fields that have been automated by ASM have a &#8220;#&#8221; character at the beginning of the variable name.<\/p>\n<div id=\"attachment_263\" style=\"width: 548px\" class=\"wp-caption alignnone\"><strong><\/strong><strong><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-263\" class=\"size-full wp-image-263\" title=\"fields_dialog\" src=\"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2009\/06\/fields_dialog.png\" alt=\"Inserting extracted data into fields\" width=\"538\" height=\"368\" srcset=\"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2009\/06\/fields_dialog.png 538w, https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2009\/06\/fields_dialog-300x205.png 300w\" sizes=\"auto, (max-width: 538px) 100vw, 538px\" \/><\/strong><p id=\"caption-attachment-263\" class=\"wp-caption-text\">Inserting extracted data into fields<\/p><\/div>\n<p>Once you double-click the M? cell, you will get a dialog that looks like this:<\/p>\n<div id=\"attachment_300\" style=\"width: 447px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-300\" class=\"size-full wp-image-300\" title=\"configure_fields_value1\" src=\"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2009\/06\/configure_fields_value1.png\" alt=\"Configuring a field value variable\" width=\"437\" height=\"329\" srcset=\"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2009\/06\/configure_fields_value1.png 437w, https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2009\/06\/configure_fields_value1-300x225.png 300w\" sizes=\"auto, (max-width: 437px) 100vw, 437px\" \/><p id=\"caption-attachment-300\" class=\"wp-caption-text\">Configuring a field value variable<\/p><\/div>\n<p>Change the Value of the field to User Variable, and enter the name of the value variable you chose.\u00a0 Once that is done click on the Name tab and do the same thing with the name variable you chose:<\/p>\n<div id=\"attachment_301\" style=\"width: 447px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-301\" class=\"size-full wp-image-301\" title=\"configure_fields_name1\" src=\"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2009\/06\/configure_fields_name1.png\" alt=\"Configuring a field name variable\" width=\"437\" height=\"330\" srcset=\"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2009\/06\/configure_fields_name1.png 437w, https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-content\/uploads\/2009\/06\/configure_fields_name1-300x226.png 300w\" sizes=\"auto, (max-width: 437px) 100vw, 437px\" \/><p id=\"caption-attachment-301\" class=\"wp-caption-text\">Configuring a field name variable<\/p><\/div>\n<p>In this way, both the name of the field and the value of the field are extracted and substituted &#8211; each replay and each virtual test case run will be different based on the page content returned from the site.\u00a0 Unfortunately, there is currently no way to get a list of your user variables, so in a complex test case you will need to utilize a naming convention like I&#8217;ve done here, or keep track of your variables by hand.\u00a0 Also, when you are cutting and pasting extractors, make sure you change both the instance number and the target variable names, so that each extracted set of variables has a set of unique names.<\/p>\n<p>If you have questions or comments about this blog entry, please post a comment, contact us directly, or submit a support request via the Support Request tool inside Load Tester.\u00a0 Happy testing!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview<br \/>\nYou&#8217;re recording test cases, configuring them, replaying them, and running load tests.\u00a0 One day, you attempt to test a new web application.\u00a0 However, every time you attempt to run a replay, the replay throws an extractor error; it is unable to find a field in the page content of the replay to extract.\u00a0 ASM configured this field automatically, so why isn&#8217;t it working?\u00a0 You look at the replay content &#8230; and the field name isn&#8217;t there.<br \/>\nThe usual culprit that causes this problem is a dynamic field name: a variable in a dynamic web page that not only changes in value, &hellip; <a href=\"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/2009\/06\/how-to-dynamic-field-names-and-multi-variable-extractors\/\">Continue reading &raquo;<\/a><\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,8],"tags":[52,53,237,51],"class_list":["post-243","post","type-post","status-publish","format-standard","hentry","category-ajax","category-load-testing","tag-dynamic-field","tag-extractor","tag-load-testing","tag-web-performance-load-tester"],"_links":{"self":[{"href":"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-json\/wp\/v2\/posts\/243","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\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-json\/wp\/v2\/comments?post=243"}],"version-history":[{"count":25,"href":"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-json\/wp\/v2\/posts\/243\/revisions"}],"predecessor-version":[{"id":276,"href":"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-json\/wp\/v2\/posts\/243\/revisions\/276"}],"wp:attachment":[{"href":"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-json\/wp\/v2\/media?parent=243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-json\/wp\/v2\/categories?post=243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webperformance.com\/load-testing-tools\/blog\/wp-json\/wp\/v2\/tags?post=243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}