Thursday, July 9, 2015

Distributed Load Testing in Jmeter.!!

Distributed testing is to be used when you reach the limits of a machine in terms of CPU, Memory, Network. Distributed testing is a kind of testing which use multiple systems to perform stress testing. It's applied for testing web sites and server applications when they are working with multiple clients simultaneously.






Few checkpoints before getting started with distributed testing:
1. the firewalls on the systems are turned off.
2. all the clients are on the same subnet.
3. the server is in the same subnet, if 192.x.x.x or 10.x.x.x ip addresses are used. If the server
doesn't use 192 or 10 ip address, there shouldn't be any problems.
4. Make sure JMeter can access the server.
5. Make sure you use the same version of JMeter on all the systems. Mixing versions may not work
correctly.

Once you've made sure the systems are ready, it's time to setup remote testing.

Terms we are using:
- Master: the system running JMeter GUI, control each slave.
- Slave: the system running jmeter-server, receive command from the master and send a request to server under test.
- Target: the web server under test, get request from slaves.

Steps: -

1. On the slave systems, move to jmeter/bin directory and execute jmeter-server.bat (jmeter-server on
unix). On windows, you should see a dos window appear with “jre\[version]\bin\rmiregistry.exe”.
If this doesn't happen, it means either the environment settings are not set or there are
multiple JRE installed on the system.
To correct the settings, please follow the given steps:
    1. Open 'jmeter-server.bat' in a text editor
    2. go to line 44 and find “:setCP”
    3. edit “START rmiregistry” to the full path. Example: “START C:\<JAVA_HOME>\jre\bin\rmiregistry”
    4. Save the batch file and restart 'jmeter-server.bat'.
2. On master system acting as the console, open windows explorer and go to jmeter/bin directory
3. Open jmeter.properties in a text editor
4. Edit the line “remote_hosts=127.0.0.1”.
5. Add the IP address of slave machines. For example, if I have jmeter server running on 192.168.0.10, 11, 12, 13, and
14, the entry would be like this:
remote_hosts=192.168.0.10,192.168.0.11,192.168.0.12,192.168.0.13,192.168.0.14
6. Start jmeter.
7. Open the test plan you want to use

Starting the Test

At this point, you are ready to start load testing. If you want to double check the slave systems are
working, open jmeter.log in notepad. You should see the following in the log.
Jmeter.engine.RemoteJMeterEngineImpl: Starting backing engine
If you do not see this message, it means jmeter-server did not start correctly. For tips on debugging
the issue, go to the tips section.
There are two ways to initiate the test:
1) Remote Start
2) Remote Start All.
Both options are listed under 'Run' option.

Like this:




Limitations:
There are some basic limitations for distributed testing. Here's the list of the known items in no specific order.
1. RMI cannot communicate across subnets without a proxy; therefore neither can jmeter without a proxy.
2. Since JMeter sends all the test results to the controlling console, it is easy to saturate the
network IO. It is a good idea to use the simple data writer to save the results and view the file
later with one of the graph listeners.
3. Unless the server is a large multi processor system, in most cases 1-2 clients is sufficient to
overwhelm the server.
4. A single JMeter client running on a 2-3Ghz CPU(recent cpu)can handle300-600 threads depending on the type of test.(The exception is the webservices). XML processing is CPU intensive and will rapidly consume all the CPU cycles. As a general rule, the performance of XML centric applications will perform 4-10 slower than applications using binary protocols.

Monday, June 22, 2015

Recording in Jmeter using 'Test Script Recorder'

In this post will discuss how to setup and use the Apache JMeter HTTP(S) Test Script Recorder to record HTTP requests. Recording HTTP requests is a great way to building test plans, and can be useful in creating tests that closely mimic a normal user's behavior.

The elements that we need to set this up are:

1. Non- test Elements: HTTP(S) Test Script Recorder.
2. Browser installed in user's system.

First will add "HTTP(S) Test Script Recorder", by right click on 'workbench' then select add and then Non- test Elements: HTTP(S) Test Script Recorder.

Like this:




Now configure it:
a) Enter the site domain or its IP in 'HTTPS Domain' field.
b) Change target controller as "WorkBench>> HTTP(S) Test Script Recorder".

Like this:

Now click on the 'Start' button located at the bottom of 'HTTP(S) Test Script Recorder'.

Open your browser and enter the proxy settings as:
Proxy: localhost
Port: 8080

Click here to check, how to change browser's proxy settings.

Now run the site URL (configured under script recorder) in the browser and perform your steps.

After that view the Jmeter, all the requests are listed under "WorkBench>> HTTP(S) Test Script Recorder".

Like this:



Sunday, June 21, 2015

Import CSV Data in Jmeter

In load testing generally we have flow's in which we have login page. And in case of number of users obviously we need multiple user login credentials.
For this case, Jmeter provides a config element as 'CSV Data Set Config' in which user can pass a file containing different login credentials.

Lets take an example of google search, the scenario is we need to load google search by searching different keywords. Now what we do, will pass a file containing different keywords and pass them to HTTP request.

Open Jmeter and add following elements:
1) Thread Group
2) Config Element: CSV Data Set Config
3) Sampler: HTTP Request
4) Listener: View Result Tree

Your test plan will look like this:


Now configure 'CSV Data Set Config', by adding file path (containing keywords) and set a variable name to it.
Like this:
a) Sample TXT file containing keywords (for now we added only two keywords, you can add more to it).
b) CSV Data Set Config look like this
Now configure Sampler 'HTTP Request'
a) Add domain and pass parameter '#q' that can pick value from txt file, for that will get the value from variable 'keyword' as mentioned in the 'CSV Data Set Config'.
Like this:




Now we have two keywords in our text file so we need to set threads count as '2' in thread group.

Script is ready, save it and run the load.

On completion, you can check the requests under listener ''View Result Tree".

 






Friday, June 19, 2015

Functional Testing Using Jmeter !!

JMeter does not have a built-in browser, unlike many functional-test tools, But it can run the browser and execute the steps.

We can automate the user actions in Jmeter by using sampler named as 'WebDriver Sampler'. Its the addon feature of Jmeter, you need to add jar to Jmeter library.

On adding you will see these new elements in Jmeter:


To add this Sampler, you need to add Jmeter plugin 'WebDriver' to your Jmeter.

You can download plugin from here:

 This plugin also add some config elements, that will help in launching the browser session for your script.

Lets make a simple script and run it using Jmeter.

Open Jmeter and add following elements to it:
1) Thread Group
2) Config Element>> Firefox Driver Config.
3) Sampler>> WebDriver Sampler
4) Listener>> View Result Tree

Like this:


You don't need to configure 'Firefox Driver Config' for this test, will go with its default settings.

Now click 'WebDriver Sampler' and paste below code in it.

WDS.sampleResult.sampleStart()
WDS.browser.get('http://google.com')
WDS.sampleResult.sampleEnd()


Like this:

Your simple script is ready, it will launch firefox and opens google in it.