Tagjmeter

How to execute a test continuously for specified duration without bothering no. of times using JMETER?

Scenario:

Do you have the following scenario to execute by Jmeter and not able to find the solution?

Having HTTP Request / REST Request in a test plan, required to execute the test for 1 hour duration without bothering repetition , and to

  • Find the application robustness and consistency to bear max load?
  • Find no. of requests application can handle for the specified duration?

and you would have

  • tried giving in scheduler but not worked as it executes for the number of threads specified In thread group.
  • tried giving in Duration but not worked. So what is next?

Solution:

  • Check ‘Forever’ check box in Thread group
  • Give Duration as ‘3600’ in Scheduler section of Thread Group

image

Enjoy Testing  Smile

Apache JMeter HTTP(S) Test Script Recorder

In this tutorial we are planning to explain step by step on how to record HTTP/HTTPS sessions.

Setup Instructions

  1. Go to JMETER_HOME/bin and start JMETER with jmeterw.cmd and jmeter in linux/unix.
  2. Select “Test Plan”, right click on “Test Plan” and add a new thread group: Add > Threads  (Users) > Thread Group.

image

3.  Select “Thread Group” right click, “Add –> Config Element –> HTTP Request Defaults”

image

4.  In new HTTP Request Defaults element: Server name – enter “host to be tested”, path can be left blank.

image

5. Right click on the “Thread Group” and add a recording controller: Add > Logic Controller >Recording Controller.

image

6.  Next, select WorkBench, Right click on WorkBench and add the recorder: Add -> Non-Test Elements -> HTTP(S) Test Script Recorder

image

7. On HTTP(S) Test Script Recorder, click the “Add” button in “URL Patterns to Include”. This will create a blank entry; enter “.*.html”. you can specify URL patterns to include and exclude such as *.html, *.js, which you would like to record.

image

8.  Right click on “HTTP(S) Test Script Recorder” and add a listener: Add -> Listener –> View Results Tree

image

9. Return to HTTP(S) Test Script Recorder, and click the “Start” button at the bottom.

This will start the JMeter proxy server which is used to intercept the browser requests. A file called ApacheJMeterTemporaryRootCA.crt will be generated in jmeter/bin folder. Install this certificate in your browser.

Note: If you browser already uses a proxy, then you need to configure JMeter to use that proxy before starting JMeter, using the command-line options -H and -P.

Configure Firefox To Use JMeter Proxy

We will use Firefox as our browser when using the JMeter HTTP(S) Test Script Recorder because, unlike Chrome and some other browsers, it does allows you to override system-wide configuration for its proxy settings.

Configure Firefox to use localhost (127.0.0.1) on port 8080 as its proxy for all traffic by following these steps:

  1. Open Firefox
  2. Go to the Preferences menu
  3. Click on the Advanced tab
  4. Then Network tab
  5. In the “Connection” section, click on “Settings…”
  6. Select the “Manual proxy configuration” radio button
  7. Set HTTP Proxy to “localhost” and Port to “8080”
  8. Check “Use this proxy server for all protocols”
  9. Click OK and exit the Preferences menu

Note: When Firefox is configured to use JMeter’s Script Recorder as a proxy, it will only work properly if the Script Recorder is running.

Recording HTTP Requests

Now that our test plan’s HTTP(S) Test Script Recorder is running, and Firefox is configured to use it as a proxy, the HTTP requests that Firefox sends will be recorded. Let’s test it out.

In Firefox, go to your server’s homepage (the same server that you configured in your JMeter HTTP Request Defaults):

http://your_domain.com/

Now there should be a little triangle next to your Recording Controller. Click on it to expand and show the requests that it has recorded. You should see the HTTP requests that were recorded, depending on which URL Patterns you have included and excluded. Feel free to browse your site to record more requests.

As you can see, a lot of requests were created. You may refine the list of HTTP requests by simply deleting unwanted entries here.

If you do not see any entries under your Recording Controller, you will want to review your URL Patterns in the HTTP(S) Test Script Recorder (Hint: Remove all includes and excludes to record everything).

Once you are done recording, click the “Stop” button at the bottom of the HTTP(S) Test Script Recorder window. Note that Firefox will no longer be able to reach any pages (because it is configured to use port 8080 as a proxy)–configure it to use “No proxy” if you want to function normally.

Run Your Test Plan

Once you are happy with the test plan you have recorded, save it, then run it. It will function exactly like a manually created test, so you can configure it, delete, and add items to make it match your desired test case more closely.

Jmeter Problems and Solutions

Performance

1) How to handle sessions in Jmeter?

Add->Pre-Processors->HTTP URL Re-writting Modifier for the sampler where your session variable is present
Then add your variable in session argument name and check chache session id.
Please see the Image below:

