如果其中一个HTTP请求失败,JMeter会发送电子邮件

时间:2022-11-08 08:30:55

I planned to create Test Plan in my JMeter like below

我打算在我的JMeter中创建测试计划,如下所示

  • Test Plan
  • Thread Group
    • Loop Controller
      • HTTP Request Sampler 1
      • HTTP请求采样器1

      • HTTP Request Sampler 2
      • HTTP请求采样器2

      • HTTP Request Sampler 3
      • HTTP请求采样器3

      • HTTP Request Sampler 4
      • HTTP请求采样器4

      • HTTP Request Sampler 5
      • HTTP请求采样器5

      • HTTP Request Sampler 6
      • HTTP请求采样器6

      • HTTP Request Sampler 7
      • HTTP请求采样器7

      • HTTP Request Sampler 8
      • HTTP请求采样器8

    • Loop Controller HTTP Request Sampler 1 HTTP Request Sampler 2 HTTP Request Sampler 3 HTTP Request Sampler 4 HTTP Request Sampler 5 HTTP Request Sampler 7 HTTP Request Sampler 8

    • If Controller condition ${JMeterThread.last_sample_ok}==false
      • SMTP Sampler
    • 如果Controller条件为$ {JMeterThread.last_sample_ok} == false SMTP Sampler

  • 线程组循环控制器HTTP请求采样器1 HTTP请求采样器2 HTTP请求采样器3 HTTP请求采样器4 HTTP请求采样器5 HTTP请求采样器7 HTTP请求采样器8如果控制器条件$ {JMeterThread.last_sample_ok} == false SMTP采样器

I would like to run the test 24/7. If one (or more) HTTP Request Sampler returns error for what ever reason, then execute the SMTP sampler and send email to me.

我想24/7全天候进行测试。如果一个(或多个)HTTP请求采样器出于任何原因返回错误,则执行SMTP采样器并向我发送电子邮件。

If none of the HTTP Request Sampler returns error , then do not execute SMTP sampler but keep repeating the loop forever.

如果HTTP请求采样器都没有返回错误,则不要执行SMTP采样器,而是永远重复循环。

I don't quite understand the if controller condition ${JMeterThread.last_sample_ok}.

我不太了解if控制器条件$ {JMeterThread.last_sample_ok}。

  1. What does JMeterThread.last_sample_ok mean?
    Last_sample_ok means only the last HTTP Request sampler (in my case HTTP Request Sampler 8 only) ? If I want to check the condition for every sampler 1-8, what can be done here?

    JMeterThread.last_sample_ok是什么意思? Last_sample_ok仅表示最后一个HTTP请求采样器(在我的情况下仅限HTTP Request Sampler 8)?如果我想检查每个采样器1-8的条件,可以在这做什么?

  2. Is JMeterThread a JMeter Java class or Java object?

    JMeterThread是JMeter Java类还是Java对象?

  3. Besides last_sample_ok , what other method can be applied to JMeterThread object?
  4. 除了last_sample_ok之外,还有哪些其他方法可以应用于JMeterThread对象?

Thanks.

2 个解决方案

#1


