How can we remove the current date from gradle generated .html and .xml file while running JMeter script from build.gradle file? - gradle

I am running my JMeter script from build.gradle file. After executing it is generating the html and xml report files with the script name. My problem is that current date is also present with the script name. Please tell me how to remove the current date from output files.
Gradle- gradle-2.4 version and HTML Report Publisher plugin in Jenkins

I'm assuming you're using com.github.kulya/jmeter-gradle-plugin ?
The date is tacked on to testplan name while generating results, which is then used while generating reports. The intention I believe is so that the results are not overwritten each time you run a test. The way it is currently implemented, it isn't configurable.
If you have only one set of result and report per jmx file, You should be able to define a new task though to strip out the date/timestamp from the results and report files.
task stripDateFromReport() {
new File("build/jmeter-report").eachFileMatch(~/.*.[xml|html]/){ file ->
def m = file.getName() =~ /^(.*?)-[0-9]{8}-[0-9]{4}(.*?)$/
file.renameTo(new File(file.getParentFile().getCanonicalPath()+ File.separator + m[0][1] + m[0][2]))
}
}
Note: If you have more than one report with just a different timestamp, this will obviously fail because once the dates are removed the filenames are not unique anymore.

Related

Azure Load test preview unable to read data from parameterized CSV file in JSR223 Sampler

I used JSR223 Preprocessor to create the request body for a POST JSON request. I used Groovy language for it The code has some parameterization so, I mentioned the path for CSV file in the script as below and attached the Order.csv file to the test plan in load test preview.
CSV file path in the script:
"List lines = new File("Order.csv").readLines()"
So whenever I run the test in Azure load test preview, the is the error message im encountering:
javax.script.ScriptException: java.io.FileNotFoundException: Order.csv (No such file or directory)
How can I fix this. Please Help.
I tried just mentioning the CSV file name in the code and attached the CSV file to the Load test preview along with .jmx file.
This is throwing error saying, File not found
How do you know where guys from Microsoft are placing the CSV file and why do you expect them to copy it to the same place where the .jmx script lives?
I would suggest amending your Groovy script to get the file location dynamically using FileServer class, i.e. change this line:
List lines = new File("Order.csv").readLines()
to something like:
List lines = new File(org.apache.jmeter.services.FileServer.getFileServer().getBaseDir() + File.separator + 'Order.csv').readLines()
More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?

Can we rename the file name in Jmeter during run time which will be uploaded in the script

I have to upload audio files in the Jmeter script which is stored in my system. E.g. abc.wav is the file store in the system. But in the script the file name format should be "Testinstanceid__itemid__ interactionid.wav". Here "Testinstanceid" is the dynamic value which we can get from correlation of previous response.
But how I can upload the file with this dynamic value during run time and it will upload correctly in the script.
Thanks in advance
You can copy your abc.wav file to the Testinstanceid__itemid__ interactionid.wav file using JSR223 PreProcessor and Groovy script like:
org.apache.commons.io.FileUtils.copyFile(new File('abc.wav'), new File(vars.get('Testinstanceid') + '__itemid__ interactionid.wav'))
once you finish the uploading you can delete the file to free up your drive in JSR223 PostProcessor like:
org.apache.commons.io.FileUtils.deleteQuietly(new File(vars.get('Testinstanceid') + '__itemid__ interactionid.wav'))
where vars stands for JMeterVariables class instance, check out the JavaDoc for all available functions

Jmeter: How to create HTML dashboard in jmeter using saved summary csv file

I am using following command to generate HTML dashboard:
jmeter -g C:/Users/E01659/Desktop/feb28/feb28_10_3600.csv -o C:/Users/E01659/Downloads/apache-jmeter-5.1/bin/sonali/
Following error is coming: File
'C:\Users\E01659\Desktop\feb28\feb28_10_3600.csv' does not contain the
field names header, ensure the jmeter.save.saveservice.* properties
are the same as when the CSV file was created or the file may be read
incorrectly when generating report An error occurred: Mismatch between
expected number of columns:17 and columns in CSV file:11, check your
jmeter.save.saveservice.* configuration or check line is complete
errorlevel=1
From the error message, it is clear that - CSV file created earlier don't have the header as the first line. When you want to create the APDEX Dashboard from CSV file, JMeter expects that files are created with correct Save Service Configuration. You can change Result file config which are present in jmeter.propertes file.
You may need to change the line as below, so that file created has the headers name as required
jmeter.save.saveservice.label = true
The command you're using is correct, the reason of failure is mismatch of the .jtl file contents and what JMeter expects it to be.
If you got this feb28_10_3600.csv file from execution on another JMeter installation - make sure that JMeter's result save configuration on the machine where you're trying to generate the report is identical to the JMeter installation where JMeter was running.
Inspect the associated JMeter properties and amend them to for 100% match, once done you should be able to normally generate the dashboard.
If you still experience the differences update your question with first 2-3 lines of your .jtl results file.
You are receiving this error (most likely) due to a corrupt line at the end of your file. Just execute a 'tail ' to see the last few lines. Most likely, your last line is missing columns due to an abrupt stop in the test. Once you delete the problematic line, you should be able to generate the HTML report.

Gradle Copy Task up-to-date determination

