Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I need to pass variable(Extracted from response) from one Request to other Requests in the same Thread Group.

Response of first Thread: "createGameRsp", "response": { "title": "Create Successful", "result": "Testo60 was successfully created. \n GameID: 56 \n Password: ", "error": "", "game": "texas", "gameID": 56

Another thread:

"get_joingame", "uid": "Esdv7CHkwo1ATMfvY6NcWBTM5YB4d3nj", "key": "AUEEW891WL", "socketId":"${sid}", "username":${userName}", "avatar": "avatar17.jpg", "language": "en", "playerMove": "", "joinGame": "", "replay": 0, "gameID":"${__property(GlobalGameID)}", "gameNo": 0, "data": "&seat=${counter2}&buyin=500&privateTable=2&clubId=0", "players": 0, "level": 347, "lastAction": "ep.playNow", "game": "texas", "playMoney": 1, "role": "1", "playerId":"${playerId}", "displayName": "p10", "seat":"${counter2}"

I've used beanshell assertion to set variable in to jmeter property

${__set.Property(GlobalGameID,$(gameID))};

While executing i'm getting

Assertion error:true Assertion failure:false Assertion failure message:org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``${__set.Property(GlobalGameID,$(gameID))};'' : Attempt to access property on undefined variable or class name

enter image description here

First of all you have an error in your function syntax

  • You need to remove the dot between set and Property

  • JMeter Variables are referenced in form ${variable-name}

    ${__setProperty(GlobalGameID,${gameID},)}
    

    Use Function Helper Dialog to generate proper function syntax

    Second, it's not recommended to inline JMeter Functions or Variables into Beanshell scripts, you can use props and vars shorthands instead:

        props.put("GlobalGameID", vars.get("gameID"));
    

    Third, it's not recommended to use Beanshell for scripting, if you need you should use JSR223 Test Elements and Groovy language as Groovy provides maximum performance comparing to other scripting engines

    More information: Using JMeter Variables With Multiple Thread Groups

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.

  •