JMeter - Run a python script before calling each HTTP request sampler

前端 未结 3 464
青春惊慌失措
青春惊慌失措 2021-02-10 15:56

I am new to Jmeter. My HTTP request sampler call looks like this

Path= /image/**image_id**/list/
Header =  \"Key\" : \"Key_Value\"

Key value is

3条回答
  •  [愿得一人]
    2021-02-10 16:38

    You can use a BSF PreProcessor.

    First download the Jython Library and save to your jmeter's lib directory.

    On your HTTP sampler add a BSF PreProcessor, choose as language Jython and perform your needed magic to obtain the id, as an example I used this one:

    import random
    randImageString = ""
    for i in range(16):
        randImageString = randImageString + chr(random.randint(ord('A'),ord('Z')))
    
    vars.put("randimage", randImageString)
    

    Note the vars.put("randimage",randImageString") which will insert the variable available later to jmeter.

    Now on your test you can use ${randimage} when you need it:

    Now every Request will be different changing with the value put to randimage on the Python Script.

提交回复
热议问题