1
votes

How to use two regular expression variable values with match count -1 in ForEach controller.

JMeter version: 3.1

Scenario: Questions List page>Each question has unique ID> Need to click each question on the list page and the HTTP request takes two parameters - QuestionID and Title

For this scenario I could achieve for one parameter (title) by using ForEach controller with regular expression match count set to -1.

When I have another RegExp for QuestionID with match count set to -1, how to use in the same ForEach controller since it takes only one input variable and puts that in one output variable. Below is the current test plan structure.

JMeter TestPlan structure:

The HTTP request looks like: POST https://test.com:xx/test

POST BODY:

mode=pr&questionId=454&Title=abcde

Here I have to put/get questionId and Title variable values, each title will have unique questionId.

ThreadGroup

--Req1 --Req2

---RegEx (title): with Match No. -1 (Debug Sampler shows match count: 4) `---RegEx (QuestionID): with MAtch No. -1 (Debug sampler shows match count: 2)

Loop Controller

---ForEach Controller (for title input variable)

----HTTP req using ForEach controller's output variable

Run the test> it is able to successfully iterate through title variable values however how to use QuestionID variable also in ForEach controller so that the HTTP request can have both RegExp variables.

Please guide.

Jmeter Version: 4.0 enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

Counter-QuesitonID-req: enter image description here

2

2 Answers

2
votes

You can use inside you ForEach loop, in case for example if it's called foreachController using an internal index introduced in JMeter 4.0

ForEach Controller now expose their current iteration as a variable named jm<"Name of your element">__idx

The problem it's started with 0, and QuestionID index start with 1,

So you need to increase value first by 1. Adding a Test action

  1. Under it add User Parameters with variable name N and value which increment by 1:

    ${__intSum(${__jm__foreachController__idx},1,)}
    
  2. then use N index to get correlate QuestionID variable inside loop using:

    ${__V(QuestionID_${N})}
    

1
votes
  1. Add Counter test element as a child of the ForEach Controller and configure it as follows:

    • Starting value: 1
    • Increment: 1
    • Maximum value: ${QuestionID_matchNr}
    • Reference name: counter

      JMeter Counter

  2. Refer generated value using __evalVar() function like:

    ${__evalVar(QuestionID_${counter})}
    

    where required

    JMeter EvalVar

More information: How to Use a Counter in a JMeter Test