1

I want to check if title = google if yes then hit yahoo.com else do nothing

could anyone please help with this. I am new to Jmeter.

1
4

First use the xpath extractor and extract the string from title the xpath would be //title Give the reference name say "t" and default as "Not Found"

Next use in the if controller give condition as "${t}" == "Google" add a sampler in it which hits yahoo.com.(Make sure you use https in protocol inside sampler)

Add a View Results Tree in the Thread Group

Run the plan

You should get 2 HTTP Requests made now make the condition in IF as "${t}" == "Facebook" Run the plan You will get only 1 HTTP Requests made Because the If condition failed.

3
  1. Add a Regular Expression Extractor as a child of the request which hits Google and configure it as follows:

    • Reference Name: anything meaningful, i.e. title
    • Regular Expression: <title>(.+?)</title>
    • Template: $1$
    • other fields may be left as they are
  2. Add If Controller at the same level as request hitting Google lives and use the following expression

    "${title}"=="Google"
    

Using XPath Extractor is not very recommended as it builds entire DOM tree in memory for locating a single word, it is not very efficient and may cause performance overhead or even out of memory errors in case of immense loads.

So use Regular Expression Extractor where possible and consider XPath or CSS extractors only if you have to deal with complex multiline DOM which may change.

For other recommendations on JMeter usage and fine tuning see JMeter Performance and Tuning Tips guide.

1

The jMeter Web Driver Sampler plugin describes a situation like this:

Example code:

WDS.browser.get('http://google.com')
if(WDS.browser.getTitle() == 'Google') { 
  WDS.browser.get('http://yahoo.com') 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.