Showing posts with label Jmeter Tutorial for Beginers. Show all posts
Showing posts with label Jmeter Tutorial for Beginers. Show all posts

How to Run JMeter Script Using Ant

How to Run JMeter Script Using Ant,Apache Ant is a pure Java build tool which is useful in compile,clean and test and run Java applications.Apache JMeter providing option to run JMeter Test Plan using Ant and displays BUILD is successful or Failure and Ant BUILD generates HTML reports after completion of execution of ant.

How to run jmeter script using ant


Also Read


How to Run JMeter Script Using Ant

In this post you will learn How to Run JMeter Script Using Ant,Apache JMeter providing Ant xml file in this path F:\apache-jmeter-3.1\extras, and build.xml file have below details.

<project name="ant-jmeter" default="all">
<description>
Jmeter Ant build description Default Value is "Load Test Results"
</description>
<property name="testpath" value="${user.dir}"/>
<property name="jmeter.home" value="${basedir}/.."/>
<property name="report.title" value="Load Test Results"/>

Function Mode:

<echo>funcMode = ${funcMode}</echo>
<delete file="${testpath}/${test}.html"/>
<jmeter
jmeterhome="${jmeter.home}"
testplan ="${testpath}/${test}.jmx"
resultlog="${testpath}/${test}.jtl">

XSLT Report:

<target name="xslt-report" depends="_message_xalan">
<tstamp><format property="report.datestamp" pattern="yyyy/MM/dd HH:mm"/></tstamp>
<xslt
classpathref="xslt.classpath"
force="true"
in="${testpath}/${test}.jtl"
out="${testpath}/${test}.html"
style="${basedir}/jmeter-results-detail-report${style_version}.xsl">
<param name="showData" expression="${show-data}"/>
<param name="titleReport" expression="${report.title}"/>
<param name="dateReport" expression="${report.datestamp}"/>
</xslt>
</target>

Condition:

<!-- Check that the xalan libraries are present -->
<condition property="xalan.present">
<and>
<!-- No need to check all jars; just check a few -->
<available classpathref="xslt.classpath" classname="org.apache.xalan.processor.TransformerFactoryImpl"/>
<available classpathref="xslt.classpath" classname="org.apache.xml.serializer.ExtendedContentHandler"/>
</and>
</condition>
<target name="_message_xalan" unless="xalan.present">
<echo>Cannot find all xalan and/or serialiser jars</echo>
<echo>The XSLT formatting may not work correctly.</echo>
<echo>Check you have xalan and serializer jars in ${lib.dir}</echo>
</target>


As you see in above build.xml file i have given three parameters xml values because you need to change those three values as below,please follow below steps to configure.

Build.xml file Configuration:


1.Open build.xml file with notepad or notepad++ and search with " ${test} " and rename with your jmx file name as below.

${test}.jmx - softwaretesting.jmx
${test}.html - softwaretesting.html
${test}.jtl - softwaretesting.jtl

In Function Mode , XSLT report parameter values as below.

Function Mode:

<target name="run">
<echo>funcMode = ${funcMode}</echo>
<delete file="${testpath}/SoftwareTestingdemo.html"/>
<jmeter
jmeterhome="${jmeter.home}"
testplan ="${testpath}/SoftwareTestingdemo.jmx"
resultlog="${testpath}/SoftwareTestingdemo.jtl">

XSLT Report:

<target name="xslt-report" depends="_message_xalan">
<tstamp><format property="report.datestamp" pattern="yyyy/MM/dd HH:mm"/></tstamp>
<xslt
classpathref="xslt.classpath"
force="true"
in="${testpath}/SoftwareTestingdemo.jtl"
out="${testpath}/SoftwareTestingdemo.html"
style="${basedir}/jmeter-results-detail-report${style_version}.xsl">
<param name="showData" expression="${show-data}"/>
<param name="titleReport" expression="${report.title}"/>
<param name="dateReport" expression="${report.datestamp}"/>
</xslt>
</target>