Jmeter_SessionHandling

2) How to customize the user data/ how to run the script for multiple users in Jmeter?

i) Add Thread Group->Config Element-> CSV Data config Element
ii) Give user variables for the csv file column.
iii) Place the csv in the same folder where you kept the jmeter script or give full file path in filename

See the images below:

Jmeter_CSV1

 

 

 

 

 

 

Jmeter_CSV

 

 

 

 

 

 

 

 

3) How to run the Jmeter for more than 300 users?

i) Run in Non GUI distributed mode to run for more than 300 users. It depends on RAM size. For the system with 3.2 GB, you can run up-to 1000 users.

Step1:
Configure Jmeter for Distributed testing

Step2:
Place your script and csv in /bin folder of the jmeter.

Step3:
Open command prompt , go to jmeter bin directory and give the following command

jmeter -n -t testplan.jmx -R ip1,ip2 -l resultfilename

4) How to record Jmeter script?
you can capture headers and parameters of the request by Fiddler or HTTPWATCH and write the script manually, or configure proxy and use Recording controller.

Detailed manual is available in Apache Site:
http://jmeter.apache.org/usermanual/jmeter_proxy_step_by_step.pdf

5) How to extract the data using regex in Jmeter?

There is an element called preprocessor->regularexpression.

Add it under the request you want and then follow the below steps:

i) Give reference name (any name , that will be substituted in the place of actual parameter value in the request)

ii) Give the regular expression , for example if the text to be extracted is ‘world’ from text=’world’, then the regex will be like this text='(.+?)’

iii) Give template as $1$

iv) Match No would be which row of the value from the web page , it may be 1, 2,3 etc. If you want random row then give ‘0’

v)Default value is a string that will be sent to the server when it fails to extract the data. it can be anything for Ex: Loginid_Failed

Please see the Image below:

Jmeter_Regex

 

 

 

 

 

 

6) what are the charcters used in regex?

Regular Expressions use certain characters and those have special meaning. Following are the list of such characters.
( ) : grouping
[ ] : character classes
{ } : repetition
* + ? : repetition
. : wild-card character
: escape character
| : alternatives
^ $ : start and end of string or line

7) How can i use special charcters with actual meaning in regex?

Add backslash to the special character to mean it as it is, for example (),$,^.

8)  Mention example for regular expression to extract string with whitespace

Regular Expression : <url.values+(.+?)=”(.+?)”

Explanation:

<url.value    : Extract the string <url.value

<url.values  : Extract the string <url.value followed by white space

<url.values+Extract the string <url.value followed by white space and

<url.values+(.+?) : Extract the string <url.value followed by white space and any character with 1 or more match

<url.values+(.+?) =  : Extract the string <url.value followed by white space and any character with 1 or more match with equals symbol 

<url.values+(.+?) =”(.+?)” : Extract the string <url.value followed by white space and any character with 1 or more match with equals symbol  and any charcter with 1 or more matches inside double quotes.

So the final string returned from above condition may be like this:

<url.value groupid=”1234trurbd93737″

9) How to use java program inside Jmeter?

Java program can be called inside jmeter by using BeanShell Pre/Post Processor.

10) How to send file with Jmeter script?

There is a column in http request as ‘ Send Files with the Request’

Give the filepath,parameter name and MIME type.

For sending different files , give it in CSV file and add the variable in CSVconfig Element. (Any question related this, you can post your questions)

11) How to capture Jmeter results?

There are lot of graphs/listeners available for jmeter. Or if the purpose is to find response time for the request, use ‘Aggregate Report’ and take min, max, avg timings(in milliseconds) . That will help a lot.
Or you can download plugin for colorful graphs.

http://code.google.com/p/jmeter-plugins/

Jmeter_AggregateReport

12) How to View the results of JTL file created in NON-GUI mode?
Open any Jmeter script, go to Aggregate report listener, Browse the file and Open it. After that you can Save it as CSV file.

13) How to test ‘HTTPS’ applications using Jmeter?
In HTTP Request default, mention the protocol as ‘https

14) How to rectify Jmeter out of memory error-heap space when opening Jmeter?
Right Click and Edit Jmeter.bat file , increase Xmx value and check.

15) Where to Download Jmeter latest version?
https://jmeter.apache.org/download_jmeter.cgi

16) How to execute ssh command or shell script on remote server using Jmeter?
Using SSH sampler it can be done. For detailed explanation see here
http://www.technix.in/execute-linux-command-shell-script-apache-jmeter/

17) How to run endurance test using Jmeter for more than 8 hours?

Using Timers , it is possible to run endurance test using jmeter, please look at this

http://www.technix.in/run-overnight-endurance-test-consecutively-using-jmeter/

 

© 2017 My techbook

Theme by Anders NorénUp ↑