JMeter with Bcrypt replacement of SHA Hash - performance

I was using ${__groovy(org.apache.commons.codec.digest.DigestUtils.sha256Hex('624111\0002021-10-06T11:35:39-04:00\000s3co3t\000'),)} to get the SHA 256 Hash key, now In place of SHA256, I have to use BCRYPT, Can anyone help here, How we use BCRYPT in JMeter OR Any JMeter Utill function defined for this

There is no built-in functionality to perform BCRYPT hashing in JMeter, you will need to use an external library like JBCrypt or Spring Security
Add the .jar of your choice with its dependencies to JMeter Classpath
Restart JMeter to pick them up
You should be able to use the classes from .jars in JSR223 Test Elements and __groovy() function
More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?

Related

Jmeter project documentation

We have been using the Jmeter for the API's functional and performance test activities.
Is there a possibility to generate the documentation (similar java docs, API docs) for the JMX projects that we have been developing?
Each JMeter's Test Element has "Comments" section which can be used for explanation of what this element is for:
It's possible to create a JMeter Test Plan using Java language and JMeter API, see JMeter Command Line Overview: 5 Ways To Launch a Test for more details. There is also jmeter-from-code sample project you can use as a reference, normal JavaDoc will be available out of the box
There is JMeter DSL project which provides easy and handy way of creating a JMeter test plan, however it doesn't fully support all the features. For basic test plans it should be faster and easier than point 2
There is Taurus tool which provides possibility to create JMeter scripts in a declarative manner using YAML and YAML naturally supports comments

how to declare global function in jmeter and use anywhere in beanshell

I'm facing with problem don't know how to create one Java function and call it to use anywhere because I don't want to write this function many times. Could anyone give me the best solution to do it?
If you still want to proceed with Beanshell (however since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language) - take a look at Beanshell configuration, there are properties like:
beanshell.init.file
beanshell.sampler.init
etc.
where you can place the "common" code which can be reused in the Beanshell test elements.
For Groovy as of JMeter 5.2.1 there are no equivalent properties, however you should be able to compile your Groovy code into a .jar file, put the file into JMeter Classpath and invoke the functions defined in the .jar from any JSR223 Test element. Check out How to Reuse Your JMeter Code with JAR Files and Save Time article for more details.
This approach can be applied to Beanshell as well if you still want to use it and find the properties not very convenient.

Jmeter cant read custom JAR depedencies

I wrote a Maven application that I want to use in my Jmeter BeanShell script.
The Maven application is using Google Guice 4.2.2 for dependecy injection and it is calling an API at the end (Code needs to perform some other operations before calling the API and that's why I am not using the JMeter Plugin). I am creating the uber JAR (Fat JAR) with maven-shade-plugin. When I run the Jar from the command line the application run successfully!
However, When I load the JAR in my Jmeter test plan and call my application main method in the Jmeter BeanShell I am getting the following error:
java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V
at com.google.inject.Key.ensureRetainedAtRuntime(Key.java:341) ~[load-testing.jar:?]
.
.
.
Now lots of other threads mentioned that this can be because of older Google Guava version (20.x older) but from the dependency tree I see the Guava version is 25.1-android and I can run my JAR successfully from the command line!!
Also, I list the classes in the Uber JAR by running jar -tf command and I can see that the com.google.common.base.Preconditions class is there.
I would appreciate it if someone can shed some light on this matter and help me to resolve this?
It seems that your fat-jar contains multiple versions of Guava (which may be caused by the shade-plugin).
Make sure to lock it to single version by using Mavens dependency management in each maven module. (https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Management)
The Beanshell itself might be a problem, since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting, the reasons are in:
Groovy is more "modern" language which supports all modern Java features while with Beanshell you're stuck at Java 1.5 language level (no lambdas, no generics, no multi-catch etc.)
Groovy performance is much better comparing to Beanshell cause Grooovy engine implements Compilable interface and is capable of caching compiled scripts providing performance very close to native Java code
Groovy provides a lot of enhancements on top of standard Java SDK
Check out Apache Groovy - Why and How You Should Use It article for more details.
I have finally cofirmed my comment. The problem was my JAR Guava version was conflicting with Jmeter Guava version (which is 17.0) and Jmeter for some reason is picking up its own Guava version, after downgrading Guice version to 3.0 which does not depend on guava, I successfully ran my JAR through Jmeter.
There is still a mystery on why Jmeter is overriding my JAR Guava version with its own. I will create a ticket with Jmeter in order to find more about this mystery but this change solved my problem

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

JSR223 Post Processor: ClassNotFoundException: org.apache.bsf.engines.java.JavaEngine

I'm trying to use a JSR223 post processor in jmeter 2.11 with some java code and I keep getting this error:
org.apache.bsf.BSFManager:Exception:java.lang.ClassNotFoundException:org.apache.bsf.engines.java.JavaEngine
I've checked the bsf/bsh jar files, not sure what else I need to do to make this work. I've read that groovy is recommended but I'd really like this to work with java.
As per the very first lines from BSF Sampler documentation:
See the Apache Bean Scripting Framework website for details of the languages supported. You may need to download the appropriate jars for the language; they should be put in the JMeter lib directory.
And at the same place:
The BSF API has been largely superseded by JSR-223, which is included in Java 1.6 onwards. Most scripting languages now include support for JSR-223; please use the JSR223 Sampler instead. The BSF Sampler should only be needed for supporting legacy languages/test scripts.
So I would recommend considering the following (in the order from worst to best performance provided)
Beanshell Sampler (if your Java code is doing something "light")
JSR223 Sampler + groovy language - for "heavy" operations (again you'll need to have groovy jar in your JMeter CLASSPATH)
Write your own implementation of Java Request Sampler
Both Beanshell and Groovy support Java syntax with some limitations which can be easily worked around.
See Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! guide which might help you to make right selection.

Resources