I am running a test with a loop and want to capture the session of the test and write it to a CSV column( not row) during run
Eg
Run1: ses1
Run2:ses2
Run 3: se3
CSV
Ses1, ses2, ses 3
In any of the JSR223 Test Elements use the following Groovy code:
new File('/path/to/your/file.csv') << vars.get('session') << ','
Replace session with the actual name of the JMeter Variable holding your session.
Related
Currently I am saving variable values in ".txt" file using beanshell post-processor, I want to save variable value into a pdf file , is there any way I can achieve it?
To save variable value in a text file, i am using below code:
var1= vars.get("myVariableValue");
f = new FileOutputStream("D:/myTextFile.txt",true);
p = new PrintStream(f);
this.interpreter.setOut(p);
p.println(var1);
f.close();
You need an external library like PdfBox for this
You will need to have PDFBox in JMeter Classpath
Since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language for scripting
Assuming all above:
Download pdfbox-2.0.24.jar and fontbox-2.0.24.jar files and put them to "lib" folder of your JMeter installation
Restart JMeter to pick up the "jar"
Add an appropriate JSR223 Test Element to your Test Plan
Put the following code into "Script" area:
import org.apache.jmeter.threads.JMeterVariables
JMeterVariables vars = new JMeterVariables()
vars.put('myVariableValue','hello')
def document = new org.apache.pdfbox.pdmodel.PDDocument()
def page = new org.apache.pdfbox.pdmodel.PDPage()
document.addPage(page)
def contentStream = new org.apache.pdfbox.pdmodel.PDPageContentStream(document, page)
contentStream.setFont(org.apache.pdfbox.pdmodel.font.PDType1Font.COURIER, 12)
contentStream.beginText()
contentStream.showText(vars.get('myVariableValue'))
contentStream.endText()
contentStream.close()
document.save('myPDFFile.pdf')
document.close()
That's it, you should see myPDFFile.pdf file in JMeter's working directory
I have two load tests below with each one being in their separate test cases. This is using SOAP UI free:
Currently I have to manually select a load test, run it manually, wait until it finishes and then manually export the results before manually moving onto the next load test and performing the same actions.
Is there a way (and if so how) to be able to automatically run all the load tests (one by one) and extract each of it's own set of results in a file (test step, min, max avg, etc). This is to save the tester having to do manual intervention and can just let the test run whilst they do other stuff.
You can use the load tests command line, the doc is here.
Something like
loadtestrunner -ehttp://localhost:8080/services/MyService c:\projects\my-soapui-project.xml -r -f folder_name
Using these two options:
r : Turns on exporting of a LoadTest statistics summary report
f : Specifies the root folder to which test results should be exported
Then file like LoadTest_1-statistics.txt will be in your specified folder with csv statistics results.
inspired with answer of #aristotll )
loadtestrunner.bat runs the following class : com.eviware.soapui.tools.SoapUITestCaseRunner
from groovy you can call the same like this:
com.eviware.soapui.tools.SoapUITestCaseRunner.main([
"-ehttp://localhost:8080/services/MyService",
"c:\projects\my-soapui-project.xml",
"-r",
"-f",
"folder_name"
])
but the method main calls System.exit()...
and soapui will exit in this case.
so let's go deeper:
def res = new com.eviware.soapui.tools.SoapUITestCaseRunner().runFromCommandLine([
"-ehttp://localhost:8080/services/MyService",
"c:\projects\my-soapui-project.xml",
"-r",
"-f",
"folder_name"
])
assert res == 0 : "SoapUITestCaseRunner failed with code $res"
PS: did not tested - just an idea
I am having issues with my jmeter test.
I am using Blazemeter Taurus (bzt command) to run it, and I run it as a Jenkins job.
My issue is:
I created user defined values, which I set as Jmeter properties so I can pass them params from the command line:
example for a property I set
The issue occurs when I pass a number:
bzt -o modules.jmeter.properties.profileId=413 -o modules.jmeter.properties.lab=8050
these are parsed as 8050.0 and 413.0
Because the "lab" param is embeded in a url, it breaks the url.
When running this via command line with the jmeter command, this works fine.
I tried working around this with a bean shell sampler that does the following:
int a = Integer.parseInt(vars.get(${lab}));
String raw = String.ValueOf(a);
String processed = raw.substring(0,5);
vars.putObject("lab" ,new String(processed));
props.put("lab", lab);
log.info("this is the new " + ${lab});
but this fails.
any help would be appreciated.
In regards to Taurus issue - report it via Taurus support forum
In regards to Beanshell workaround - your code is not very correct, you need to amend it as follows:
int lab = (int)Double.parseDouble(props.get("lab"));
int profileId = (int)Double.parseDouble(props.get("profileId"));
props.put("lab", String.valueOf(lab));
props.put("profileId", String.valueOf("profileId"));
log.info("lab=" + lab);
log.info("profileId=" + profileId);
as stuff passed via -o modules.jmeter.properties should be accessed via props shorthand, not vars
Demo:
See How to Use BeanShell: JMeter's Favorite Built-in Component guide for more information on using JMeter and Java API from Beanshell test elements in your JMeter test.
In Bean shell sampler I am getting the line count how to pass the line count to the Threadgroup
import org.apache.commons.io.FileUtils;
int lines = FileUtils.readLines(new File("path to data file")).size();
vars.put("lines", String.valueOf(lines));
this lines variable I want to use to thread group how I can achieve this
please help me on this
Updating the output of Debugsampler
JMeterVariables:
JMeterThread.last_sample_ok=true
JMeterThread.pack=org.apache.jmeter.threads.SamplePackage#1e59359f
START.HMS=081505
START.MS=1449648905577
START.YMD=20151209
TESTSTART.MS=1449652524822
applicationname=test
buildinfo=../data/Test.csv
env=Test
lines=77
package=.zip
First, you can use Debug sampler to verify if you are successfully getting the desired value in your variable.
Second, you can simply call the this variable just like other user defined variables in JMeter. Put ${lines} where required.
If you still face any issues, then let me know in comment or edit your question to add further details.
You cannot configure Thread Group loop count this way as it is being populated on JMeter launch. Here are the options:
Use Loop Controller instead, it is possible to set the number of loops via variable
Define "Loop Count" in Thread Group as a property, like ${__P(loops,)}. In that case you can get CSV file lines count before the test i.e. using the relevant OS command like:
type c:\temp\file.csv | find /c /v "~~~" - for Windows
cat /tmp/file.csv | wc -l for *nix
and pass the resulting value to JMeter via -J command line key as:
jmeter -Jloops=XX -t /path/to/your/testplan.jmx ...
See Apache JMeter Properties Customization Guide for more information on JMeter properties and ways of setting and overriding them.
How can I run a specific thread group in a Test Plan from the command line? I have a Test Plan (project file) that contains two "thread groups": one for crawling a site and another for calling specific urls with parameters. From the command line I execute with Maven, like so:
mvn.bat -Dnamescsv=src/test/resources/RandomLastNames.csv
-Ddomainhost=stgweb.domain.com -Dcrawlerthreads=2 -Dcrawlerloopcount=10 -Dsearchthreads=5 -Dsearchloopcount=5 -Dresultscsv=JmeterResults.csv clean test verify
I want to pass an argument to run only one of the two "thread group" in that project file. Can you do that with JMeter? I don't want to use an IF controller unless I have to because it feels like a "hack". I know that SoapUI lets you do this with the '-s' option.
I asked this question on the JMeter forum also.
In our tests we use the while controller. It doesn't look like a hack to me and works well. You can turn thread groups on and off easily with the JMeter properties. Note you can't change its status when the test is already running though.
Add While controller - ${__P(threadActive)}
Set JMeter property on JMeter load ( -JthreadActive = true )
Run test
Please note ${__P(threadActive)} equates to ${__P(threadActive)} == true, anything other than true will result in that thread group not running