JMeter - SubResults are not displaying in Summary table etc - jmeter

JMeter 5.4.1.
JSR223 script contains several sub steps in complex transaction.
The sub step contains a code like that:
// SendMessage:
def myResult_SendMessage = new org.apache.jmeter.samplers.SampleResult()
myResult_SendMessage.setSampleLabel('SendMessage')
myResult_SendMessage.sampleStart()
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(text(),'Send a message')]")));
WebElement Depot_SendMessage = driver.findElement(By.xpath("//a[contains(text(),'Send a message')]"));
Depot_SendMessage.click();
myResult_SendMessage.setResponseCodeOK()
myResult_SendMessage.setSuccessful(true)
myResult_SendMessage.sampleEnd()
myResult_SendMessage.latencyEnd()
myResult_SendMessage.setResponseData(driver.getPageSource());
SampleResult.addSubResult(myResult_SendMessage,false)
I want to see all sub results, not only the main result, in "Summary table" / "Aggregate report" / "Synthesis report".
Actually, I see subresults only in "View Results Tree", but not in "Summary table".
In user.property file:
jmeter.save.saveservice.subresults=true
in Summary table - configuration - "save sub results" are checked also,
but sub results are not displaying as a labels in resulting tables.
What should I do to collect sub results displayed in Summary table using defined setSampleLabel?

I think you need to add the following lines to user.properties file:
webdriver.sampleresult_class=com.googlecode.jmeter.plugins.webdriver.sampler.SampleResultWithSubs
jmeter.save.saveservice.subresults=true
JMeter restart will be required to pick the properties up
More information:
WebDriver Sampler
Configuring JMeter
Apache JMeter Properties Customization Guide

Related

Writing web service response to excel

I am trying to wrote the response of a restful service response to excel.
In the below once, if my test case response is below one, then i need to write to csv or excel for sheet1 (in excel) TC01, sampleResponse
<user-batch-result xmlns="http://www.xxxxxx.com/api//02" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<records-succeeded>1</records-succeeded>
<records-failed>0</records-failed>
<UsersDetails>
<UserInfo>
<EmployeeID>xxxxx</EmployeeID>
<FeedRecordNumber>0</FeedRecordNumber>
<Status>SUCCESS</Status>
</UserInfo>
</UsersDetails>
You can do something like:
Download tika-app.jar and drop it somewhere to JMeter Classpath (i.e. to "lib" folder of your JMeter installation). JMeter restart will be required to pick the .jar up.
Add JSR223 PostProcessor as a child of the request which returns the above response
Put the following code into "Script" area:
def wb = new org.apache.poi.hssf.usermodel.HSSFWorkbook()
def sheet1 = wb.createSheet("sheet1")
def row = sheet1.createRow(0)
def A1 = row.createCell(0, org.apache.poi.ss.usermodel.CellType.STRING)
A1.setCellValue(prev.getResponseDataAsString())
wb.write(new File('myFile.xlsx'))
Run your test.
If everything goes well you should see myFile.xlsx having Sheet1 and the response of your Web Service as the very first cell value. Feel free to amend this code as required according to your use case.
References:
Busy Developers' Guide to HSSF and XSSF Features
How to Implement Data Driven Testing in your JMeter Test

Using custom amount in Jmeter WebDriver Sampler in graph metrics

I'm using Jmeter to get daily results of website performance, specifically, the render time (which I calculate using the sum domComplete - domLoading).
I end up with the result as a new var, but I don't know how to take that amount and transfer it to a Jmeter graph to display the results. My code is below:
WDS.sampleResult.sampleStart();
WDS.browser.get('http://www.vivastreet.co.uk/');
var completeTime = WDS.browser.executeScript('return window.performance.timing.domComplete;');
var loadingTime = WDS.browser.executeScript('return window.performance.timing.domLoading;');
var renderTime = completeTime - loadingTime;
WDS.log.info("Render time = " + renderTime);
WDS.sampleResult.sampleEnd();
The functionality is available only in JMeter 5.0, if you're on a previous version - you will have to upgrade, moreover it is highly recommended as per JMeter Best Practices
Store the result variable into JMeter Variables using WDS.vars shorthand. Add the following line before WDS.sampleResult.sampleEnd()
WDS.vars.put('renderTime', renderTime.toString())
Store the values into .jtl results file using Sample Variables property and configure JMeter HTML Reporting Dashboard to plot the custom value Add the following lines to user.properties file:
sample_variables=renderTime
jmeter.reportgenerator.graph.custom_testGraph.classname=org.apache.jmeter.report.processor.graph.impl.CustomGraphConsumer
jmeter.reportgenerator.graph.custom_testGraph.title=Rendering Time
jmeter.reportgenerator.graph.custom_testGraph.property.set_Y_Axis=Page Rendering time
jmeter.reportgenerator.graph.custom_testGraph.set_X_Axis=Over Time
jmeter.reportgenerator.graph.custom_testGraph.property.set_granularity=60000
jmeter.reportgenerator.graph.custom_testGraph.property.set_Sample_Variable_Name=renderTime
jmeter.reportgenerator.graph.custom_testGraph.property.set_Content_Message=Rendering Time :
Restart JMeter to pick the properties up

JMeter Parameterized Plug-in doesn't work under Loop controller