2.Save the build.xml file.
3.Now Copy softwaretesting.jmx file in F:\apache-jmeter-3.1\extras folder as below.
4.Now open Command Prompt.
5.Go to F:\apache-jmeter-3.1\extras folder path
6.Enter ant and press enter,once BUILD is successful then it will display below details in command prompt.
How to run jmeter script using ant

7.Now go to F:\apache-jmeter-3.1\extras folder ,it will generate softwaretesting.jtl,softwaretesting.html files.
Run jmeter script using ant

8.Now open Softwaretesting.html file ,below reports will display all samples related HTML reports.

Load Test Results:



Thank you for reading My post please provide your valuable comments,in case you are facing any problem while generating the reports.

How to open Jmeter jtl file in Excel example

How to open Jmeter jtl file in Excel example gives you knowledge about open jmeter Test results jtl file in Excel workbook with real time example.Please follow below steps to open Jmeter jtl file in Excel.Using Jmeter you can save Test result file in csv,xls,txt and jtl formats and with the help of Simple Data Writer Listener as provided specific path in local system.

How to open Jmeter jtl file in Excel example


How to open Jmeter jtl file in Excel example


In order to perform above task we require below details,those are

1. Jmeter Test Plan.
2.Some HTTP/SOAP/REST service Samples.
3. Listener - Simple Data Writer.
4.Write results to file Path .
5.Set Up Thread group for Number of virtual users to run.
6.In case you are using apache-jmeter-3.0 new version then you need to copy paste below xsl files from old version and my old apache jmeter version is "apache-jmeter-2.13".
Go to apache-jmeter-2.13/extras folder then you will find below XSL format files,those are
  1. jmeter-results-detail-report.xsl
  2. jmeter-results-detail-report_21.xsl
  3. jmeter-results-report.xsl
  4. jmeter-results-report_21.xsl
Jmeter jtl file from Excel

7.Just copy paste above old version files in new version that is apache-jmeter-3.0/extras,it will looks like below.Let's see below example to generate jmeter results file in jtl format which is save in xml format with .jtl extension and adding some simple path in xml file,then only jtl file will open in Excel workbook.

Also Read:

  1. Generate HTML Report Dashboard.
  2. Jmeter SOAP/REST Web Services Testing
  3. Response Assertion Examples.
  4. XPATH Assertion Examples.
  5. Transaction Controller Examples.

Configurations in Simple Data Writer:


Before running your Test plan in Jmeter,you need to configure Sample Result Save Configuration in Simple Data Writer window panel,Please follow below steps.

STEP 1 : Add Simple Data writer from Right click on Thread Group - Add - Listener - Simple Data Writer
STEP 2 : Click on Configure button.
STEP 3 : Select require check boxes to save in results file.

Jtl file from Excel example


VIDEO TUTORIAL:



Note : In case Save as XML checkbox is not selected in Sample Result Save Configuration dialog box then your jtl result file save in csv format but we require to save it in XML format.

STEP 4 : Select Save as XML check box in Sample Result Save Configuration dialog box.
STEP 5 : Now enter Write results to file/Read from File path with file name as E:\QTP_Tutorials\JMETER\TestResults\Test-results.jtl

Note : You should not create jtl extension file manually because Simple Data Writer automatically creates given file name with .jtl extension.

STEP 6 : Now Run your Test Plan
STEP 7 : Now open Specified File name results path and you will see Test-results.jtl file is generated as below.

JTL Test Result File

STEP 8 : Now open .jtl file in Notepad or Wordpad or Notepad++ ,it will open as below.

STEP 9 : Now copy below path in between <?xml version="1.0" encoding="UTF-8"?> and <testResults version="1.2">

Code : <?xml-stylesheet type="text/xsl" href="F:\Java_Applications\apache-jmeter-3.0\extras\jmeter-results-detail-report_21.xsl"?>

