qileilove

blog已经转移至github,大家请访问 http://qaseven.github.io/

jmeter 之后置处理器

18.8.5 BeanShell PostProcessor

The BeanShell PreProcessor allows arbitrary code to be applied after taking a sample.

For JMeter versions after 2.2 the BeanShell Post-Processor no longer ignores samples with zero-length result data

For full details on using BeanShell, please see the BeanShell website.

The test element supports the ThreadListener and TestListener methods. These should be defined in the initialisation file. See the file BeanShellListeners.bshrc for example definitions.

Control Panel

Parameters

AttributeDescriptionRequired
NameDescriptive name for this element that is shown in the tree. The name is stored in the script variable LabelNo
Reset bsh.Interpreter before each callIf this option is selected, then the interpreter will be recreated for each sample. This may be necessary for some long running scripts. For further information, see Best Practices - BeanShell scripting .Yes
ParametersParameters to pass to the BeanShell script. The parameters are stored in the following variables:
  • Parameters - string containing the parameters as a single variable
  • bsh.args - String array containing parameters, split on white-space
No
Script fileA file containing the BeanShell script to run. The file name is stored in the script variable FileNameNo
ScriptThe BeanShell script. The return value is ignored.Yes (unless script file is provided)

 

The following BeanShell variables are set up for use by the script:

  • log - (Logger) - can be used to write to the log file
  • ctx - ( JMeterContext ) - gives access to the context
  • vars - ( JMeterVariables ) - gives read/write access to variables: vars.get(key); vars.put(key,val); vars.putObject("OBJ1",new Object());
  • props - (JMeterProperties - class java.util.Properties) - e.g. props.get("START.HMS"); props.put("PROP1","1234");
  • prev - ( SampleResult ) - gives access to the previous SampleResult
  • data - (byte [])- gives access to the current sample data

For details of all the methods available on each of the above variables, please check the Javadoc

If the property beanshell.postprocessor.init is defined, this is used to load an initialisation file, which can be used to define methods etc for use in the BeanShell script.

18.8.6 BSF PostProcessor

The BSF PostProcessor allows BSF script code to be applied after taking a sample.

Control Panel

Parameters

AttributeDescriptionRequired
NameDescriptive name for this element that is shown in the tree.No
LanguageThe BSF language to be usedYes
ParametersParameters to pass to the script. The parameters are stored in the following variables:
  • Parameters - string containing the parameters as a single variable
  • args - String array containing parameters, split on white-space
No
Script fileA file containing the script to run, if a relative file path is used, then it will be relative to directory referenced by "user.dir" System propertyNo
ScriptThe script to run.Yes (unless script file is provided)

 

The script (or file) is processed using the BSFEngine.exec() method, which does not return a value.

Before invoking the script, some variables are set up. Note that these are BSF variables - i.e. they can be used directly in the script.

  • log - (Logger) - can be used to write to the log file
  • Label - the String Label
  • Filename - the script file name (if any)
  • Parameters - the parameters (as a String)
  • args[] - the parameters as a String array (split on whitespace)
  • ctx - ( JMeterContext ) - gives access to the context
  • vars - ( JMeterVariables ) - gives read/write access to variables: vars.get(key); vars.put(key,val); vars.putObject("OBJ1",new Object()); vars.getObject("OBJ2");
  • props - (JMeterProperties - class java.util.Properties) - e.g. props.get("START.HMS"); props.put("PROP1","1234");
  • prev - ( SampleResult ) - gives access to the previous SampleResult (if any)
  • sampler - (Sampler)- gives access to the current sampler
  • OUT - System.out - e.g. OUT.println("message")

For details of all the methods available on each of the above variables, please check the Javadoc


18.9.8 Debug PostProcessor

The Debug PostProcessor creates a subSample with the details of the previous Sampler properties, JMeter variables, properties and/or System Properties.

The values can be seen in the View Results Tree Listener Response Data pane.

Control Panel

Parameters

AttributeDescriptionRequired
NameDescriptive name for this element that is shown in the tree.No
JMeter PropertiesWhether to show JMeter properties (default false).Yes
JMeter VariablesWhether to show JMeter variables (default false).Yes
Sampler PropertiesWhether to show Sampler properties (default true).Yes
System PropertiesWhether to show System properties (default false).Yes


18.8.8 JDBC PostProcessor

The JDBC PostProcessor enables you to run some SQL statement just after a sample has run. This can be useful if your JDBC Sample changes some data and you want to reset state to what it was before the JDBC sample run.



See Also:

 

