Satyajit
Satyajit

Reputation: 152

Regex in JMeter - To capture a particular field after a pattern match

I have got the following response for one of my HTTP request in JMeter:

  <div class="container">
    <h2>Choose your departure city:</h2>
    <form action="reserve.php" method="post">
    <select name="fromPort" class="form-inline">
        <option value="Paris">Paris</option>
        <option value="Philadelphia">Philadelphia</option>
        <option value="Boston">Boston</option>
        <option value="Portland">Portland</option>
        <option value="San Diego">San Diego</option>
        <option value="Mexico City">Mexico City</option>
        <option value="São Paolo">São Paolo</option>
    </select>
    <p>
    <h2>Choose your destination city:</h2>
    <select name="toPort" class="form-inline">
        <option value="Buenos Aires">Buenos Aires</option>
        <option value="Rome">Rome</option>
        <option value="London">London</option>
        <option value="Berlin">Berlin</option>
        <option value="New York">New York</option>
        <option value="Dublin">Dublin</option>
        <option value="Cairo">Cairo</option>
    </select>

Now I want to select the fromPort values and also the toPort values in two different variables and then pass it on to the next request. I build the regex expression but it captures all the values of fromPort and toPort in a single array. I need to extract these in two different arrays and then call them. So I want to know about the right regex for this ??

Upvotes: 0

Views: 436

Answers (2)

sunny_teo
sunny_teo

Reputation: 1999

I have tried with CSS/JQuery Extractor. Check the below snapshot for format and output. Below is for "from port" and second CSS selector for "TO port". Just change the CSS expression for 2nd extractor from select[name=fromPort] to select[name=toPort]. enter image description here

Output in View Results enter image description here Now, you have the array. I hope this helps.

Update:-

Use the below syntax for the CSS/JQuery Extractor.

enter image description here

Below is the required output. Since, we are using Match No. as 0..values will be random on each iteration.

enter image description here

Upvotes: 1

Rohit
Rohit

Reputation: 611

The easiest way to extract this kind of values is to use Xpath Extractor. Add a xpath extractor as a child to the request. To extract fromPort you can use //select[@name='fromPort']/* as Xpath and match no 0 to get any random value from fromport options

To extract toPort you can use //select[@name='toPort']/* and match no 0 as shown below

enter image description here

Result : enter image description here use ${variableName} in your script

More information:

Jmeter- extract variables

Please let me know if it helps..

Upvotes: 0

Related Questions