I've noticed that JMeter Parameterized Plug-in doesn't work under Loop
controller. It picks 1st value from CSV again and again..
Can someone help me with the steps?
Please find the attached Snapshot for CSV Data Set Configenter image description here
Please find the attached snapshot for CSV Dataenter image description here
Scenerio: User LogsIn and picks value from csv(1st row) and does a search, then picks second row value and search again(Loop) and logs off. i.e i need to do multiple iteration of search for single user
Change scope of your "CSV Data Set Config" to loop or Sampler instead of "Thread Group" or "Test Plan".
Means
Case 1: Won't work
[Does not work, if the scope of "CSV Data Set Config" to "Thread Group", as shown below]
Thread Group
|
---Loop
|
|
---CSV Data Set Config
Case 2: Should work
"CSV Data Set Config" Scope should be to "Loop controller" or "Sampler", as shown below
Thread Group
|
---Loop
|
------CSV Data Set Config
|
|

Trying to generate JMeter Test Plan (jmx) With JMeter API : Not able to save CSVDataSet element

I am creating a JMeter jmx file dynamically by using JMeter APIs. I am able to add a ThreadGroup within a TestPlan and a JavaSampler within the ThreadGroup. But when I add a CSVDataSet element within the Java Sampler, it does not get saved properly.
The following code is used to create a new CSVDataSet element
CSVDataSet csvDataSet = new CSVDataSet();
csvDataSet.setName("CSV Data Set");
csvDataSet.setComment("Sample CSV Data Set");
csvDataSet.setDelimiter(",");
csvDataSet.setFileEncoding("");
csvDataSet.setFilename("d:\\jmeter\\data.csv"); // variable
csvDataSet.setQuotedData(true);
csvDataSet.setRecycle(true);
csvDataSet.setShareMode(shareMode.all);
csvDataSet.setStopThread(false);
csvDataSet.setVariableNames("firstname, lastname, email"); // variable
csvDataSet.setEnabled(true);
When this is saved using SaveService.saveTree, the final jmx does not contain all the values which were set.
<org.apache.jorphan.collections.HashTree>
<CSVDataSet testname="CSV Data Set Config" enabled="true">
<stringProp name="TestPlan.comments">Sample CSV Data Set Config</stringProp>
</CSVDataSet>
<org.apache.jorphan.collections.HashTree/>
As seen above, only the test name, enabled, and comments are added. The rest of the variables are completely ignored.
Is there something that needs to be set in order to get all the values as expected?
or is this a bug in JMeter? I am using version 2.11
The basic code is as per section 4.3 from following link
http://blazemeter.com/blog/5-ways-launch-jmeter-test-without-using-jmeter-gui
To that I add the code shown above. The way it is added is,
testPlanTree.add("testPlan", testPlan);
testPlanTree.add("loopController", loopController);
testPlanTree.add("threadGroup", threadGroup);
testPlanTree.add("httpSampler", httpSampler);
testPlanTree.add("csvDataSet", csvDataSet);
SaveService
.saveTree(testPlanTree, new FileOutputStream("d:\\test.jmx"));
output of CSVDataSet block is as shown above.
After looking into the JMeter source code, it seems all the properties are set using the setProperty function rather than the individual setter functions. So putting the following code does the job of creating the CSVDataSet element properly.
csvDataSet.setProperty("delimiter", ",");
csvDataSet.setProperty("fileEncoding", "");
csvDataSet.setProperty("filename", "d:\\data.csv");
csvDataSet.setProperty("quotedData", true);
csvDataSet.setProperty("recycle", true);
csvDataSet.setProperty("shareMode", "shareMode.all");
csvDataSet.setProperty("stopThread", false);
csvDataSet.setProperty("variableNames", "var1, var2, var3");
Not sure why setters are not used in the code, but this seems to be the way to go for now
It is clearly not a bug in JMeter otherwise CSV Data Set could not be saved.
It is probably an issue in the way you build the HashTree, but unless you show the full code, you cannot get help.
By the way, as I said in a previous answer, what you are trying to do to build different tests based on input parameter is not good idea IMHO, the approach will be very fragile towards upcoming versions of JMeter.
JMeter provides ways to do it that you should follow.

Apache Jmeter read SQL variables from csv file

Need to load test a Oracle database the requirement is to fire sql queries concurrently to the database reading the varaibles from a CSV file is this feasible ?
Have a CSV file with values like
Name Email
Justin justin#beiber.com
George george#washington.com
...
Micheal micheal#jackson.com
And then have 10,20,30 users fire of queries like
select name,phone,city
from address
where name = <<feild1-from-csv>>
and email = <<feild2-from-csv>>
...
I'd suggest splitting your test logic into 2 separate pieces:
Load information from CSV and store it as JMeter variables
Execute SQL code against Oracle using variables from point 1
In regards to implementation I'd suggest to use 2 separate Thread Groups, the first one will be loading stuff from CSV, the second one will be doing actual testing.
Important: don't forget to check "Run Thread Groups Consecutively" box at TestPlan level to assure that second thread group runs after first one.
Example configuration of 1st thread group:
Counter
Start - 1
Increment - 1
Reference name - counter
CSV Data Set Config
Filename - path to your csv file
Variable names - name, email
Delimiter - if you're using TAB - "\t", if comma - "," without quotes
Allow quoted data - False
Recycle on EOF - False
Stop thread on EOF - True
Sharing mode - All Threads
Beanshell Sampler (this one is optional, JMeter 2.10 is smart enough to store variables for you but I prefer to control everything myself)
Code for Beanshell sampler shoud look as follows:
props.put("name" + vars.get("counter"), vars.get("name"));
props.put("email" + vars.get("counter"), vars.get("email"));
It fetches current "name" variable and stores it as name + counter property.
So given 3 lines is CSV file you'll have following properties:
name1=Justin
email1=justin#beiber.com
name2=George
email2=george#washington.com
name3=Micheal
email3=micheal#jackson.com
You can use Debug Sampler to see JMeter Variables and Properties values
After that in second thread group you can refer stored properties as:
${__P(name1,)}
or
${__property(name1,,)}
in your JDBC Request Sampler.
Both should work.

Resources