0
votes

I have some selenium code which repeats in every JMX I have, how can I create a jar of that and use it in JMeter web driver sampler? I am using Beanshell language in web driver sampler.

For example, if I need to use login and logout in every Jmx of web driver sampler, and now I am repeating it in every JMX. How do I keep those login and logout script somewhere and use that. Keeping as jars would be fine, but how can I do it in jMeter?

1

1 Answers

1
votes

Given the .jar containing your functions to perform login/logout will be present in JMeter Classpath you should be able to normally using import statement or equivalent call your functions from the WebDriver Sampler code.

One point: don't use java language as it is not real Java, it is Beanshell interpreter which has limited support of Java features and not very good performance. Since JMeter 3.1 it is recommended to use groovy for any scripting purposes so consider migrating on next available opportunity. Most likely you won't have to change your code.


Also be aware that there is a built-in mechanism in JMeter which helps you to avoid code duplication: Module Controller so instead of having .jars you can have separate WebDriver Sampler instances which will be doing common tasks like login/logout and you will be able to call them via Module Controller where required.