XPath assertion of commonly used assertions in Jmeter

In general, using response assertion and json assertion can meet most assertion requirements, and Xpath assertion is mainly applicable to: the returned data format is html or xml.
XPath is a W3C standard. XPath is an expression language that uses path expressions to select nodes or sets of nodes in an XML document. The XPath assertion is similar to the XPath extractor in configuration and usage, except that the XPath extractor extracts node information that meets the path expression conditions from the document, while the XPath assertion judges that there are nodes in the document that meet the path expression conditions.

1. Add assertion method

As needed, assertions can be added under [Test Plan], [Thread Group], and [Thread Request], generally under the corresponding [Thread Request], as shown in the figure below, which is what this article introduces.
Add path: [Thread Request - Right Click - Add - Assertion - XPath Assertion]insert image description here

Two, XPath assertion

insert image description here

2.1.Apply to

Main sample and sub-samples – can be applied to the main sampler and sub-sampler at the same time. Examples include HTTP samplers with embedded resources, Mail Reader or samplers generated by transaction controllers.
Main sample only - can only be applied to the main sampler.
Sub-samples only - can only be applied to sub-samplers
JMeter Variable Name to use – applied to the variable of the specified name (extract the value of the specified variable) and sample all eligible samplers in order.
For example, if there is one main sampler and three sub-samplers,
when set to Sub-samples only, only three sub-samplers will be checked;
when Main sample and sub-samples, one main sampler and three sub-sampler for inspection.

2.2.XML Parsing Options (XML Parsing Options)

Use Tidy: When the page to be processed is in HTML format, this option must be selected ; if it is in XML or XHTML format (such as RSS return), uncheck it;
Quiet means to display only the required HTML pages,
Report errors means to display Respond to an error,
Show warnings means to display warnings;
Use Namespaces: If this option is enabled, the subsequent XML parser will use the namespace to distinguish;
Validate XML: Check and parse according to the page element mode;
Ignore Whitespace: Ignore blank content ;
Fetch external DTDs: If this item is checked, the external DTD rules will be used to fetch page content. Reference name: The name of the parameter to be referenced in the next request. If you fill in the title, you can use ${var_regexp2} to reference it.
(Some XML elements have attributes. The attributes contain information used by the application. The attributes only provide additional information about the element when the program reads and writes the element. At this time, it needs to be declared in DTDs)

2.3.Xpath Assertion

It is used to fill in the xpath expression, click Validate to verify its correctness, and check True if nothing matches to confirm that nothing matches.
insert image description here
insert image description here
Check True if nothing matches to indicate that the confirmation does not match, and the assertion verification is passed
insert image description here

3. Assertion result view

Note: All assertion result error messages for all requests under the entire test plan will be displayed under the [View Result Tree] component and [Assertion Result] component

3.1. [View result tree] component

Add path: [Test Plan - Right Click - Add - Listener - View Results Tree]
insert image description here

3.2. [Assertion result] component

Add path: [Test Plan - Right Click - Add - Listener - Assertion Results]
insert image description here

Guess you like

Origin blog.csdn.net/weixin_37600187/article/details/130067395