{"id":42339,"date":"2016-12-05T17:51:46","date_gmt":"2016-12-05T12:21:46","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=42339"},"modified":"2016-12-06T11:12:27","modified_gmt":"2016-12-06T05:42:27","slug":"advance-use-case-of-load-testing-using-jmeter","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/advance-use-case-of-load-testing-using-jmeter\/","title":{"rendered":"Advance Use Case of Load Testing Using JMeter"},"content":{"rendered":"<p><strong>Apache JMeter<\/strong>, an open-source product developed in Java used to perform <a title=\"7 Things You Must Know About Load-Testing Using JMeter\" href=\"http:\/\/www.tothenew.com\/blog\/7-things-you-must-know-about-load-testing-using-jmeter\/\">load testing<\/a> of web applications and simulate user load with various parameters like a real-life scenario.<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-42435\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/logo-jmeter.png\" alt=\"logo-jmeter\" width=\"208\" height=\"69\" \/><\/p>\n<p>There were few use cases that I came across while performing load testing on my project.<br \/>\nThese are simple and often very <a title=\"Automated testing services\" href=\"http:\/\/www.tothenew.com\/testing\/automated-independent-manual-testing\" target=\"_blank\">helpful in performing tests<\/a> on daily basis. Also, it can be cumbersome if not understood properly before performing.<\/p>\n<p><strong>What to expect in this Blog ?<\/strong><\/p>\n<p>1) Scheduler Configuration in Thread Group<br \/>\n2)\u00a0Get Hidden HTML Form Values<br \/>\n3) While Controller over CSV file<br \/>\n4)\u00a0Counter Config Element<br \/>\n5) HTTP Recording (using JMeter and Blazemeter)<\/p>\n<p><strong>1) Scheduler Configuration in Thread Group<br \/>\n<\/strong>The Scheduler Configuration of <a title=\"JMeter Master Slave Setup In Multiple AWS Regions\" href=\"http:\/\/www.tothenew.com\/blog\/jmeter-master-slave-setup-in-multiple-aws-regions\/\" target=\"_blank\">JMeter<\/a>, part of Thread Group allows to schedule the test plan to run at a specific time and for a particular amount of time.<\/p>\n<p>The Scheduler Configuration works according to the Linux timezone of the shell in which the script also runs.<\/p>\n<p>To use this, check the field &#8220;Scheduler&#8221; in Thread Group and set the Loop Count &#8220;Forever&#8221;.<\/p>\n<p>There are four parameters :-<br \/>\n<strong>\u00a0 \u00a0 i) Start Time<\/strong> : The time at which the script will start running.<br \/>\n<strong>\u00a0 \u00a0 ii) End Time<\/strong> \u00a0: The time at which the script will finish its execution and shut down all its threads.<br \/>\n<strong>Note &#8211;<\/strong> Keep Start Time and End Time as same as they will be modified according to the below two parameters :-<br \/>\n<strong>\u00a0 \u00a0 iii) Duration (seconds)<\/strong> : The duration in seconds for which the script will run, this overrides the End Time of the script.<br \/>\n<strong>\u00a0 \u00a0 iv) Startup Delay (seconds)<\/strong> : Time in seconds that script must wait before starting its execution, this overrides the Start Time.<\/p>\n<p>Let&#8217;s schedule a script to run for 30 minutes (1800 seconds) and start at a particular time :<\/p>\n<p><strong>Firstly, check the Linux\u00a0timestamp &#8211;<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-42353\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/date-for-scheduler.png\" alt=\"date\" width=\"272\" height=\"34\" \/><\/p>\n<p><strong>Scheduler Configuration-<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-42433\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/scheduler-configuration1.png\" alt=\"scheduler-configuration-jmeter\" width=\"827\" height=\"414\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/scheduler-configuration1.png 827w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/scheduler-configuration1-300x150.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/scheduler-configuration1-624x312.png 624w\" sizes=\"(max-width: 827px) 100vw, 827px\" \/><\/p>\n<p>Set Start and End Time accordingly, for example, &#8220;2016\/11\/22 09:05:09&#8221; and Duration : 1800.<\/p>\n<p>If this JMX script will be running on a\u00a0server, then it becomes\u00a0burdensome to make changes in UI locally and then upload the script to the server.<br \/>\nBetter approach is to edit the JMX file :<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-42357\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/jmx-start-and-end-time.png\" alt=\"jmx-start-and-end-time\" width=\"669\" height=\"122\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/jmx-start-and-end-time.png 669w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/jmx-start-and-end-time-300x54.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/jmx-start-and-end-time-624x113.png 624w\" sizes=\"(max-width: 669px) 100vw, 669px\" \/><\/p>\n<p>The start and end time is stored as <strong>epoch time<\/strong> in <strong>milliseconds<\/strong> (Here, 147978570900) in the JMX file.<\/p>\n<p>To find out epoch time use\u00a0http:\/\/www.epochconverter.com\/\u00a0, calculate the time and modify these parameters accordingly.<\/p>\n<p>Now run the script, it will automatically start at the specified time ( Here, 2016\/11\/22 09:05:09 ) and will run for 30 minutes.<\/p>\n<p><strong>2) Get Hidden HTML Form Values<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-42363\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/hidden-field.png\" alt=\"hidden input field\" width=\"999\" height=\"321\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/hidden-field.png 999w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/hidden-field-300x96.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/hidden-field-624x200.png 624w\" sizes=\"(max-width: 999px) 100vw, 999px\" \/><\/p>\n<p>Suppose, hidden input field value named &#8220;lsd&#8221; is required from facebook.com&#8217;s login form.<\/p>\n<p><strong>Note<\/strong>: This value changes at run-time.<\/p>\n<p>To get this value,\u00a0XPath Extractor from Post Processors will be required in an HTTP Request, which uses XPath Query Language.<\/p>\n<p>To get basic understanding of\u00a0XPath Query Language follow this link : \u00a0http:\/\/www.w3schools.com\/xml\/xpath_syntax.asp<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-42367\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/XPath-Extractor.png\" alt=\"XPath Extractor\" width=\"1090\" height=\"311\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/XPath-Extractor.png 1090w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/XPath-Extractor-300x85.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/XPath-Extractor-1024x292.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/XPath-Extractor-624x178.png 624w\" sizes=\"(max-width: 1090px) 100vw, 1090px\" \/><\/p>\n<p>This is the <strong>XPath query<\/strong> used to get value of &#8220;lsd&#8221; named hidden field :<\/p>\n<p><strong>&#8220;\/\/input[@type=&#8221;hidden&#8221;][@name=&#8221;lsd&#8221;]\/@value&#8221;<\/strong><\/p>\n<p>XPath parses XML so check &#8220;Use Tidy (tolerant parser)&#8221; \u00a0to convert the returned HTML response in XTML.<br \/>\nThe value got stored in reference name test, which can be used later as &#8220;${test}&#8221;.<br \/>\nIn next HTTP request name is passed as ${test} and on running the test the value is returned as &#8220;AVpDFtW9&#8221; :<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-42370\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/extracted-value.png\" alt=\"Extracted Value\" width=\"1089\" height=\"178\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/extracted-value.png 1089w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/extracted-value-300x49.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/extracted-value-1024x167.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/extracted-value-624x101.png 624w\" sizes=\"(max-width: 1089px) 100vw, 1089px\" \/><\/p>\n<p><strong>2) While Controller over CSV<br \/>\n<\/strong>If there are multiple URLs for a domain that are supposed to be tested for a particular load. So, instead of using separate HTTP Request Sampler for each request a while controller can be used with CSV while containing the URL Paths.<br \/>\nIt becomes very convenient to edit the URL Paths as they are changed according to the requirements.<br \/>\nFor setting up this, a While Controller, CSV Data Set Config, HTTP Request Sampler, HTTP Request Defaults and a file containing URL paths will be required.<\/p>\n<p><strong>\u00a0 \u00a0 i) CSV file containing URL Paths<\/strong> :<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-42390\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/while-urls.png\" alt=\"URL Paths\" width=\"134\" height=\"98\" \/><\/p>\n<p><strong>\u00a0 \u00a0 ii) Configuring CSV Data Set Config<\/strong> :<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-42389\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/csv-data-set.png\" alt=\"csv data set config\" width=\"1090\" height=\"284\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/csv-data-set.png 1090w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/csv-data-set-300x78.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/csv-data-set-1024x266.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/csv-data-set-624x162.png 624w\" sizes=\"(max-width: 1090px) 100vw, 1090px\" \/>Specify the file path, Variable Names (Ex: PATH, which will be later used as ${PATH} in HTTP Request and in While Controller), Delimiter and other configurations.<\/p>\n<p><strong>\u00a0 \u00a0 iii) While Controller<\/strong> :<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-42391\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/while-controller.png\" alt=\"while-controller\" width=\"826\" height=\"111\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/while-controller.png 826w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/while-controller-300x40.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/while-controller-624x83.png 624w\" sizes=\"(max-width: 826px) 100vw, 826px\" \/><\/p>\n<p>Condition is the basis on which the while loop in Jmeter will work.<\/p>\n<p>Here, it works till there exists paths in the csv file.<\/p>\n<p><strong>\u00a0 \u00a0 iv) Now specify the Path in HTTP Request as<\/strong> :<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-42394\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/HTTP_Request.png\" alt=\"HTTP Request Jmeter\" width=\"810\" height=\"212\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/HTTP_Request.png 810w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/HTTP_Request-300x78.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/HTTP_Request-624x163.png 624w\" sizes=\"(max-width: 810px) 100vw, 810px\" \/><\/p>\n<p><strong>\u00a0 \u00a0 v) Output of above configured script is as follows<\/strong> :<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-42395\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/output-of-while.png\" alt=\"output-of-while-loop\" width=\"827\" height=\"217\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/output-of-while.png 827w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/output-of-while-300x78.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/output-of-while-624x163.png 624w\" sizes=\"(max-width: 827px) 100vw, 827px\" \/><\/p>\n<p>It successfully read 5 URL paths specified in the CSV file.<\/p>\n<p><strong>3) Counter Config Element<br \/>\n<\/strong>The counter is used to generate values in a particular format at particular intervals.<br \/>\nThese generated values can be used for sign up process to create multiple users each with a username followed by a particular value.<\/p>\n<p>Example : vaibhav.[1-100]@tothenew.com<\/p>\n<p>Here are some parameters\u00a0:-<br \/>\n<strong>\u00a0 \u00a0 i) Start<\/strong> : The starting value of the range from which counter should generate values<br \/>\n<strong>\u00a0 \u00a0 ii) Increment<\/strong> : At what intervals it should increment the values<br \/>\n<strong>\u00a0 \u00a0 iii) Maximum<\/strong> : The end limit of the range till which counter should generate values<br \/>\n<strong>\u00a0 \u00a0 iv) Number format<\/strong> : The format in which the numbers should be generated, Ex &#8220;0&#8221;, it generates values in the format 1,2,3 etc<\/p>\n<p>If it is specified as &#8220;00&#8221;, the values generated are 01,02,03,etc.<\/p>\n<p><strong>4)\u00a0HTTP Recording (using JMeter and Blazemeter)<br \/>\n<\/strong><strong>\u00a0 \u00a0 i) JMeter Recording\u00a0<\/strong>: JMeter comes with a wonderful feature of <strong>recording controller<\/strong> which helps to record the entire flow of websites as the links are clicked in the browser as HTTP requests.<\/p>\n<p>To set-up HTTP recording :<\/p>\n<p>Firstly create a Thread Group.<br \/>\nThen, HTTP request defaults of the website for which the UX is to be recorded.<br \/>\nAdd recording controller\u00a0within the Thread Group.<br \/>\nNext step is to set HTTP(S) Test Script Recorder in WorkBench and specify the port (Let&#8217;s say 8080).<\/p>\n<p>Specify the network proxy in Firefox for port 8080 :<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-42372\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/proxy-firefox.png\" alt=\"proxy firefox 8080\" width=\"540\" height=\"652\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/proxy-firefox.png 540w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/proxy-firefox-248x300.png 248w\" sizes=\"(max-width: 540px) 100vw, 540px\" \/><\/p>\n<p>Start the <strong>HTTP(S) Test Script Recorder<\/strong> and hit the required page in the\u00a0browser.<\/p>\n<p>Now see that results are flooded in the recording controller:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-42375\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/tothenew-http-recording.png\" alt=\"Recording Controller Results\" width=\"1093\" height=\"614\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/tothenew-http-recording.png 1093w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/tothenew-http-recording-300x168.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/tothenew-http-recording-1024x575.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/tothenew-http-recording-624x350.png 624w\" sizes=\"(max-width: 1093px) 100vw, 1093px\" \/><\/p>\n<p><strong>\u00a0 \u00a0 ii) Blazemeter<\/strong> :<br \/>\nTo save time and efforts of adding proxy and different controllers as in JMeter.<br \/>\nThere is an online application namely Blazemeter available in Chrome store, here&#8217;s the link :\u00a0https:\/\/chrome.google.com\/webstore\/detail\/blazemeter-the-load-testi\/mbopgmdnpcbohhpnfglgohlbhfongabi?utm_source=chrome-ntp-icon<\/p>\n<p>Once it is downloaded and sign up credentials are provided it becomes ready to use and record.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-42383\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/blazemeter.png\" alt=\"Blazemeter\" width=\"307\" height=\"565\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/11\/blazemeter.png 307w, \/blog\/wp-ttn-blog\/uploads\/2016\/11\/blazemeter-163x300.png 163w\" sizes=\"(max-width: 307px) 100vw, 307px\" \/><\/p>\n<p>Specify the Load Origin, User Agent, Advanced Options (to filter out the results) and then click the record button to start recording.<\/p>\n<p>Visit the required websites, once it is done, press the stop button to stop unnecessary recording.<\/p>\n<p>Then, click.jmx button to download the entire recording as .jmx file, which can be imported in JMeter and the task of load testing is simplified.<\/p>\n<p>I hope that you will find the load testing process simple and easy to perform now.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apache JMeter, an open-source product developed in Java used to perform load testing of web applications and simulate user load with various parameters like a real-life scenario. There were few use cases that I came across while performing load testing on my project. These are simple and often very helpful in performing tests on daily [&hellip;]<\/p>\n","protected":false},"author":913,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":11},"categories":[2348,1,1816],"tags":[4214,4212,4208,4210,4213,696,3301,4206,1949,4207,4209,4211],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/42339"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/913"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=42339"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/42339\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=42339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=42339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=42339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}