Upload
wira-santos
View
5.680
Download
2
Embed Size (px)
DESCRIPTION
Resource from Apache JMeter and Online. Taken this topic for Testing Team at Bullseye for knowledge sharing day - 26th April 2013. Thanks guys for listening!.
Citation preview
Automating with
JMeter ApachePrepared by Wira.
Introduction - Automation
Automation testing which is also known as Test Automation, is when the tester
writes scripts and uses another software to test the software.
This process involves automation of a manual process.
Automation Testing is used to re-run the test scenarios that were performed
manually, quickly and repeatedly (regression).
Apart from regression testing, Automation testing is also used to test the
application from load, performance and stress point of view.
It increases the test coverage; improve accuracy, saves time and money in
comparison to manual testing.
What to Automate?
It is not possible to automate everything in the Software; however the areas
at which user can make transactions such as login form or registration forms
etc, any area where large amount of users accessing.
Furthermore all GUI items, connections with databases, field validations etc
can be efficiently tested by automating too.
When to Automate?
Test Automation should be uses by considering the following for the Software:
Large and critical projects.
Projects that require testing the same areas frequently.
Requirements not changing frequently.
Accessing the application for load and performance with many virtual users.
Stable software with respect to manual testing.
Availability of time.
How to Automate?
Automation is done by using a supportive computer language like scripting
language and an automated software application.
There are a lot of tools available which can be use to write automation
scripts.
Software Testing Tools: HP Quick Test Professional, Selenium, JMeter,
IBM Rational Functional Tester, SilkTest, TestComplete, Testing Anywhere,
WinRunner, Load Runner, Visual Studio Test Professional, WATIR.
Introduction - JMeter
Stefano Mazzocchi of the Apache Software Foundation was the original developer of
JMeter. He wrote it primarily to test the performance of Apache JServ (a project
that has since been replaced by the Apache Tomcat project).
Apache JMeter is a 100% pure Java desktop application designed to load test
client/server software (such as a web application ).
It may be used to test performance both on static and dynamic resources such as
static files, Java Servlets, CGI scripts, Java objects, databases , FTP servers , and
more.
JMeter can be used to simulate a heavy load on a server, network or object to test
its strength or to analyze overall performance under different load types.
Additionally, JMeter can help you regression test your application by letting you
create test scripts with assertions to validate that your application is returning the
results you expect. For maximum flexibility, JMeter lets you create these assertions
using regular expressions.
Note: JMeter is not a browser.
Getting started…
The easiest way to begin using JMeter is to first download the latest production
release and install it. The release contains all of the files you need to build and
run most types of tests, e.g. Web (HTTP/HTTPS), FTP, JDBC, LDAP, Java, and
JUnit.
URL: http://jmeter.apache.org/download_jmeter.cgi
Requirements:
JMeter requires a fully compliant JVM/JRE 6 or higher.
JMeter is a 100% Java application and should run correctly on any system that has a
compliant Java implementation.
Installation: To install a release build, simply unzip the zip/tar file into the
directory where you want JMeter to be installed. Provided that you have a
JRE/JDK correctly installed and the JAVA_HOME environment variable set, there
is nothing more for you to do.
Running – Jmeter…To run JMeter, run the jmeter.bat (for Windows) or jmeter (for Unix) file. These files are
found in the bin directory. After a short pause, the JMeter GUI should appear.
Building a Basic Web Test Plan…
In this section, we will learn how to create a basic Test Plan to test a Web site.
We will create five users that send requests to two pages on the JMeter Web site.
Also, we will tell the users to run their tests twice.
So, the total number of requests is (5 users) x (2 requests) x (repeat 2 times) = 20 HTTP requests.
To construct the Test Plan, we will be using the following elements: Thread Group, HTTP Request,
HTTP Request Defaults, and Graph Results (Note: There are many elements are available in
JMeter – refer below URL: http://jmeter.apache.org/usermanual/index.html --> Section
“Elements of a test plan”
Thread Group - Adding Users
The Thread Group tells JMeter the number of users we want to simulate, how often the users should
send requests, and the how many requests they should send.
Go ahead and add the ThreadGroup element by first selecting the Test Plan, clicking your right
mouse button to get the Add menu, and then select Add --> ThreadGroup.
Next, increase the number of users (called threads) to 5.
In the next field, the Ramp-Up Period, This property tells JMeter how long to delay between
starting each user. For example, if you enter a Ramp-Up Period of 5 seconds, JMeter will finish
starting all of your users by the end of the 5 seconds. So, if we have 5 users and a 5 second Ramp-
Up Period, then the delay between starting users would be 1 second (5 users / 5 seconds = 1 user
per second). If you set the value to 0, then JMeter will immediately start all of your users.
Finally enter a value of 2 in the Loop Count field. This property tells JMeter how many times to
repeat your test. If you enter a loop count value of 1, then JMeter will run your test only once. To
have JMeter repeatedly run your Test Plan, select the Forever checkbox.
Adding Default HTTP Request Properties Now that we have defined our users, it is time to define the tasks that they will be
performing.
In this section, we will specify the default settings for your HTTP requests.
And then, in next section (HTTP Request element), you will add HTTP Request elementswhich use some of the default settings you specified here.
Begin by selecting the JMeter Users (Thread Group) element. Click your right mousebutton to get the Add menu, and then select Add --> Config Element --> HTTP RequestDefaults.
For the Test Plan that we are building, all HTTP requests will be sent to the same Webserver, jmeter.apache.org. Enter this domain name into the field. This is the only fieldthat we will specify a default, so leave the remaining fields with their default values.
Note: Nearly all web testing should use cookie support, unless your applicationspecifically doesn't use cookies. To add cookie support, simply add an HTTP CookieManager to each Thread Group in your test plan. This will ensure that each thread getsits own cookies, but shared across all HTTP Request objects. *** To add the HTTP CookieManager , simply select the Thread Group , and choose Add --> Config Element --> HTTPCookie Manager.
Note: The HTTP Request Defaults element does not tell JMeter to send an HTTP request.
It simply defines the default values that the HTTP Request elements use.
Adding HTTP Requests In our Test Plan, we need to make two HTTP requests. The first one is for the JMeter
home page (http://jmeter.apache.org/), and the second one is for the Changes page
(http://jmeter.apache.org/changes.html).
JMeter sends requests in the order that they appear in the tree.
Start by adding the first HTTP Request to the JMeter Users element (Add --> Sampler -
-> HTTP Request).
Steps:
Change the Name field to "Home Page".
Set the Path field to "/". Remember that you do not have to set the Server Name field
because you already specified this value in the HTTP Request Defaults element.
Next, add the second HTTP Request and edit the following properties:
Change the Name field to "Changes".
Set the Path field to "/changes.html".
Listener- Adding a Graph Result
The final element you need to add to your Test Plan is a Listener .
This element is responsible for storing all of the results of your HTTP requests in a file and
presenting a visual model of the data.
Select the JMeter Users element and add a Graph Results listener (Add --> Listener -->
Graph Results).
Next, we need to specify a directory and filename of the output file. You can either type it
into the filename field, or select the Browse button and browse to a directory and then
enter a filename.
Logging in to a web-site…
It's not the case here, but some web-sites require you to login before permitting you to
perform certain actions. In a web-browser, the login will be shown as a form for the user
name and password, and a button to submit the form.
The button generates a POST request, passing the values of the form items as parameters.
To do this in JMeter, add an HTTP Request, and set the method to POST.
You'll need to know the names of the fields used by the form, and the target page.
These can be found out by inspecting the code of the page.
Can we do Recording using JMeter ???
Yes… we can – using one of the best
components called “HTTP Proxy Server”
The HTTP Proxy Server allows JMeter to watch and record your actions while
you browse your web application with your normal browser.
JMeter will create test sample objects and store them directly into your test
plan as you go.
To use the proxy server, add the HTTP Proxy Server element to the
workbench.
Select the WorkBench element in the tree, and right-click on this element to
get the Add menu (Add --> Non-Test Elements --> HTTP Proxy Server).
Step by step guide using HTTP Proxy
Server… This tutorial attempts to explain the exact steps for JMeter's proxy. For those new to JMeter, one easy
way to create a test plan is to use the Proxy. What the proxy does is it records the requests sent to the
server.
1. Go to JMETER_HOME/bin and start JMeter with jmeter.bat (on windows)
2. Select “Test Plan” on the tree.
3. Right click on the “Test Plan” and add a new thread group: Add > Threads (Users) > Thread Group
4. Select the Thread Group.
5. Right click “Add -> Config Element -> HTTP Request Defaults”
6. In new HTTP Request Defaults element: Server name – enter “jmeter.apache.org”
7. Path – leave blank
8. Right click on the “Thread Group” and add a recording controller: Add > Logic
Controller > Recording Controller
9. Next, select WorkBench
10. Right click on WorkBench and add the Http proxy: Add -> Non-Test Elements -> HTTP Proxy Server
11. On HTTP Proxy Server, click the “Add” button in “URL Patterns to Include”. (This will create a blank entry).
12. Enter “.*\.html”
13. Click 3 times, the “Add” button in “URL Patterns to Exclude”. (This will create 3 blank entries).
14. Enter “.*\.png” pattern, “.*\.gif” pattern and “.*\.ico” pattern
15. Right click on “HTTP Proxy Server” and add a listener: Add -> Listener -> View Results Tree
16. Return to HTTP Proxy Server, and click the “Start” button at the bottom.
Configure your brower to use the JMeter HTTP Proxy
At this point, JMeter's proxy is running.
For this exercise, we will use Firefox to record some pages on JMeter.
17. Start Firefox, but do not close JMeter.
18. From the tool bar, click “Tools > Preferences”. This should bring up the options.
19. Select the “Advanced” tab, and “Network” tab.
20. Click “Settings” button near the bottom.
21. On the new popup, check “Manual proxy configuration”. The address and port fields should be
enabled now.
22. Address – enter “localhost” or the IP address of your system.
23. Port – enter “8080”.
24. Check the “Use this proxy server for all protocols”
25. Click “ok” button
26. Click “ok” button again. This should return you to the browser.
Record your navigation
27. With your brower, in the “Address” bar at the top, enter
“http://jmeter.apache.org/index.html” and hit the “enter” key.
28. Click on a few links on JMeter's pages.
29. Close your browser and bring up the JMeter window.
Expand the thread group and there should be several samplers. At this point,
the test plan can be saved as is.
30. Select “Thread Group”.
31. Right click “Add -> Listener -> Summary Report” to add an summary listener.
32. The summary listener will show some basic statistics.
33. Select “Thread Group”.
34. Number of Threads – enter “5”.
35. Ramp up Period – do not change.
36. Loop Count – enter 100
Start the test (with test plan)…
At this point, we are ready to run our test plan and see what happens. Save the test plan.
When you're ready to run the test, there's two ways:1. Run -> Start
2. Ctrl–R
Before you start the test, select “Summary Report”. As the test runs, the statistics will change
until the test is done. At the end of the test, the summary report should look like this.
While the test is running, in the upper right-hand corner, there should be a green square.
When the test is done, the box should be grey.
The End…