In the linked test plan,"JDBC PostProcessor" JDBC PostProcessor calls a stored procedure to delete from Database the Price Cut-Off that was created by PreProcessor.

 


JDBC PostProcessor

 

 

 


8.8.4 Result Status Action Handler

This test element allows the user to stop the thread or the whole test if the relevant sampler failed.

Control Panel

Parameters

AttributeDescriptionRequired
NameDescriptive name for this element that is shown in the tree.No
Action to be taken after a Sampler errorDetermines what happens if a sampler error occurs, either because the sample itself failed or an assertion failed. The possible choices are:
  • Continue - ignore the error and continue with the test
  • Start next thread loop - does not execute samplers following the sampler in error for the current iteration and restarts the loop on next iteration
  • Stop Thread - current thread exits
  • Stop Test - the entire test is stopped at the end of any current samples.
  • Stop Test Now - the entire test is stopped abruptly. Any current samplers are interrupted if possible.
No

18.8.3 XPath Extractor

This test element allows the user to extract value(s) from structured response - XML or (X)HTML - using XPath query language.

Control Panel

Parameters

AttributeDescriptionRequired
NameDescriptive name for this element that is shown in the tree.No
Apply to:This is for use with samplers that can generate sub-samples, e.g. HTTP Sampler with embedded resources, Mail Reader or samples generated by the Transaction Controller.
  • Main sample only - only applies to the main sample
  • Sub-samples only - only applies to the sub-samples
  • Main sample and sub-samples - applies to both.
  • JMeter Variable - assertion is to be applied to the contents of the named variable
XPath matching is applied to all qualifying samples in turn, and all the matching results will be returned.
Yes
Use Tidy (tolerant parser)If checked use Tidy to parse HTML response into XHTML.
  • "Use Tidy" should be checked on for HTML response. Such response is converted to valid XHTML (XML compatible HTML) using Tidy
  • "Use Tidy" should be unchecked for both XHTML or XML response (for example RSS)
Yes
QuietSets the Tidy Quiet flagIf Tidy is selected
Report ErrorsIf a Tidy error occurs, then set the Assertion accordinglyIf Tidy is selected
Show warningsSets the Tidy showWarnings optionIf Tidy is selected
Use NamespacesIf checked, then the XML parser will use namespace resolution. Note that currently only namespaces declared on the root element will be recognised. A later version of JMeter may support user-definition of additional workspace names. Meanwhile, a work-round is to replace: 
//mynamespace:tagname 
by 
//*[local-name()='tagname' and namespace-uri()='uri-for-namespace'] 
where "uri-for-namespace" is the uri for the "mynamespace" namespace. (not applicable if Tidy is selected)
If Tidy is not selected
Validate XMLCheck the document against its schema.If Tidy is not selected
Ignore WhitespaceIgnore Element Whitespace.If Tidy is not selected
Fetch External DTDsIf selected, external DTDs are fetched.If Tidy is not selected
Return entire XPath fragment instead of text content?If selected, the fragment will be returned rather than the text content. 
For example //title would return "<title>Apache JMeter</title>" rather than "Apache JMeter". 
In this case, //title/text() would return "Apache JMeter".
Yes
Reference NameThe name of the JMeter variable in which to store the result.Yes
XPath QueryElement query in XPath language. Can return more than one match.Yes
Default ValueDefault value returned when no match found. It is also returned if the node has no value and the fragment option is not selected.No

 

To allow for use in a ForEach Controller, the following variables are set on return:

  • refName - set to first (or only) match; if no match, then set to default
  • refName_matchNr - set to number of matches (may be 0)
  • refName_n - n=1,2,3 etc. Set to the 1st, 2nd 3rd match etc.

Note: The next refName_n variable is set to null - e.g. if there are 2 matches, then refName_3 is set to null, and if there are no matches, then refName_1 is set to null.

XPath is query language targeted primarily for XSLT transformations. However it is usefull as generic query language for structured data too. See XPath Reference or XPath specification for more information. Here are few examples:

/html/head/title
extracts title element from HTML response
/book/page[2]
extracts 2nd page from a book
/book/page
extracts all pages from a book
//form[@name='countryForm']//select[@name='country']/option[text()='Czech Republic'])/@value
extracts value attribute of option element that match text 'Czech Republic' inside of select element with name attribute 'country' inside of form with name attribute 'countryForm'

 

When "Use Tidy" is checked on - resulting XML document may slightly differ from original HTML response:
  • All elements and attribute names are converted to lowercase
  • Tidy attempts to correct improperly nested elements. For example - original (incorrect) ul/font/li becomes correct ul/li/font
See Tidy homepage for more information.

 

