how to run jmeter with ANT - ant

I want to display Jmeter results via html. the html dashboard is not informative enough, so I want to use the ant solution.
I installed ant as expected
I took my testplan.jmx and copy it to
C:\Jmeter_4.0\apache-jmeter-4.0\extras
I changet the testplan.jmx to Test.jtl
I entered to cmd cd C:\Jmeter_4.0\apache-jmeter-4.0\extras
I entered ant and press enter
the test plan always take 20 minutes and in ant 12 second that is very stange since I have delay of 15 minutes.
I opened Test.html and instead of seeing results I saw the test plan as xml. and jmeter not start or even worked. what I am missing , why ant not runnung the testplan. the results is not even html see pic

You need to rename your file to Test.jmx, not to Test.jtl.
If there is a Test.jtl file already there - you will need to delete it as by default JMeter Ant Task will add new results into existing Test.jtl file which is not something you should be looking for.
There is another option: you can generate Ant-style HTML report from .jtl results file.
Execute your script "normally" in non-GUI mode like:
jmeter -n -t testplan.jmx -l Test.jtl
Copy Test.jtl file to "extras" folder of your JMeter installation
Execute ant xslt-report command.
That's it, you should see the results in HTML form as Test.html file
See Five Ways To Launch a JMeter Test without Using the JMeter GUI article for more information on different ways of running a JMeter test from command line and from Java code.

Related

Jtl file is empty when running Jmeter using ant

I am trying to run Jmeter with ant, (since I want to display the results of test, with all the steps).
The issue is that after I managed to run the command the Jtl file is empty, I am trying to run the basic test.jmx default test.
I run the command ant -Detest=Test run
the build is successful but the jtl results are empty. moreover it is finished after one second, while if I run via UI mode it should take more time.
Can someone please advise how to use ant with Jmeter, or how to get fully reports like in csv in html out put?
[][build results]
[][build.xml from ant\bin location]
[][location of test.jtl results file]
[][results are empty]
Most probably something is wrong with your JMeter test itself, i.e.
JMeter failed to start (installation or configuration issues)
it has 0 threads in Thread Group
there is an If Controller condition which prevent test execution
the test relies on a JMeter Plugin which is not installed
etc.
So I would recommend amending your build.xml file and enable writing JMeter log file by adding the next line to <jmeter> section: jmeterlogfile="${testpath}/jmeter-ant.log >
So it would look like
<jmeter
jmeterhome="${jmeter.home}"
testplan ="${testpath}/${test}.jmx"
resultlog="${testpath}/${test}.jtl"
jmeterlogfile="${testpath}/jmeter-ant.log>
When you run your test one more time you should see jmeter-ant.log file in the folder where your .jmx file lives.
More information: JMeter Ant Task

Jmeter with ant - reports creation

I am trying to create report using ant in jmeter, meaning the full report.
I downloaded ant and it is installed as expected.
first I want to understand if ant command need to perform after test plan ran in the past? meaning it is offline process that creates the html reports? after the test plan finished?
Or is it command that actually used to run the test plan and create the html, meaning I do not need to run jmeter before?.
I used this command
jmeter -n -t C:\JMETER\Framework\Test_Fragment\Kung_Fu.jmx -l C:\Users\stackoverflow\Desktop\Jmeter_reports\results22_05_2018.csv
to run jmeter from command line, and create csv, so do I need two commands? one for creating csv and one for the ant? and if I create the csv where can I find the jtl of the testplan.
Name of test plan kung_fu
name of csv results22_05_2018.csv
what are the processes to run he ant, since I rename the Kung_Fu.jmx to test.jmx and put it in extras folder and when I command ant, it says test.jtl is not found.
can someone give a full explanation about the whole process
Rename results22_05_2018.csv into results22_05_2018.jtl and copy it to "extras" folder of your JMeter installation
Execute the following command in "extras" folder of your JMeter installation:
ant -Dtest=results22_05_2018 xslt-report
HTML report will be available as results22_05_2018.html
For more details see:
build.xml - reference Ant build file, by default it:
looks for Test.jmx file in the current folder
executes it and stores the result into Test.jtl file
applies XSLT transformation to the Test.jtl file and generates HTML file out of it.
JMeter Ant Task
Five Ways To Launch a JMeter Test without Using the JMeter GUI

Jenkins "Console Output" log location in filesystem