STEP 10 : Save your .jtl file and close the same.
STEP 11 : Open empty Excel workbook and drag and drop .jtl test results file into Excel workbook,select "Open the file with the following style sheet applied(Select One)"


How to Open jtl file from Excel examples


STEP 12 : Click on OK button.
STEP 13 : Again click on Yes button.
STEP 14 : Now your Test Results reports will generate in Excel workbook as below.

Test Result:


You will see below Load Test Results.

Jmeter jtl file from Excel workbook

JTL Load Test Results in EXCEL Workbook


Please provide your valuable comments on this post How to open Jmeter jtl file in Excel example.Thank you for reading.

Jmeter SOAP/REST Web Services Testing

Jmeter SOAP/REST Web Services Testing plan creation,in this lesson you will learn web services testing using Jmeter performance testing.Web Services is a client server application component using for communication between multiple systems or applications. Web Services transferring the data between different system with the help of Protocols example http protocols.In order to understand here i am using simple flight web services URL to create web services test plan in Jmeter. Let's create Web Services Test plan in jmeter.

Jmeter SOAP/REST Web Services Testing

Before creating web services test plan in jmeter we should require following details.

1.Web Service URL.
2.Web Service input parameters
3.Web Service Response details

Must Read

Generate Jmeter Report Dashboard
Xpath Assertion in Jmeter
Apache Jmeter Web Test Plan


Steps to Create Web Services Test Plan

1.Open Apache Jmeter from F:\apache-jmeter-3.0\bin folder by double click on jmeter.bat file in windows.
2.Right click on Test Plan Add - Threads - Thread Group,Enter following details

  • Number of Threads(Users):
  • Ramp up Period(in Seconds)
  • Loop Count
Jmeter Web Services Testing
Thread Group


3.Right click on Thread Group - Add - Sampler - SOAP/XML-RPC Request,it will display below details

Jmeter Web Services Testing


  • URL : Web Service url ex : http://localhost:24240/HPFlights_SOAP
  • Send SOAP Action
  • Soap/XML - RPC Data : This text area useful in writing SOAP input parameters in SOAP request as below.
Jmeter SOAP Testing



4.Now add Response Assertion to verify the web services response,Right click on SOAP/XML-RPC Request - Add - Assertions - Response Assertion.

Web Services testing using Jmeter

5.Click on Add in Pattern to Test and enter pattern to verify from Web Service Response as below.

Web Services Response Testing
Response Assertion - Pattern to Test


6.Add View Result Tree from Listeners, Right click on Thread Group - Add - Listeners - View Result Tree.
Apache Jmeter Web Services Testing


7.Save your script.
8.Now run your script and verify View Result Tree window whether it is pass or fail.

View Result Tree - PASS

Apache Jmeter Web Services Testing



View Result Tree - FAIL

Apache Jmeter Soap/Rest web services testing


What have you learn?

1.What is web services?
2.How to create web services test plan
3.How to add web services in jmeter
4.How to verify the web services response with assertions.


Assertions in Jmeter examples

Assertions in Jmeter is very useful components ,Assertions in Jmeter are performs an extra task to verify results of Samplers whether it may be HTTP Requests,SOAP request or REST API services.Assertions are verifies once the main sampler is completes the requests.Mainly assertions are applied for main samplers and not applied on sub-samplers.

Assertions in Jmeter examples
Assertion in Jmeter

Assertions in Jmeter examples

Apache JMeter providing different assertions lists to verify different samaplers as stated above,Following are the assertions are available in JMeter.

Response Assertion
Duration Assertion
Size Assertion
XML Assertion
BeanShell Assertion
MD5Hex Assertion
HTML Assertion
XPath Assertion
XML Schema Assertion
BSF Assertion
JSR223 Assertion
Compare Assertion - The Compare Assertion can be used to compare sample results within its scope
SMIME Assertion

Assertions can be applied to Main samples or Sub samples and default is main samples or you can apply for both together i.e main sample and sub-samples options in assertion window.Let's see one by one assertions explanation in details.

