简体   繁体   中英

J meter with Python : how to import the packages

Iam new bee to the jmeter

My code is working in the Python 2.7 with importing additional packages Dateutil, parser .

Problme : But when I am trying to run same code in the J Meter-JSR-223 PreProcessors , an error saying No module named dateutil in.

So , I have tried another approach to use Jython .

Installed the Jython ( downloaded the dateutil) and provide the packages reference under

import sys
sys.path.append('C:/Jython27/Lib/site-packages')
sys.path.append('C:/Jython27/Lib/site-packages/python_dateutil-2.4.2-py2.7/dateutil')
sys.path.append('C:/Jython27/Lib/site-packages/python_dateutil-2.4.2-py2.7/dateutil')

Now packages error is gone but string syntax error is present . java.sql.Date' object has no attribute . . java.sql.Date' object has no attribute .

I believe dateutil package can be picked up from CPython as it doesn't require any extra wrappers for Java.

  1. Install dateutil normally using pip like:

     pip install python-dateutil 
  2. Add site-packages folder of Python (not Jython) installation to sys.path like:

     sys.path.append("C:\\Python27\\Lib\\site-packages") 
  3. That's it, now you should be able to use dateutil module functions from the JSR223 Test Elements:

    在此处输入图片说明


Be aware that invoking Python scripts via Jython interpreter is not the best idea from performance perspective and if you're about to invoke your Python code only limited number of times and/or with a single thread - it might be better to go for the OS Process Sampler .

If you plan to use the Python code to create the main load - consider using Locust tool instead of JMeter. If you don't want to change JMeter a good approach would be rewriting your Python code in Groovy - it will be way better from the performance perspective.

hi please find follwing

import sys
sys.path.append('C:/Python27/Lib/site-packages')
sys.path.append('C:/Python27/Lib/site-packages/python_dateutil-2.4.2-py2.7/dateutil')

from dateutil.parser import *
sourceDateTimeOfEvent = ""
dateTimeOfEvent = ""

a=parse('2016-07-01 13:00:00')
sourceDateTimeOfEvent = a.isoformat()+"+05:30Z"
dateTimeOfEvent = a.isoformat()+ "Z"

vars.put("sourceDateTimeOfEvent", sourceDateTimeOfEvent)
vars.put("dateTimeOfEvent", dateTimeOfEvent)

This sourceDateTimeOfEvent and dateTimeOfEvent considered as two variables and passed it to the json file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM