Jmeter 5.5 XML SMTP采样器配置-无法设置标头

vmdwslir  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(172)

我正在尝试使用这个.jmx文件(XML)设置一个本地Jmeter运行:

<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.4">
  <hashTree>
    <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Perf Tests" enabled="true">
      <stringProp name="TestPlan.comments"></stringProp>
      <boolProp name="TestPlan.functional_mode">false</boolProp>
      <boolProp name="TestPlan.tearDown_on_shutdown">true</boolProp>
      <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
      <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
        <collectionProp name="Arguments.arguments"/>
      </elementProp>
      <stringProp name="TestPlan.user_define_classpath"></stringProp>
    </TestPlan>
    <hashTree>
      <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Big - 8mb attachment" enabled="true">
        <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
        <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
          <boolProp name="LoopController.continue_forever">false</boolProp>
          <stringProp name="LoopController.loops">10</stringProp>
        </elementProp>
        <stringProp name="ThreadGroup.num_threads">5</stringProp>
        <stringProp name="ThreadGroup.ramp_time">5</stringProp>
        <boolProp name="ThreadGroup.scheduler">false</boolProp>
        <stringProp name="ThreadGroup.duration"></stringProp>
        <stringProp name="ThreadGroup.delay"></stringProp>
        <boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp>
      </ThreadGroup>
      <hashTree>
        <SmtpSampler guiclass="SmtpSamplerGui" testclass="SmtpSampler" testname="Email - 8mb attachment" enabled="true">
          <stringProp name="SMTPSampler.server">localhost</stringProp>
          <stringProp name="SMTPSampler.serverPort">8080</stringProp>
          <stringProp name="SMTPSampler.serverTimeout">15000</stringProp>
          <stringProp name="SMTPSampler.serverConnectionTimeout">15000</stringProp>
          <stringProp name="SMTPSampler.mailFrom">bobby.hill@hey.com</stringProp>
          <stringProp name="SMTPSampler.replyTo"></stringProp>
          <stringProp name="SMTPSampler.receiverTo">bobby.hill@hey.com</stringProp>
          <stringProp name="SMTPSampler.receiverCC"></stringProp>
          <stringProp name="SMTPSampler.receiverBCC"></stringProp>
          <stringProp name="SMTPSampler.subject">Perf Test - 1 attachment 8mb</stringProp>
          <stringProp name="SMTPSampler.suppressSubject">false</stringProp>
          <stringProp name="SMTPSampler.include_timestamp">false</stringProp>
          <stringProp name="SMTPSampler.message">Hello World - Perf Test!</stringProp>
          <stringProp name="SMTPSampler.plainBody">false</stringProp>
          <stringProp name="SMTPSampler.attachFile">8mb-content-size.pdf</stringProp>
          <stringProp name="SMTPSampler.useSSL">false</stringProp>
          <stringProp name="SMTPSampler.useStartTLS">false</stringProp>
          <stringProp name="SMTPSampler.trustAllCerts">false</stringProp>
          <stringProp name="SMTPSampler.enforceStartTLS">false</stringProp>
          <stringProp name="SMTPSampler.useLocalTrustStore">false</stringProp>
          <stringProp name="SMTPSampler.trustStoreToUse"></stringProp>
          <stringProp name="SMTPSampler.tlsProtocols"></stringProp>
          <boolProp name="SMTPSampler.use_eml">false</boolProp>
          <stringProp name="SMTPSampler.emlMessageToSend"></stringProp>
          <stringProp name="SMTPSampler.useAuth">false</stringProp>
          <stringProp name="SMTPSampler.password"></stringProp>
          <stringProp name="SMTPSampler.username"></stringProp>
          <stringProp name="SMTPSampler.messageSizeStatistics">false</stringProp>
          <stringProp name="SMTPSampler.enableDebug">false</stringProp>
          <collectionProp name="SMTPSampler.headerFields"/>
        </SmtpSampler>
        <hashTree/>
      </hashTree>
    </hashTree>
  </hashTree>
</jmeterTestPlan>

此XML会将电子邮件消息传送至位于localhost:8080的本机服务器,而不会发生任何错误。
但是,我想为这些邮件设置日期头。在SmtpSampler元素前面,我尝试添加一个HeaderManager,如下所示:

<HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP Header Manager" enabled="true">
          <collectionProp name="HeaderManager.headers">
            <elementProp name="Date" elementType="Header">
              <stringProp name="Header.name">Date</stringProp>
              <stringProp name="Header.value">Fri, 21 Nov 1997 09:55:06 -0600</stringProp>
            </elementProp>
          </collectionProp>
        </HeaderManager>

但此XML没有正确设置SMTP邮件的标头。
我尝试过用扩展元素替换<collectionProp name="SMTPSampler.headerFields"/>

<collectionProp name="SMTPSampler.headerFields">
            <elementProp name="Date" elementType="Header">
              <stringProp name="Header.name">Date</stringProp>
              <stringProp name="Header.value">Fri, 21 Nov 1997 09:55:06 -0600</stringProp>
            </elementProp>
          </collectionProp>

这将产生以下堆栈跟踪:

java.lang.ClassCastException: class org.apache.jmeter.protocol.http.control.Header cannot be cast to class org.apache.jmeter.config.Argument (org.apache.jmeter.protocol.http.control.Header and org.apache.jmeter.config.Argument are in unnamed module of loader org.apache.jmeter.DynamicClassLoader @372f7a8d)

我也试过这个:

<collectionProp name="SMTPSampler.headerFields">
              <elementProp name="date" elementType="Argument">
                <stringProp name="Argument.name">Date</stringProp>
                <stringProp name="Argument.value">Fri, 21 Nov 1997 09:55:06 -0600</stringProp>
              </elementProp>
            </collectionProp>

此配置也会失败。
我很想看到一个在SMTP采样器XML中设置标头的示例,但我在官方Apache文档中找不到任何内容。
谢谢你,谢谢你

mf98qq94

mf98qq941#

正如其名称HTTP Header Manager所示,它控制着HTTP协议的头
如果需要为SMTP protocol添加头,SMTP示例中有一个特殊的输入:

或者,如果您喜欢手动编辑XML:

<collectionProp name="SMTPSampler.headerFields">
  <elementProp name="foo" elementType="Argument">
    <stringProp name="Argument.name">foo</stringProp>
    <stringProp name="Argument.value">bar</stringProp>
  </elementProp>
</collectionProp>

相关问题