Automated JMeter tests do not always work - jmeter

I wrote multiple automated JMeter tests. They consist of sending in files to REST endpoints, checking logs and databases. They work fine. I wrote a batch script to run all of them, automatically. However, sometimes they run into errors, and I do not understand why.
Here is the script:
#echo off
for /r %%i in (tests\*) do (CALL jmeter -n -t %%i -l result.txt)
CALL >nul find "failed" result.txt && (
CALL echo ------Failed.-------
) || (
CALL echo ------Success!-------
)
CALL pause
I check the log, and it's always something about the logs. for example:
Test failed: text expected to contain /Some text I am testing for/
I am using Response Assertion inside SSH Command, and there is a Constant Timer before the assertions, so there is ample time for the log to react to the sent in files.
When I use GUI or CLI to run a single test case, they work. But running them using the script always results in at least some errors, like the one I quoted above.

The reason is obvious: your Sampler doesn't produce the expected output.
We cannot tell you why does it happen, you need to figure out the reason yourself.
I would suggest either switching JMeter's .jtl results file to XML format and to include the response data so you could inspect the full response and see what does the SSH Command sampler return.
the relevant changes to the command line will look like:
jmeter -Jjmeter.save.saveservice.output_format=xml -Jjmeter.save.saveservice.response_data=true -n -t %%i -l result.txt
you will then be able to open the result.txt in the View Results Tree listener and see what was the actual response of the SSH Command sampler.
References:
Configuring JMeter
Results File Configuration
Apache JMeter Properties Customization Guide
Overriding Properties Via The Command Line

Related

how can I add multiple command in jmeter

I'm using jmeter in macOS(Big sur) to test some actions.
Before main test, I am trying to use JMeter naturally.
What I wanna do is to execute multiple commands by jmeter(OS Process Sampler)
The scenario is like this.
I want to print out the current path by "pwd" command.
After that, I want to make Dircetory named dir123 by "mkdir dir123" command.
Finally, I want to see all directories and files by "ls" command.
The screenshot is like this.
OS Process Sampler
And current Result by "View Results Tree" is like this.
View Results Tree
It seems the first command "pwd" is the only command executed.
How can I execute more commands?
You're trying to execute 3 different commands so my expectation is that you should be using 3 OS Process Samplers.
If some reason you want/need/have to do it using single OS Process Sampler - you can use && operator to connect these 3 commands like:
pwd && mkdir dir123 && ls
More information:
How to Run External Commands and Programs Locally and Remotely from JMeter
Bash Reference Manual - List of Commands

other commands executed failed after JMeter command-line

execute JMeter test in command-line and deal with the output files
jmeter -n -t test.jmx -l output.jtl
copy output.jtl output_A.jtl
after execute this file, I find that the 2nd line copy... is not executed.
Actually, jmeter will be executed for a while, and the subsequent lines may be ignored.
Now I put jmeter in another file and call it from the main command file. Can I put them into one file?
How can I deal with such situation?
Maybe you need to add && between your commands like:
jmeter -n -t test.jmx -l output.jtl && copy output.jtl output_A.jtl
More information: Using multiple commands and conditional processing symbols

Jmeter displays doubled results when running in non gui mode

I have a Test plan which when I run in the Gui Mode execute the sampler one time, but when I start the Test Plan from the command line I get the sampler to be running twice.
I have deleted the result.jtl file to insure that the results are not accumulated.
Without seeing your test plan it's hard or even impossible to say what's the reason as there are too many possible options, the most straightforward I can think of is:
You have a Listener (or two) somewhere in the test plan configured to write data into the same file which you specify via -l command-line argument
You have resultcollector.action_if_file_exists=APPEND property defined somewhere
So try out the following way of running the test:
jmeter -n -t test.jmx -l result.jtl -f -Jresultcollector.action_if_file_exists=DELETE
where:
-f forces JMeter to overwrite the .jtl results file
resultcollector.action_if_file_exists=DELETE property does the same for Listeners
More information:
Full list of JMeter command-line options
JMeter Properties Reference
Apache JMeter Properties Customization Guide

JMeter prints summary view on the command line for one script but not another

I have 2 JMeter scripts which I am running from the command line. In the first script, I can see the summary view on the console while the test is running. That is:
summary + 3234 in 00:00:30...
summary = 34872 in 00:31:30...
In the other script, none of the summary data is printed, although the script will run correctly and save the data to the output file.
I see the same behavior for these script whether I run them from a Windows command line or from Linux. What is the trick to enable the summary output for my second script?
I can think of 2 options:
Your "other" script runs less than 30 seconds and by default Summariser "ticks" every 30 seconds. If this is the case you can amend summariser.interval property so it would occur more frequently
You have Transaction Controllers everywhere in your "other" script and by default Summariser doesn't report the sample results originating from the Transaction Controllers. If this is the case - set summariser.ignore_transaction_controller_sample_result property to false
More information:
Configuring JMeter
Summariser - Generate Summary Results - configuration
Seeing similar behavior. The result summary is not printed when I use conf path parameter to run the script. Whereas it is shown when I remove the -p parameter
jmeter -n -t fullpathtojmx -p fullpathtopropertiesfile -l fullpathtojtlfile

How to email the updated test result in jmeter

I have a simple HTTP Request sampler in a test plan. And, viewing the result through "Aggregate Report" and writing the same results to a file. I have used "SMTP Sampler" in "tearDown Thread Group" and also used the "Test Action" to wait for a while.
Issue is, once I execute the test-case, in mail I got the previous run results instead of the new one.
Here is the screen-shot of my test plan.
Please help. Thanks in advance!
I don't like your "Test Action to wait for a while" approach as it may be not enough so you won't be able to tell for sure whether JMeter stored the most recent results or not.
I would suggest the following: add jmeter.save.saveservice.autoflush=true line to user.properties file (it's located under /bin folder of your JMeter installation) and on next JMeter start it will be storing every single line.
So
Apply aforementioned property change
Configure your SMTP Sampler to send results.jtl file
Disable all the listeners.
Run JMeter in command-line non-GUI mode as follows
jmeter -n -t /path/to/your/testplan.jmx -l /path/to/results.jtl
As an alternative to editing user.properties file you can pass the property via -J command line argument like:
jmeter -Jjmeter.save.saveservice.autoflush=true -n -t /path/to/your/testplan.jmx -l /path/to/results.jtl
See Apache JMeter Properties Customization Guide for more information on JMeter properties and ways of working with them.

Resources