Friday 30 January 2015

Call/reuse a Beanshell function jmeter

1. Go to Jmeter bin folder.
2. Open BeanShellFunction.bshrc file.
3. Define a function you want call and save the file.
4. Open jmeter properties file and search for "beanshell.function.init=BeanShellFunction.bshrc"
5. Uncomment this line by removing # symbol at the beginning of the line and save the file.
6. Go to jmeter and select Function helper dialog from Options menu.
7. Select Beanshell from the drop-down (shown below).
8. Write your defined function name and parameter(if any) in the Expression to evaluate (shown below).
9. Click on Generate button.
10. Use the function string generated wherever you want to call the function(shown below).



Tuesday 13 January 2015

Difference between (.*) and (.*?) in Regular Expressions


Quantifiers

  •  (.)   -  matches any single character except newline.
  •  (*)  -  between zero and unlimited times, as many times as possible, giving back as needed  [greedy]
  •  (.*) -  matches zero or more number of characters (except newline)
  • (.*?) - matches any character (except newline)
  • (*?)  - between zero and unlimited times, as few times as possible, expanding as needed [lazy]



Example:

Test String: <xyz>vikram</xyz><abc>ffasdfsaf</abc><xyz>awdfafsd</xyz>safasf

1. Regular Expression: <xyz>(.*)<\/xyz>
    Output: "vikram</xyz><abc>ffasdfsaf</abc><xyz>awdfafsd"

2. Regular Expression: <xyz>(.*?)<\/xyz>
    Output: "vikram"

In the first regular expression the (.*) matches till the end of Test String(i.e (.*) is greedy) and then Reg-ex Engine backtracks to first occurrence of right boundary from the end .

In the second regular expression the (.*?) matches some elements of Test String(i.e (.*?) is lazy) from the beginning and checks for right boundary, if does not exists expands further until right boundary matches.

Use (.*?) instead of  (.*) for efficient extraction.