Learn JMeter In 1 Day - Guru99

Transcription

Learn JMeter in 1 DayBy Krishna RungtaCopyright 2019 - All Rights Reserved – Krishna RungtaALL RIGHTS RESERVED. No part of this publication may be reproduced ortransmitted in any form whatsoever, electronic, or mechanical, includingphotocopying, recording, or by any informational storage or retrievalsystem without express written, dated and signed permission from theauthor.

Table Of ContentChapter 1: What is JMeter? Introduction & Uses1.2.3.4.5.What is JMeter? Why it is used?Why JMeter?JMeter AdvantagesHow does JMeter work?Jmeter Version HistoryChapter 2: How to Download & Install Apache JMeter in easy steps1.2.3.4.5.6.Operating system Support for JMeterSteps to Install JMeterStart JMeter in GUI ModeHow to run JMeter in Non-GUI ModeAdditional PackagesUse JMeter in LinuxChapter 3: JMeter Elements: Thread Group, Samplers, Listeners,Configuration1.2.3.4.5.6.7.8.9.What is Element in JMeter?Thread GroupSamplersFTP request:HTTP request:JDBC request:BSF Sampler:Access Log Sampler:SMTP Sampler:

10.11.12.13.ListenersConfiguration ElementsCSV Data Set Config:HTTP Cookie ManagerChapter 4: JMeter GUI: Test Plan & Workbench1.2.3.4.5.6.7.8.9.10.11.What is a Test Plan?What is WorkBench?How to add Elements?Loading and Saving ElementsHow to Create JMX fileHow to Run JMX fileHow to Configure ElementsHow to Save a Test PlanCreate a Combo Test PlanHow to Run Test PlanTest ReportChapter 5: How to Use JMeter for Performance & Load Testing1.2.3.4.5.Create a Performance Test Plan in JMeterStep 1) Add Thread GroupStep 2) Adding JMeter elementsStep 3) Adding Graph resultStep 4) Run Test and get the test resultChapter 6: Jmeter Timers: Constant, Gaussian Random, Uniform [Example]1.2.3.4.Constant Timer:Gaussian Random Timer:Uniform Random Timer:BeanShell Timer

5.6.7.8.BSF TimerJSR223 TimerHow to Use Constant TimerPre-condition:Chapter 7: How to use Assertions in JMeter (Response Example)1.2.3.4.5.6.7.8.What is an Assertion?Types of AssertionsResponse AssertionDuration AssertionSize AssertionXML AssertionHTML AssertionSteps to use Response AssertionChapter 8: Controllers in JMeter: Loop, Simple, Transaction, Module,Random1.2.3.4.5.6.7.8.9.10.11.12.What is the Logic Controller?Recording Controller:Simple Controller:Loop Controller:Random Controller:Module Controller:Other Important Controllers:Loop Controller ExampleStep 1) Configuring Thread GroupStep 2) Configuring Loop ControllerStep 3) Add View Results in TableStep 4) Run your test

Chapter 9: Processor in JMeter: PreProcessor & processor:Post Processor ExampleStep 1) Add Thread GroupStep 2) Add JMeter elementsStep 3) Add Post-Processor ElementStep 4) Config the HTTP RequestStep 5) Add View Result TreeStep 6) Run TestChapter 10: Jmeter Distributed (Remote) Testing: Master SlaveConfiguration1.2.3.4.5.What is Distributed Testing?Remote Test ExampleStep 1) System configurationStep 2) Run the testStep 3) TroubleshootingChapter 11: HTTP Proxy Server in JMeter: Record Example Script1.2.3.4.Step 1) Setting the HTTP Proxy serverStep 2) Record your activityStep 3) Run your Test PlanStep 4) Save your test result

Chapter 12: Best Practices for your Jmeter Tests1.2.3.4.5.6.7.Limit the Number of ThreadsUsing a proxy serverUsing variablesReduce resource requirementCheck the JMeter logsErase the local path from CSV Data Set ConfigFollow file naming convention

Chapter 1: What is JMeter?Introduction & UsesWhat is JMeter? Why it is used?The Apache JMeterTM is pure Java open source software, which was firstdeveloped by Stefano Mazzocchi of the Apache Software Foundation,designed to load test functional behavior and measure performance. You canuse JMeter to analyze and measure the performance of web application or avariety of services. Performance Testing means testing a web applicationagainst heavy load, multiple and concurrent user traffic. JMeter originally isused for testing Web Application or FTP application. Nowadays, it is used fora functional test, database server test etc.Why JMeter?

Have you ever tested a web server to know how efficiently it works? Howmany concurrent users can a web server handle?Let say that one day, your boss asks you to do performance testingof www.google.com for 100 users. What would you do?It's not feasible to arrange 100 people with PC and internet accesssimultaneously accessing google.com Think of the infrastructure requirementwhen you test for 10000 users (a small number for a site like google). Henceyou need a software tool like JMeter that will simulate real-user behaviorsand performance/load test your site.

JMeter AdvantagesJMeter advantages are described as figure belowOpen source license: JMeter is totally free, allows developer use thesource code for the developmentFriendly GUI: JMeter is extremely easy to use and doesn't take time toget familiar with itPlatform independent: JMeter is 100% pure Java desktop application. Soit can run on multiple platformsFull multithreading framework. JMeter allows concurrent andsimultaneous sampling of different functions by a separate threadgroupVisualize Test Result: Test result can be displayed in a different formatsuch as chart, table, tree and log fileEasy installation: You just copy and run the *.bat file to run JMeter. Noinstallation needed.