How to Add Assertions

Please follow below steps to add different assertions to your Test plan or Thread Group.

1.Open Apache Jmeter from apache jmeter 3.0/bin/ folder
2.Double click on jmeter.bat file
3.JMeter window opens
4.Now right click on Test plan - add-Threads - Thread Group
5.Right Click on Thread Group - Add - Assertions- here all available assertions will displays.

Response Assertions

Response Assertions allows you to verify the response of the samples with the help of different patterns as displaying below screenshot.
Response Assertion
Response Assertion Control Panel

Patterns are

  1. Contains
  2. Matches
  3. Equals
  4. Substring
  5. Not

In Pattern to test textbox you can simply enter text as Success or to verify the title of the page as Jmeter Tutorials or Assertions in Jmeter etc and you can select response Field to test as Text Response , Document(Text) , URL Sampled , Response Code (200 - ok ,404 - HTTP Error etc) , Response Message ,Response Headers and Ignore Status.As per above pattern you can verify the Response of samplers with Response Assertions.

Example:

In application I want to verify the title then we will select options as below.

Apply to  : Main Sample Only
Response Field to Test : Text Response
Patterns Matching Rules : Contains - It will search entire web page and verify the response
Pattern to Test  - Assertions in Jmeter examples

Note:You can add multiple assertions to any samples to verify the response.

Duration Assertion

As per Duration Assertion it will verify each response time whether sample response will receives within specified duration in milliseconds,in case response is not received for that particular request in specified assertion time then that request will get Failed.
Duration Assertion
Duration Assertion Control Panel


Duration Assertion will have below options

1.Apply to : Main Sample and Sub-Samples , Main Sample Only and Sub-Sample Only
2.Duration to Assert : Duration in Milliseconds - The maximum number of milliseconds for each response should receive.

Size Assertion

Size assertion in JMeter verifies what are the bytes it should have while complete that particular request.Size assertion control panel provides below types .
Size Assertion
Size Assertion Window


Equals to
Not Equal to
Greater than,
Less than,
Less than equal to
Greater than equal to for a given number of bytes.

In case bytes size is matches than it will Pass other wise assertion will fails.

XML Assertion

The XML Assertion verify that the gives response data officially contains a correct XML document or not. It does not corroborate the XML based on a DTD or schema to do any additional validation process.

XML Assertion
XML Assertion window



BeanShell Assertion

The Beanshell Assertion in jmeter is useful in validate the response of request with the help of BeanShell script,to learn Beanshell scripting please read Beanshell Tutorials.
BeanShell Assertion
Bean Shell Assertion Panel



Beanshell assertion window displays following details

Name - Name of the BeanShell Assertion
Comments - you can provide any comments regarding this assertion
Reset bsh.interpreter before each call - In case this option is selected, than the interpreter will be recreated for each samples and it is useful only when your scripts runs for longer time.
Parameters - Specified parameters to pass into your Beanshell script
Script File - In case you have script file ,you can run your assertion with the file with proper script in the file and path of the script file.
Script - This area provides to option to create a script to validate the response of samples.

HTML Assertion

The HTML Assertion validates the HTML syntax of the response data using JTidy option as below mention screenshot.The HTML assertion has below options to verify the response.
HTML Assertion
HTML Assertion window


Tiday Settings

Tidy settings has below option

Doctype : Doctype has omit,auto,strict and loose list items.
Format : It has HTML,XHTML and XML options
Error Only : Verifies only errors in HTML format as selected formats
Error threshold : No of errors allowed before alloting the particular request response as failed
Warning threshold : Number of warnings allowed before alloting the particular request response as failed
Filename : Name of the file to which report is to be write with results as below details written in txt file

Error HTML Assertion Results:

