Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JMeter Function ${__base64Encode} Not Executing Correctly in JMeter DSL When Loading .jmx File #290

Open
Farahala opened this issue Dec 26, 2024 · 3 comments

Comments

@Farahala
Copy link

  • Loading the .jmx file that was created previously by JMeter and run it using JMeterDSL.
  • The .jmx file contains a request with the following JMeter function: ${__base64Encode(Username,)}.

what I Expected that
the ${__base64Encode(Username,)} function should encode the Username value to Base64.

but the Actual Behavior when run the script was
the ${__base64Encode(Username,)} function is treated as a plain string and does not perform the Base64 encoding.

also i have included the following dependencies in my project:

kg.apc
jmeter-plugins-functions
2.2

org.apache.jmeter ApacheJMeter_functions ${jmeter.version}
@rabelenda
Copy link
Contributor

There is currently no support for usign jmeter-plugins-functions, and the problem is caused by jmeter configuration don't having such jar in the search path for libraries. You can use a groovy lambda instead of using such function like Username.bytes.encodeBase64().toString(). Another alternative might be adding the jar in the search path by extending EmbeddedJmeterEngine ovewritting run method to pass your own extended version of JmeterEnvironment which could overwrite updateSearchPath by doing something like:

private static class MyEnv extends JmeterEnvironment {

    public MyEnv() throws IOException {
    }

    public void updateSearchPath(HashTree tree) {
      super.updateSearchPath(tree);
      Properties props = JMeterUtils.getJMeterProperties();
      String searchPathsPropName = "search_paths";
      String prevPath = props.getProperty(searchPathsPropName);
      String functionJarPath = new File(Base64Encoder.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getPath()
      props.setProperty(searchPathsPropName,prevPath + ";" + functionJarPath);
    }
  }

Another alternative might be to contribute some improvement to JMeter DSL general logic for solving the search path from a test plan so it not only includes test elements classes in the search but also function classes, but I guess this might be tricky. A simpler contribution could be to add a method to EmbeddedJmeterEngine (and in JmeterEnvironment) that allows to add a particular class (like the one of the function you mention) in the search path, so whenever someone wants, they can add new function classes to the search path, if they need to.

@rabelenda
Copy link
Contributor

Hello, have you tried the previously mentioned workaround?

@Farahala
Copy link
Author

Farahala commented Jan 27, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants