Wednesday 11 February 2015

Apply Regular Expression on a Jmeter Variable

There are few scripting areas where jmeter has upper hand over other load test tools, below is one such area.

In majority of load test tools you cannot apply a Regexp on a defined variable, in such cases we need to write some string functions which is a tedious job, but in jmeter you can easily achieve it by using Regular Expression Extractor(see below).


Step 1: Creating a jmeter variable by extracting a value to "cExpandContext1"



Step 2: To apply Regexp on above variable
  a) Add a Regular Expression Extractor to a request
  b) Select Jmeter Variable option under "Apply to" and input the variable name(i.e cExpandContext1)
  c) Now add extraction rule as we do for normal extractions (see below)


Thursday 5 February 2015

Ignore 404 errors jmeter

Jmeter by default marks transaction/request as fail when embedded resources(.js, .css. .img...etc) throws 404(file not found) HTTP status code, to mark transaction/request as pass use any of the following 4 methods.

1. Un-comment "httpsampler.ignore_failed_embedded_resources=false" in Jmeter properties file and mark it as true. (This technique ignores 500 errors)


2. Exclude corresponding resource(s) while downloading embedded resources(run-time) by using following Reg-ex.

    Regexp: ^((?!RESOURCE URL).)*$

    Eg:

   HTTP Request Defaults







3. Use Bean-shell assertion when explicitly requesting a resource
   
     Eg:
   
   

Note: Bean-Shell assertion doesn't work when downloading resources during test execution (i.e  when "Retrieve All Embedded Resources" checked on HTTP Request Defaults).  

   
4. Ignore Status
    
   Eg:



Note: It also ignores 5XX errors (eg: 500-Internal Server Error) which is not recommended, so use ignore status option when appropriate.