I want to access and grep Jenkins Console Output as a post build step in the same job that creates this output. Redirecting logs with >> log.txt is not a solution since this is not supported by my build steps.
Build:
echo "This is log"
Post build step:
grep "is" path/to/console_output
Where is the specific log file created in filesystem?
#Bruno Lavit has a great answer, but if you want you can just access the log and download it as txt file to your workspace from the job's URL:
${BUILD_URL}/consoleText
Then it's only a matter of downloading this page to your ${Workspace}
You can use "Invoke ANT" and use the GET target
On Linux you can use wget to download it to your workspace
etc.
Good luck!
Edit:
The actual log file on the file system is not on the slave, but kept in the Master machine. You can find it under: $JENKINS_HOME/jobs/$JOB_NAME/builds/lastSuccessfulBuild/log
If you're looking for another build just replace lastSuccessfulBuild with the build you're looking for.
Jenkins stores the console log on master. If you want programmatic access to the log, and you are running on master, you can access the log that Jenkins already has, without copying it to the artifacts or having to GET the http job URL.
From http://javadoc.jenkins.io/archive/jenkins-1.651/hudson/model/Run.html#getLogFile(), this returns the File object for the console output (in the jenkins file system, this is the "log" file in the build output directory).
In my case, we use a chained (child) job to do parsing and analysis on a parent job's build.
When using a groovy script run in Jenkins, you get an object named "build" for the run. We use this to get the http://javadoc.jenkins.io/archive/jenkins-1.651/hudson/model/Build.html for the upstream job, then call this job's .getLogFile().
Added bonus; since it's just a File object, we call .getParent() to get the folder where Jenkins stores build collateral (like test xmls, environment variables, and other things that may not be explicitly exposed through the artifacts) which we can also parse.
Double added bonus; we also use matrix jobs. This sometimes makes inferring the file path on the system a pain. .getLogFile().getParent() takes away all the pain.
You can install this Jenkins Console log plugin to write the log in your workspace as a post build step.
You have to build the plugin yourself and install the plugin manually.
Next, you can add a post build step like that:
With an additional post build step (shell script), you will be able to grep your log.
I hope it helped :)
Log location:
${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_NUMBER}/log
Get log as a text and save to workspace:
cat ${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_NUMBER}/log >> log.txt
For very large output logs it could be difficult to open (network delay, scrolling). This is the solution I'm using to check big log files:
https://${URL}/jenkins/job/${jobName}/${buildNumber}/
in the left column you see: View as plain text. Do a right mouse click on it and choose save links as. Now you can save your big log as .txt file. Open it with notepad++ and you can go through your logs easily without network delays during scrolling.
I found the console output of my job in the browser at the following location:
http://[Jenkins URL]/job/[Job Name]/default/[Build Number]/console
This is designed for use when you have a shell script build step. Use only the first two lines to get the file name.
You can get the console log file (using bash magic) for the current build from a shell script this way and check it for some error string, failing the job if found:
logFilename=${JENKINS_HOME}/${JOB_URL:${#JENKINS_URL}}
logFilename=${logFilename//job\//jobs\/}builds/${BUILD_NUMBER}/log
grep "**Failure**" ${logFilename} ; exitCode=$?
[[ $exitCode -ne 1 ]] && exit 1
You have to build the file name by taking the JOB_URL, stripping off the leading host name part, adding in the path to JENKINS_HOME, replacing "/job/" to "/jobs/" to handle all nested folders, adding the current build number and the file name.
The grep returns 0 if the string is found and 2 if there is a file error. So a 1 means it found the error indication string. That makes the build fail.
Easy solution would be:
curl http://jenkinsUrl/job/<Build_Name>/<Build_Number>/consoleText -OutFile <FilePathToLocalDisk>
or for the last successful build...
curl http://jenkinsUrl/job/<Build_Name>/lastSuccessfulBuild/consoleText -OutFile <FilePathToLocalDisk>

Jmeter+Jenkins Parameters

I am trying to run jmeter(.jmx) file using Jenkins by passing Number of Threads as a Parameter. Build getting success but .jmx file is not running. And also not showing any error in console.Following are my setup
In Jmeter Thread properties --Number of thread (Users)- ${__P(USERS,1)
In Jenkins job Created build string parameter -- USER_COUNT
Build using Execute shell and following is my command
cd /apache-jmeter-2.13/bin
./jmeter.sh -n -t /jmxFiles/Jbpm6Rest3Jenkins1.jmx -l /jmxFiles/SIP.jtl -JUSERS=%USER_COUNT%
While starting build passing USER_COUNT value from Jenkins
Following is the Jenkins console output
Jenkins Console Output
Not sure where i am doing wrong.
Note: Not using Ant/Maven to run jmx file.
As the other answer mentioned, change the %_USER_COUNT% to ${USER_COUNT}.
But is there any specific reason you are not using Ant/Maven?
Eventhough you should be able to run your jmeter test using a simple shell script, using Ant/Maven might make your life easier while generating report, charts etc.
I would advise you check the below links.
http://www.testautomationguru.com/jmeter-continuous-performance-testing-part1/
http://www.testautomationguru.com/jmeter-continuous-performance-testing-part2/
From the output, seems you are running a shell build step ($ /bin/sh -xe ....), which means your Jenkins runs on Linux (?). Also the paths use forward slash (/)....
You should put the string ${USER_COUNT} as part of your command (%USER_COUNT% is windows style).
I hope this helps.

How to use Apache Ant in Jmeter?

How to generate Html reports from using Apache ant in Jmeter.
Please attach screenshots
There won't be too much screenshots, however I believe the answer will still be helpful
Install Apache Ant. Make sure that /bin folder of Ant installation is in your PATH
Go to "extras" folder of your JMeter installation in command propmt.
Type ant
If everything goes well you should see "BUILD SUCCESSFUL" message
Ant will generate 2 artifacts:
Test.jtl - XML file with results
Test.html - HTML wile with results which can be viewed in browser
If steps 1-5 are successful you can now replace /extras/Test.jmx with your own JMeter test, delete Test.jtl file and execute step 3 for your test script.
See following references:
/extras/build.xml Ant build file
JMeter Ant Task manual
Five Ways To Launch a JMeter Test without Using the JMeter GUI guide which includes launching JMeter via Ant.
JMeter produces the result in XML format. You need an XSLT file to convert this to a nice HTML.
This site has the detailed steps on running JMeter tests with ANT + creating HTML reports + Creating charts.
http://www.testautomationguru.com/jmeter-continuous-performance-testing-part1/

Resources