line 2 column 1 - Warning: unknown attribute "xmlns:expr"
line 2 column 1 - Warning: unknown attribute "xmlns:data"
line 2 column 1 - Warning: unknown attribute "xmlns:b"
line 16 column 1 - Warning: unknown attribute "property"
line 17 column 1 - Warning: unknown attribute "property"
line 18 column 1 - Warning: unknown attribute "property"
line 24 column 128 - Warning: Warning: unescaped & or unknown entity "&zx"
InputStream: Doctype given is ""
InputStream: Document content looks like XHTML 1.0 Transitional
212 warnings, 25 errors were found!
This document has errors that must be fixed before
using HTML Tidy to generate a tidied up version.
The table summary attribute should be used to describe
the table structure. It is very helpful for people using
non-visual browsers. The scope and headers attributes for
table cells are useful for specifying which headers apply
to each table cell, enabling non-visual browsers to provide
a meaningful context for each cell.
For further advice on how to make your pages accessible
see "http://www.w3.org/WAI/GL". You may also want to try
"http://www.cast.org/bobby/" which is a free Web-based
service for checking URLs for accessibility.


XPath Assertion


The XPath assertion in JMeter to verify the response of samples with the help of XPath,please read this post for clear understanding with real time examples,How to write XPath assertion to verify particular request response in Jmeter.


XML Schema Assertion


The XML schema assertion is able to validate XML scheme in particular request response to verify assertion is pass or fail.

XML Schema Assertion
XML Schema Assertion

Apache Jmeter Web Test Plan

Apache Jmeter providing option to prepare web test plan to perform performance testing of your website in QA or production environment.Let us build simple web test plan ,here I am using my blog where pages are end with HTML extension.It is very easy to build web test plan in JMeter.

Apache Jmeter Web Test Plan

Please follow below easy steps to create JMeter Web Test Plan to perform load testing for different HTTP Requests of your applications.

Step 1 : Open Jmeter


Open Jmeter from F:\Java_Applications\apache-jmeter-3.0\bin folder by double click on jmeter.bat file in windows operating system,the JMeter windows open as below.

Apache Jmeter Web Test Plan


Step 2 : Test Plan 


Change the Test plan name as Software Testing ,i choosen this name because i am preparing Test plan for Software Testing blog,so you can mention any simple name for your Test Plan as mention below.

Test Plan Options


No need of Changing below Option.

1.Run Thread Groups Consecutively(i.erun groups one at a time).
2.Run teardown Thread Groups after shutdown of main threads.
3.Functional Test Mode.

Step 3 : Add Thread Group


Add Thread Group by Right Click on Test Plan - Add - Threads(Users) - Thread Group,Thread Group is the main component to access Samples , Controllers , Assertions and Listeners components
in our Test plan to verify the performance of Samples.

Apache Jmeter Web Test Plan
Threaad Group

Thread Group has below options

Thread Properties:


1.Number of Threads(Users)
2.Ramp-Up Period(in Seconds)
3.Loop Count []Forever.

Rename the Thread Group as VUsers,Just follow same as below window configurations.

Step 4 : HTTP Sampler


Now it's time to add HTTP Samplers in our Test Plan under Thread Group to add web application ,just right click on Thread Group - Add - Sampler - HTTP Request.It will add HTTP Request
under Thread Group and below window appears as below.
Apache Jmeter Web Test Plan
HTTP Request


HTTP Request has below configurations

Name - Change the name of the Request as Selenium Tutorials because we are adding Selenium Tutorials html page from blog.
Server Name or IP - ServerName indicates on which server it is deployed here server name is my blog softwaretestutorials.blogspot.in,in case in your company any ip address is providing then please add ip address here
Port - here not required,in case any port number is required in your company applications please enter port number.
Protocol - Here protocol is not required presently,will keep this as blank AS IS.
Path - Here path will mention with  ' / ' to seperate the html pages as Example : /p/selenium-tutorials.html then while running it will run as softwaretestutorials.blogspot.in/p/selenium-tutorials.html

Step 5 : Listeners


Listeners able to check your test plan HTTP request response whether request is giving proper response as a realtime environment.Here i am adding View Result Tree to view HTTP Request response ,in this listener you can view the response as Text,HTML,JSON etc formats.