2  

  1. JMeterThread.last_sample_ok is a static String field of the JMeterThread class.

    JMeterThread.last_sample_ok是JMeterThread类的静态String字段。

    This line from the source code of JMeterThread class shows that LAST_SAMPLE_OK will be set to String representation of the parent.isSuccessful() boolean variable, where parent is a SampleResult object:

    来自JMeterThread类源代码的这一行显示LAST_SAMPLE_OK将设置为parent.isSuccessful()布尔变量的String表示形式,其中parent是SampleResult对象:

        threadContext.getVariables().put(LAST_SAMPLE_OK, Boolean.toString(parent.isSuccessful()));
    

    Basically, LAST_SAMPLE_OK will indicate if the last sample was successful (until it gets reset by the next sampler).

    基本上,LAST_SAMPLE_OK将指示最后一个样本是否成功(直到它被下一个采样器重置)。

    Yes, if JMeterThread.last_sample_ok is true then the last sampler was successful. In your case it is HTTP Request Sampler 8.

    是的,如果JMeterThread.last_sample_ok为真,则最后一个采样器成功。在您的情况下,它是HTTP请求采样器8。

    You can add all your HTTP Samplers as children of a Transaction Controller and select the "Generate a parent sample" checkbox.

    您可以将所有HTTP采样器添加为事务控制器的子项,然后选中“生成父样本”复选框。

    This will make JMeter generate a parent sample for all the inner samples of a Transaction Controller. If one of the child samplers fails, the parent sample will fail as well.

    这将使JMeter为事务控制器的所有内部样本生成父样本。如果其中一个子采样器发生故障,则父采样也将失败。

    Add your If Controller right after the Transaction Controller.

    在事务控制器之后添加您的If Controller。

    Now JMeterThread.last_sample_ok will relate to the generated parent sample.

    现在JMeterThread.last_sample_ok将与生成的父样本相关。

  2. JMeterThread is a class in the org.apache.jmeter.threads package .

    JMeterThread是org.apache.jmeter.threads包中的一个类。

  3. LAST_SAMPLE_OK is not a method, but a static field. There is one more field and a number of methods in the JMeterThread class.
  4. LAST_SAMPLE_OK不是方法,而是静态字段。 JMeterThread类中还有一个字段和许多方法。

#2


0  

One way you could do this is using Jenkins Email Extension Plugin which you can set to email you when there is a failure on you build. (so you could fail the build when the script has a failed HTTP request.)

一种方法是使用Jenkins电子邮件扩展插件,您可以设置为在构建失败时通过电子邮件发送给您。 (因此,当脚本的HTTP请求失败时,您可能会失败构建。)

https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin

#1


2  

  1. JMeterThread.last_sample_ok is a static String field of the JMeterThread class.

    JMeterThread.last_sample_ok是JMeterThread类的静态String字段。

    This line from the source code of JMeterThread class shows that LAST_SAMPLE_OK will be set to String representation of the parent.isSuccessful() boolean variable, where parent is a SampleResult object:

    来自JMeterThread类源代码的这一行显示LAST_SAMPLE_OK将设置为parent.isSuccessful()布尔变量的String表示形式,其中parent是SampleResult对象:

        threadContext.getVariables().put(LAST_SAMPLE_OK, Boolean.toString(parent.isSuccessful()));
    

    Basically, LAST_SAMPLE_OK will indicate if the last sample was successful (until it gets reset by the next sampler).

    基本上,LAST_SAMPLE_OK将指示最后一个样本是否成功(直到它被下一个采样器重置)。

    Yes, if JMeterThread.last_sample_ok is true then the last sampler was successful. In your case it is HTTP Request Sampler 8.

    是的,如果JMeterThread.last_sample_ok为真,则最后一个采样器成功。在您的情况下,它是HTTP请求采样器8。

    You can add all your HTTP Samplers as children of a Transaction Controller and select the "Generate a parent sample" checkbox.

    您可以将所有HTTP采样器添加为事务控制器的子项,然后选中“生成父样本”复选框。

    This will make JMeter generate a parent sample for all the inner samples of a Transaction Controller. If one of the child samplers fails, the parent sample will fail as well.

    这将使JMeter为事务控制器的所有内部样本生成父样本。如果其中一个子采样器发生故障,则父采样也将失败。

    Add your If Controller right after the Transaction Controller.

    在事务控制器之后添加您的If Controller。

    Now JMeterThread.last_sample_ok will relate to the generated parent sample.

    现在JMeterThread.last_sample_ok将与生成的父样本相关。

  2. JMeterThread is a class in the org.apache.jmeter.threads package .

    JMeterThread是org.apache.jmeter.threads包中的一个类。

  3. LAST_SAMPLE_OK is not a method, but a static field. There is one more field and a number of methods in the JMeterThread class.
  4. LAST_SAMPLE_OK不是方法,而是静态字段。 JMeterThread类中还有一个字段和许多方法。

#2


0  

One way you could do this is using Jenkins Email Extension Plugin which you can set to email you when there is a failure on you build. (so you could fail the build when the script has a failed HTTP request.)

一种方法是使用Jenkins电子邮件扩展插件,您可以设置为在构建失败时通过电子邮件发送给您。 (因此,当脚本的HTTP请求失败时,您可能会失败构建。)

https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin