0

I am using jython inside jmeter by placing the jython.jar under "lib" folder of your JMeter installation. It runs successfully.

But the problem is I can't install additional packages or modules of python inside it. To be more specific, I want to run selenium in python inside jmeter, so needs selenium module needs to be installed in jython.

How should I do it?

Ahsanul Haque
  • 10,676
  • 4
  • 41
  • 57

1 Answers1

2

You can install Jython packages normally, i.e. using pip, however make sure you are executing pip which comes with Jython (located under "bin" folder of your Jython installation)

  1. Download Jython installer and perform the installation somewhere, i.e. /temp/jython
  2. Navigate to /temp/jython/bin folder and execute ./pip install selenium command
  3. Add the next line to user.properties file which is located in JMeter's "bin" folder:

    user.classpath=/temp/jython;/temp/jython/javalib
    

    Note that JMeter restart will be required to pick the classpath up, check out Apache JMeter Properties Customization Guide for more information.

  4. Add JSR223 Sampler and selenium jython from the "Language" dropdown

  5. Add the next lines at the beginning of your script:

    import sys
    sys.path.append('/temp/jython/Lib')
    sys.path.append('/temp/jython/Lib/site-packages')
    import selenium
    

You should be good to go.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Can't produce #4 here. Till #2, everything is successful, as I can import selenium from jython. May be the problem is in #3, can you please check it a bit? Can it be any permission related issue? Though I could produce jython in dropdown placing jython-standalone.jar in lib of jmeter earlier. – Ahsanul Haque Mar 29 '17 at 07:24
  • Double check the path and restart JMeter after property change – Dmitri T Mar 29 '17 at 08:41
  • Actually there was a OS related issue, may be you are working in a windows machine, where `;` is used as path separator in `user.classpath`, whereas in linux, I had to use `:` as path separator. This is also described in comments of `user.properties` file. You can consider adding it to your answer to make it more complete one. – Ahsanul Haque Mar 29 '17 at 11:50