18.8.1 Regular Expression Extractor

Allows the user to extract values from a server response using a Perl-type regular expression. As a post-processor, this element will execute after each Sample request in its scope, applying the regular expression, extracting the requested values, generate the template string, and store the result into the given variable name.

Control Panel

Parameters

AttributeDescriptionRequired
NameDescriptive name for this element that is shown in the tree.No
Apply to:This is for use with samplers that can generate sub-samples, e.g. HTTP Sampler with embedded resources, Mail Reader or samples generated by the Transaction Controller.
  • Main sample only - only applies to the main sample
  • Sub-samples only - only applies to the sub-samples
  • Main sample and sub-samples - applies to both.
  • JMeter Variable - assertion is to be applied to the contents of the named variable
Matching is applied to all qualifying samples in turn. For example if there is a main sample and 3 sub-samples, each of which contains a single match for the regex, (i.e. 4 matches in total). For match number = 3, Sub-samples only, the extractor will match the 3rd sub-sample. For match number = 3, Main sample and sub-samples, the extractor will match the 2nd sub-sample (1st match is main sample). For match number = 0 or negative, all qualifying samples will be processed. For match number > 0, matching will stop as soon as enough matches have been found.
Yes
Response Field to checkThe following response fields can be checked:
  • Body - the body of the response, e.g. the content of a web-page (excluding headers)
  • Body (unescaped) - the body of the response, with all Html escape codes replaced. Note that Html escapes are processed without regard to context, so some incorrect substitutions may be made.

     

    Note that this option highly impacts performances, so use it only when absolutely necessary and be aware of its impacts

     

  • Body as a Document - the extract text from various type of documents via Apache Tika (see View Results Tree Document view section).

     

    Note that Body as a Document option can impact performances, so ensure it is Ok for your test

     

  • Headers - may not be present for non-HTTP samples
  • URL
  • Response Code - e.g. 200
  • Response Message - e.g. OK
Headers can be useful for HTTP samples; it may not be present for other sample types.
Yes
Reference NameThe name of the JMeter variable in which to store the result. Also note that each group is stored as [refname]_g#, where [refname] is the string you entered as the reference name, and # is the group number, where group 0 is the entire match, group 1 is the match from the first set of parentheses, etc.Yes
Regular ExpressionThe regular expression used to parse the response data. This must contain at least one set of parentheses "()" to capture a portion of the string, unless using the group $0$. Do not enclose the expression in / / - unless of course you want to match these characters as well.Yes
TemplateThe template used to create a string from the matches found. This is an arbitrary string with special elements to refer to groups within the regular expression. The syntax to refer to a group is: '$1$' to refer to group 1, '$2$' to refer to group 2, etc. $0$ refers to whatever the entire expression matches.Yes
Match No.Indicates which match to use. The regular expression may match multiple times.
  • Use a value of zero to indicate JMeter should choose a match at random.
  • A positive number N means to select the nth match.
  • Negative numbers are used in conjunction with the ForEach controller - see below.
Yes
Default ValueIf the regular expression does not match, then the reference variable will be set to the default value. This is particularly useful for debugging tests. If no default is provided, then it is difficult to tell whether the regular expression did not match, or the RE element was not processed or maybe the wrong variable is being used.

However, if you have several test elements that set the same variable, you may wish to leave the variable unchanged if the expression does not match. In this case, remove the default value once debugging is complete.

No, but recommended

 

If the match number is set to a non-negative number, and a match occurs, the variables are set as follows:

  • refName - the value of the template
  • refName_gn, where n=0,1,2 - the groups for the match
  • refName_g - the number of groups in the Regex (excluding 0)
If no match occurs, then the refName variable is set to the default (unless this is absent). Also, the following variables are removed:
  • refName_g0
  • refName_g1
  • refName_g

 

If the match number is set to a negative number, then all the possible matches in the sampler data are processed. The variables are set as follows:

  • refName_matchNr - the number of matches found; could be 0
  • refName_n, where n = 1,2,3 etc - the strings as generated by the template
  • refName_n_gm, where m=0,1,2 - the groups for match n
  • refName - always set to the default value
  • refName_gn - not set
Note that the refName variable is always set to the default value in this case, and the associated group variables are not set.

See also Response Assertion for some examples of how to specify modifiers, and for further information on JMeter regular expressions.

 


posted on 2014-03-06 11:10 顺其自然EVO 阅读(2845) 评论(0)  编辑  收藏 所属分类: jmeter


只有注册用户登录后才能发表评论。


网站导航:
 
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

常用链接

留言簿(55)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