根据 CSV 中的值评估 Jmeter 中的 If 条件
Evaluating If condition in Jmeter based on values in CSV
由于我对 jmeter 缺乏了解,本应简单的东西却遇到了很多问题。
我有一个测试包括:
CSV Data Set config
Http Request
If controller(containing Json Path extractor and an assertion)
我只想在 CSV 中的特定变量设置为 'Y' 时执行 If 语句的内容。
CSV 中的变量名称 = Check_For_Selector
我在 IF 上设置的条件是 "${Check_For_Selector}"="Y"
这行不通,我也不知道为什么。
请注意我使用的是 Jmeter 2.13(被迫使用这个而不是 3.1)。
我到底做错了什么?
在 JavaScript 中你需要使用 ==
运算符来 compare two strings like
"${Check_For_Selector}"=="Y"
参见 How to Use JMeter's 'IF' Controller for more details on how to execute JMeter samplers conditionally with the help of the If Controller
正如 Dmitri 提到的,您必须使用 ==
而不是 =
运算符进行比较。
如果仍然无法正常工作,请检查以下内容:
你不应该保留 Post-Processors and Assertions
(另外,Pre-processors
),而没有在其范围内包含任何封闭的 Sampler。如果它们的范围内没有采样器,它们将不会被执行。
如您所说,JSON Path Extractor & Assertion
在 If Controller
内,现在它们的范围仅限于控制器,它们不知道采样器(HTTP Request
,在If Controller
), JMeter
不会执行它们。
解决方案:
将 HTTP Request
保留在 If Controller
中 或者 将 JSON Path Extractor & Assertion
作为 HTTP request
的子项保留。
参考文献:
由于我对 jmeter 缺乏了解,本应简单的东西却遇到了很多问题。
我有一个测试包括:
CSV Data Set config
Http Request
If controller(containing Json Path extractor and an assertion)
我只想在 CSV 中的特定变量设置为 'Y' 时执行 If 语句的内容。
CSV 中的变量名称 = Check_For_Selector
我在 IF 上设置的条件是 "${Check_For_Selector}"="Y"
这行不通,我也不知道为什么。
请注意我使用的是 Jmeter 2.13(被迫使用这个而不是 3.1)。
我到底做错了什么?
在 JavaScript 中你需要使用 ==
运算符来 compare two strings like
"${Check_For_Selector}"=="Y"
参见 How to Use JMeter's 'IF' Controller for more details on how to execute JMeter samplers conditionally with the help of the If Controller
正如 Dmitri 提到的,您必须使用 ==
而不是 =
运算符进行比较。
如果仍然无法正常工作,请检查以下内容:
你不应该保留 Post-Processors and Assertions
(另外,Pre-processors
),而没有在其范围内包含任何封闭的 Sampler。如果它们的范围内没有采样器,它们将不会被执行。
如您所说,JSON Path Extractor & Assertion
在 If Controller
内,现在它们的范围仅限于控制器,它们不知道采样器(HTTP Request
,在If Controller
), JMeter
不会执行它们。
解决方案:
将 HTTP Request
保留在 If Controller
中 或者 将 JSON Path Extractor & Assertion
作为 HTTP request
的子项保留。
参考文献: