JMeter with Custom Java Code - jmeter

I am new to JMeter and trying out certain sample code as part of my POC's. My requirement is pretty simple, I just need to attach a zip file to a SOAP message and fire the request. But to create the SOAP message we already have a framework that needs to be used. Now the problem I am facing is to include the framework JARs. I tried to add the library files into the project and create a JAR and paste it in /lib/ext folder and also by putting them in the class path. None of this works.
How do you use any existing framework JARs with the custom code you write for JMeter??

Drop your jar to /lib folder of your JMeter installation
Restart JMeter. JMeter doesn't pick up new libraries or configuration file changes dynamically.
In Beanshell or JSR223 Sampler refer to your jar classes as:
import com.yourcompany.package.SomeClass;
import com.yourcompany.package.SomeMessage;
SomeClass myClass = new SomeClass(parameter1, parameter2);
SomeMessage message = myClass.createMessage();
message.send();
See WebSocket Testing With Apache JMeter guide as an example of using external jars in JMeter.

Related

How to write response/variables to a particular cell of xlsx excel file using Jmeter?

I want to write jmeter response to a excel file at particular cell.
I have kept tika jar in jmeter lib/ext folder but when I open Jmeter I get below errors
Please let me know how can I overcome this error or are there any other apache POI libraries which I can use?
Thanks
EDIT: I have freshly installed the Jmeter and that error is no more now thanks #Dmitri. I'm using "tika-app-2.6.0.jar" at lib folder I have below code in my beanshell sampler
but I'm getting below error when trying to run
Can someone help?
Thanks
It looks like a Jar Hell, i.e. you have several instances of Apache POI libraries in your JMeter Classpath and the Java Classloader picks the wrong .jar combination.
Also "lib/ext" folder is for JMeter Plugins, all the dependency .jar files should go to "lib" folder.
And last but not the least according to JMeter Best Practices you should always be using the latest version of JMeter so consider
Performing clean installation of JMeter 5.5 (or whatever is the latest stable JMeter version which is available at JMeter Downloads page)
Make sure that only one instance of Apache POI library is in JMeter Classpath ("lib" folder of your JMeter installation)
Restart JMeter to pick up the POI .jar(s). You can also use tika-app.jar but in that case make sure not to add anything else as Tika has POI bundled.
The error should go away

Exported jar file is not visible in JUnit request sampler

i try to select class file in jmeter junit request sampler.i want help how to choose my class file in junit request sampler
i export the package and stored it in apache lib->junit folder
then,restart the jmeter, but my class file is not visible in junit request sampler and i import all the selenium jar files into the project including selenium standalone jar.
#Test
public void performence()
{
WebDriver driver=new HtmlUnitDriver();
driver.get("https://www.spicejet.com/");
System.out.println( driver.getTitle());
}
}
please help me to resolve this
I think your main issue is probably you didn't put dependencies (Webdriver) of your JUnit classes in lib folder.
Check jmeter.log to see what the error is and clarify your question.
Try checking Search for JUnit 4 annotations (instead of JUnit3) box (it is not checked by default hence JMeter is looking for JUnit3-style annotations)
Make sure your class has an empty constructor or constructor with a single String parameter. Other class types are not supported as of JMeter 5.0
Make sure to place the .jar with your test into lib/junit folder of your JMeter installation and other libraries (i.e. Selenium java client) to lib folder of your JMeter installation. Carefully select dependency libraries versions in order to avoid so called JAR Hell as JMeter and Selenium might rely on different versions of the same library.
JMeter restart will be required to pick up any changes
Check jmeter.log file for any suspicious entries. In the absolute majority of cases JMeter will print the information regarding the error or failure there.
See How to Use JUnit With JMeter article for more information on JUnit and JMeter integration.
If you don't have large number of JUnit-based tests which you want to import into JMeter and you're starting development from scratch it might be easier to go for WebDriver Sampler plugin which provides JMeter with smooth Selenium support and possibility to write Selenium-related code in variety of languages including Java.
You can install WebDriver Sampler plugin using JMeter Plugins Manager

Jmeter junit not on sampler menu

I've donwloaded JMeter 3.1 and am trying to run a junit sampler.
Per these instructions
jmeter.apache.org/usermanual/junitsampler_tutorial.pdf
I've added a ThreadGroup to test plan, i select add->sampler, but do not find Junit.
This is what I see. What am I missing?
no jmeter on menu
Here is an example photo I found on the tutorial.
enter image description here
I do have a junit class in a jar in the lib/junit folder.
This is weird, my JMeter 3.1 (installation comes with the JUnit Request sampler out of the box.
So please double check the following:
jmeter.log file - normally it contains enough information to guess the problem cause
you should have ApacheJMeter_junit.jar file under "lib/ext" folder of your JMeter installation. If it is not there - most probably something went wrong and your installation is corrupt
Be aware that you can add JUnit support (as well as any other JMeter Plugin) using JMeter Plugins Manager
For JMeter 5.0, the JUnit sampler did not appear for me when I incorrectly placed all my JUnit dependency jars in JMeter's lib/junit. It looks like it got stuck parsing all those jars looking for tests.
After placing JUnit dependency jars in JMeter lib folder and only the unit test jar in lib/junit, it worked correctly and JMeter GUI also started a lot faster.
I do have a junit class in a jar in the lib/junit folder.
This may be the problem in you case, if JMeter does not find any tests (or fails to find in my case), the JUnit sampler is simply not added to the UI

Maven Test Automation Project

I have a maven test automation project developed using selenium and testng. This is what I am doing with my framework:
1.I have main class in src/main/java and within the main class I trigger methods to dynamically create and run the testng xml.
2.The tests to be run are determined from the XMLFlag.xls sheet and test data for the tests is set in TestNG.xlsx sheet in src/main/resources.
3.I have successfully created a jar of my entire package.
Since I have put my Test Data sheets(TestNG.xlsx and XMLFlag.xls)under src/main/resources, these Test data sheets get packaged within the jar.
But ideally, I would like to run my test scripts for different sets of test data and see if the scripts are successful.
for example: I would like to run my scripts with ,say, username:abcd and password:1234 for the first time and then run the same set of scripts with username:efgh and password:9876.
But with my Test data sheets packaged within the jar I will not be able to achieve the above scenario since I cannot edit the test data sheets.
So let me say to overcome the above problem:
1.I put my Test data sheets in src/test/resources and not src/main/resources and then create a jar.
But when I do this and try to run the jar,
I get an error message:
.\src\test\resources\XMLFlag.xls (The system cannot find the path specified)
This, I believe, is because the Test data sheets get placed in test-classes folder under target folder and not within the jar.
To put it in simple words:
i. I want the test data sheets to be outside my jar, so that it can be edited and test scripts can be run based on the users requirement.
ii.If the test data sheets are outside my jar and everything else within my framework is dependent on test data information(ie.test scripts, testng.xml) and is packaged within the jar, my jar would not run.
Is there a way to avoid this error and accomplish what I want to do?
Or should I restructure my entire framework??
Kindly help me out.
How about passing the Test Data sheets as program arguments when you're executing your jar?
That is,
java -jar c:/path/to/your/jar c:/path/to/your/testng.xlsx c:/path/to/your/xmlflag.xlsx
and then just in your main method, read the file names and their content such as
File testNgXlsxFile = new File(args[0]);
and pass the information from the files to your framework.
Is that possible?

Publishing messages on HornetQ using JMeter

I'm developing a project wich is using HornetQ, and I want to publish some messages on it to execute a load test using JMeter. Does anyone here ever tried anything like it?
How can I configure JMeter to publish messages on HornetQ?
I already copied all the jars to the JMeter lib and filled all the fields on the "JMS Publisher Sampler". How can I proceed? Any example or JMX file which I could use as an example?
Add HornetQ JARs to jmeter/lib folder
Then for configuration of JMS Sampler use this:
http://docs.jboss.org/hornetq/2.2.5.Final/user-manual/en/html/using-jms.html

Resources