Add Listeners:


  • Right click on Thread Group.
  • Click on Add - Listners.
  • Select View Result Tree in list items.Please see below View Result Tree window.
Apache Jmeter Web Test Plan
Jmeter Listners


Step 6 : Execute Test Plan


We have added all required Samplers,configured required sampler details as Server Name,Path etc and added Listeners to view the HTTP Sampler results.We can use Assertions to verify whether response is valid or not inorder to check PASS or FAIL.

Apache Jmeter Web Test Plan
Failed Requests


  • Now run the Test Plan by clicking on Green color icon or
  • Select Run menu and Click on Start option(Ctrl + R)
  • I have added two HTTP requests.

Please save your Test plan because it will ask you to save test plan and Save the Test plan as SoftwareTesting.jmx format and in Jmeter all test plans saves in JMX formats and you will observe your test plan will start running with one thread user ,1 second ramp up period and loop count is 1 ,here you can change number of thread users.Once the test plan running completed all your HTTP requests results will display in ViewResults Tree listeners.

View Results Tree


Your all samples results will display in Listeners as below and below points observed

Green Color - indicates particular HTTP Sampler request is Passed.
Red Color - Indicates particular HTTP Sampler request is Failed,it could be different reasons.

Apache Jmeter Web Test Plan



Here i have used only simple Test plan and you can run test plan with many number of Thread Users such as 10,20 or 25 etc users,Different Ramp-Up period by this you can check proper average response time for different HTTP requests.You can check Summary Report Listener to check Min,Max,Average in milliseconds,Throughput,Error percentage etc details as below.

Summary Report


Apache Jmeter Web Test Plan
Summary Report

Transaction controller in jmeter

Transaction Controller in Jmeter which is useful in measures child samples time taken to complete the transactions.Performance Testing with JMeter for Web applications i.e Samples which is HTTP sample requests and which have resources as Images,Stylesheets,Css,recording etc.

Transaction controller in jmeter

What is Transaction Controller?

Transaction Controller is generates an extra samples same as HTTP Samples in order to measures the overall time taken or response time of Transaction controller of child test samples,don't worry we will learn in details with real-time examples.

Transaction Controller in Jmeter

Transaction Controller has two check boxes,those are

1.Generate Parent Samples
2.Include duration of timer and pre-post processors in generated sample - It is the time which includes all processing samples within the Transaction controller , not just the HTTP samples.

Generate Parent Samples

If you check Generate Parent Samples check box in Transaction Controller then in Summary Report it will display only Transaction Controller Label and remaining nested HTTP Samples will not display in Summary Report.Please see below screenshot.Overall Response time is taken will display in Transaction Controller with nested HTTP Samples.It is not good practice to perform or run your test plan to perform performance testing of a proper test scenario.

Transaction controller in jmeter

Test Scenario

Open Product Page - Search The product - Checkout the Product page - Perform Payment

The above scenario will look like as below

Transaction Controller
Open Product Page Samples 1
Search The product sample 2
CCheck out the product sample 3
Payment sample 4

Above four samples are nested elements for Transacstion Controller,if you run above scenario or test plan with Generate Parent Samples check box on it will display only Transaction Controller label name and will not display all four samples label name in summary report.

Transaction controller in jmeter
Summary Report


If you want to check all the samples label name in Summary Report don't check Generate Parent Samples check box in Transaction Controller.

Transaction Controller without Generate Parent Samples

Uncheck Generate Parent Samples in Transaction Controller screen.

Transaction controller in jmeter


Now run your Test plan it will display Nested HTTP Samples + Transaction Controller Sample in Summary Report(Which will display all nested samples details as below).

Transaction controller in jmeter
Summary Report-Transaction Controller

Transaction Controller Problems

1.In Case one sample is failed then entire Transaction Controller will fail
2.In case any one sample assertion is failed then entire Transaction Controller will fail.