Highly Extensible: You can write your own tests. JMeter also supportsvisualization plugins allow you to extend your testingMultiple testing strategy: JMeter supports many testing strategies suchas Load Testing, Distributed Testing, and Functional Testing.Simulation: JMeter can simulate multiple users with concurrent threads,create a heavy load against web application under test Support multiprotocol: JMeter does not only support web application testing but alsoevaluate database server performance. All basic protocols such as HTTP,JDBC, LDAP, SOAP, JMS, and FTP are supported by JMeterRecord & Playback - Record the user activity on the browser andsimulate them in a web application using JMeterScript Test: Jmeter can be integrated with Bean Shell & Selenium forautomated testing.How does JMeter work?The basic workflow of JMeter as shown in the figures belowJMeter simulates a group of users sending requests to a target server, andreturn statistics information of target server through graphical diagrams

The completed workflow of JMeter as shown in the figure below

Jmeter Version HistoryVersion12.1333.13.23.34Descriptionfirst official releaseJava 6 Java 7 Java 7 Java 8 Java 8Java 8 / 9

Chapter 2: How to Download & InstallApache JMeter in easy stepsOperating system Support for JMeterJMeter is a pure Java application and should run correctly on any system thathas a compatible Java implementation.Here is the list of an operating system compatible with JMeterLinuxWindowsMac OSUbuntuSteps to Install JMeterStep 1) Install JavaBecause JMeter is pure Java desktop application, it requires a fully compliantJVM 6 or higher. You can download and install the latest version of Java SEDevelopment Kit. Download Java Platform (JDK)

After installation is finished, you can use the following procedure to checkwhether Java JDK is installed successfully in your systemIn Window/Linux, go to TerminalEnter command java -versionIf the Java runtime environment is installed successfully, you will see theoutput as the figure belowIf nothing displays, please re-install Java SE runtime environmentPlease see the link for details mlStep 2) Download JmeterAs of this writing, the latest version of JMeter is Apache JMeter 4.2. You candownload it here But this tutorial demos installation of version 2.9, theinstall process remains the same.Choose the Binaries file (either zip or tgz) to download as shown in thefigure below

Step 3) InstallationInstallation of JMeter is extremely easy and simple. You simply unzip thezip/tar file into the directory where you want JMeter to be installed. Thereis no tedious installation screen to deal with! Simply unzip and you aredone!Once the unzipping is done installation directory structure should look like asfigure below

Given below is the description of the JMeter directories and its importanceJMeter directory contains many files and directory/bin: Contains JMeter script file for starting JMeter/docs: JMeter documentation files/extras: ant related extra files/lib/: Contains the required Java library for JMeter/lib/ext: contains the core jar files for JMeter and the protocols/lib/junit: Junit library used for JMeter/printable docs:Step 4) Launch JMeter

You can start JMeter in 3 modesGUI ModeServer ModeCommand Line ModeStart JMeter in GUI ModeIf you are using Window, just run the file /bin/jmeter.bat to start JMeter inGUI mode as shown belowThe following figure annotates the various components in the JMeter GUI

How to run JMeter in Non-GUI ModeStart JMeter in Server ModeServer mode is used for distributed testing. This Testing works as a clientserver model. In this model, JMeter runs on a server computer in servermode. On a client computer, JMeter runs in GUI mode.To start the server mode, you run the bat file bin\jmeter-server.bat

as below figureStart JMeter in command line modeJMeter in GUI mode consumes much computer memory. For saving theresource, you may choose to run JMeter without the GUI. To do so, use thefollowing command optionsThis is a command line example jmeter -n -t testPlan.jmx - l log.jtl -H 127.0.0.1 -P 8000

Additional PackagesBased on your requirement, you will need one or more optional packageslisted below.Java CompilerJava Compiler allows developers to build JMeter source code and otherJMeter pluginsSAX XML parserSAX is the Simple API for XML, originally a Java-only API. You can use SAXXML parser as an alternative to XML parser in JMeterEmail SupportJMeter has extensive Email capabilities. It can send email based on testresults and has a POP3(S)/IMAP(S) sampler. It also has an SMTP sampler.

JDBC driverIf you want to test database server, you have to install JDBC driverUse JMeter in LinuxUsing JMeter in Linux is the same as in Window; you simply run thefollowing shell script.Run the script file jmeter (This file has no extension)- run JMeter (inGUI mode by default).Run the script file jmeter-server - start JMeter in server mode (callsJMeter script with appropriate parameters)jmeter.sh - very basic JMeter script with no JVM options specified.mirror-server.sh - runs the JMeter Mirror Server in non-GUI modeshutdown.sh - Run the Shutdown client to stop a non-GUI instancegracefullystoptest.sh - Run the Shutdown client to stop a non-GUI instanceabruptly

If you want to test database server, you have to install JDBC driver Use JMeter in Linux Using JMeter in Linux is the same as in Window; you simply run the following shell script. Run the script file jmeter (This file has no extension)- run JMeter (in GUI mode by default). Run the script file jmeter-server - start JMeter in server mode (calls