I'm relatively new to gradle and trying to set up a backup task. I have a few examples, first I'll describe the goal:
I have a number of files in a directory (call it the "data directory"). When the contents of Any File in this data directory are modified, I want to create a new directory in a "backup location" and copy Every File in the data directory into the directory that was just created. The name of the directory created will contain the current date and time. For now, the data directory contains no subdirectories.
I had this working fine when the "data directory" contained one file and all I wanted to do was rename that file to include the date. Example:
task copyDocs(type: Copy) {
from 'src/main/doc/testfile.html'
into 'build/target/doc'
rename { String fileName ->
def date = new Date();
date.format("YYYY-MM-dd--HH-mm-ss") + " " + fileName
}
}
This worked great. I could run the task "copyDocs" as many times as I wanted, but it would only create a new file if I had actually modified the contents of testfile.html. Now, I wanted to expand this so that instead of creating a new file that got renamed, it would create a new directory and copy the source file into it.
task copyDocs(type: Copy) {
def dateStr = (new Date()).format("YYYY-MM-dd--HH-mm-ss");
from 'src/main/doc/testfile.html'
into 'build/target/doc/' + dateStr
}
This did not work so great. While the directory that gets created has the name I wanted, the problem is that Every Time I run the task, it creates a new directory and copies testfile.html into it, regardless of whether this file was modified.
I know this has something to do with the 'task inputs' and such, and I have read the parts of the documentation that describe the initialization phase vs. the configuration phase and so on. What I have not found is anything specific enough to help me understand why the copy task believes it needs to be re-run in the second case but not in the first case.
Simply put, in both cases, the potential output file(s) change every time the task is run as a function of the date/time. The input file(s) Do Not Change in the case of either task. So why does the second task need to be re-run every time, but not the first task? Is there a straightforward way to "debug" gradle so that it explicitly tells me why this is?
Your time and help are greatly appreciated, I am interested in learning more about gradle as it seems like an effective and modern build system!
When it comes to copy task whether it will be executed is determined by task's inputs and outputs which are set during configuration phase (see here). Since at configuration phase output is different every time:
into 'build/target/doc/' + dateStr
(it depends on seconds, but if you trim to hours, days, months the effect will be the same but rarer) the file is copied every time the task is executed even though it hasn't changed. To fix the problem you need to alter the destination at the execution time which can be done in the following way:
task copyDocs(type: Copy) {
def dest = 'build/target/doc/'
from 'src/main/doc/testfile.html'
into dest
eachFile { fcp ->
def dateStr = (new Date()).format("YYYY-MM-dd--HH-mm-ss");
fcp.path = dest + dateStr
}
}
This way task will be executed if and only if from input differs.

An Error message occurs on command prompt while generating Dashboard from Jmeter

I have started using JMeter 3.1 recently for load testing, all I wanted to do was generate a report dashboard from a csv file.
When I run the following command from Command Prompt:
jmeter -g (csv file location) -o (Destination folder to save HTML Dashboard)
I get the error shown below:
Could not parse timestamp<1.487+12> using format defined by property.saveservice.timestamp+format=ms on sample 1.487+12 .........
I have also attached the screenshot of the error message kindly refer below:
Below is my saveservice properties that I copied into user properties file:
jmeter.save.saveservice.bytes = true
jmeter.save.saveservice.label = true
jmeter.save.saveservice.latency = true
jmeter.save.saveservice.response_code = true
jmeter.save.saveservice.response_message = true
jmeter.save.saveservice.successful = true
jmeter.save.saveservice.thread_counts = true
jmeter.save.saveservice.thread_name = true
jmeter.save.saveservice.time = true
jmeter.save.saveservice.print_field_names=true
# the timestamp format must include the time and should include the date.
# For example the default, which is milliseconds since the epoch:
jmeter.save.saveservice.timestamp_format = ms
# Or the following would also be suitable
#jmeter.save.saveservice.timestamp_format = dd/MM/yyyy HH:mm
#save service assertion
jmeter.save.saveservice.assertion_results_failure_message = true
I am not able to figure out the resaon, any help in this regard will be much appreciated.
please help, also please let me know if any addition information is required.
I have followed the below link to generate Dashboard:
http://jmeter.apache.org/usermanual/generating-dashboard.html
The answer is in your question itself:
Could not parse timestamp<1.487+12>
According to your configuration, JMeter expects first column to be in Unix timestamp format like 1487047932355 (time since beginning of Unix epoch in milliseconds)
Another supported format is yyyy/MM/dd HH:mm:ss.SSS like 2017/02/14 05:52:12.355
So there are several constraints:
The value of jmeter.save.saveservice.timestamp_format = ms should be the same during test execution and dashboard generation
You need to restart JMeter to pick the properties up. For example if you ran the test, then amended properties and then tried to generate dashboard - it might fail
There are no duplicate properties
You don't do anything with the .jtl results file between test execution and dashboard generation
My expectation is that you opened .jtl results file with MS Excel which converted timestamps into scientific notation and saved so most probably you will be able to do the opposite.
Just in case I would also recommend getting familiarised with Apache JMeter Properties Customization Guide
The default timestamp format in JMeter csv and logs is given in a Unix style format , but you can change it .
Go to (jmeterDirectory)/bin .
open jmeter.properties file .
Search for the following :-
jmeter.save.saveservice.timestamp_format
You will find it commented (Start with #) . Uncomment it and restart the Jmeter .
You can update this above property with the format you need

Resources