Hi Anas,I can think of three more ways to achieve your goal. (Two of them are sketched out in the attached test plan).
* Use a listener (as already proposed by Dmitri), but use it to change the assertion messages. This can be done with a JSR 223 Listener with the following (Groovy) code:
sampleResult.assertionResults.each{
it.failureMessage=it.failureMessage.replaceAll("\n","\\\\n")
}
* Use a *custom failure message* in the assertion.
For this, type in your message in the field "Custom failure message"
at the bottom of the assertion.
* Use a JSR 223 Assertion and do the check with a custom (Groovy) snippet. With this, you can massage the message as it gets created.The listener described in the first point can be placed on the global level to change all "wrong" failure messages.
It might be a good idea to extend the current JTL writer to make these changes itself. Maybe you want to raise a bug report?
Hope this helps Felix Am 01.04.23 um 07:55 schrieb OUFDOU Anas:
Thanks stuart, The origine of \n is default jmeter message assertion not from response, There is no way to format data before logging to CSV ? Best regards On Fri, Mar 31, 2023 at 7:22 AM Stuart Kenworthy<[email protected]> wrote:You could run a groovy jsr223 post processor on the sampler with the following lines String responseMessage = prev.getResponseMessage() prev.setResponseMessage(responseMessage.replace("\n", "\\n")) -----Original Message----- From: Dmitri T<[email protected]> Sent: Friday, March 31, 2023 7:59 AM To: JMeter Users List<[email protected]>; OUFDOU Anas < [email protected]> Subject: Re: [JMETER] Log on multiple line in CSV OUFDOU Anas wrote:Hello, When failure message is multiline the CSV jtl file has a line logged on multiline, there is no way to replace "\n" by "\\n" in the jtl file to have one request by line ? image.png -- Cordialement, ------------- Anas OUFDOUAs of current JMeter stable version 5.5< https://www.blazemeter.com/blog/jmeter-5-5> it's not configurable and the only way to amend this is changing JMeter source code < https://github.com/apache/jmeter/blob/rel/v5.5/src/components/src/main/java/org/apache/jmeter/assertions/ResponseAssertion.java#L573,re-compiling the .jar and replacing the original version of the ApacheJMeter_components < https://mvnrepository.com/artifact/org.apache.jmeter/ApacheJMeter_components with the amended one. Alternatively you can set jmeter.save.saveservice.assertion_results < https://jmeter.apache.org/usermanual/properties_reference.html#results_file_config property to *none* and store assertion results in a separate file using a Listener < https://jmeter.apache.org/usermanual/properties_reference.html#results_file_config.--------------------------------------------------------------------- To unsubscribe, e-mail:[email protected] For additional commands, e-mail:[email protected] The information included in this email and any files transmitted with it may contain information that is confidential and it must not be used by, or its contents or attachments copied or disclosed to, persons other than the intended addressee. If you have received this email in error, please notify BJSS. In the absence of written agreement to the contrary BJSS' relevant standard terms of contract for any work to be undertaken will apply. Please carry out virus or such other checks as you consider appropriate in respect of this email. BJSS does not accept responsibility for any adverse effect upon your system or data in relation to this email or any files transmitted with it. BJSS Limited, a company registered in England and Wales (Company Number 2777575), VAT Registration Number 613295452, Registered Office Address, 1 Whitehall Quay, Leeds, LS1 4HR
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.5.1-SNAPSHOT a5044bc">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Testplan" 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="Benutzer definierte Variablen" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="TestPlan.user_define_classpath"></stringProp>
</TestPlan>
<hashTree>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread-Gruppe" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Schleifen-Controller (Loop Controller)" enabled="true">
<boolProp name="LoopController.continue_forever">false</boolProp>
<stringProp name="LoopController.loops">1</stringProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">1</stringProp>
<stringProp name="ThreadGroup.ramp_time">1</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>
<ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="true">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>true</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
<sentBytes>true</sentBytes>
<url>true</url>
<threadCounts>true</threadCounts>
<idleTime>true</idleTime>
<connectTime>true</connectTime>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
<JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="normal multiline" enabled="true">
<stringProp name="cacheKey">true</stringProp>
<stringProp name="filename"></stringProp>
<stringProp name="parameters"></stringProp>
<stringProp name="script">"OK"</stringProp>
<stringProp name="scriptLanguage">groovy</stringProp>
</JSR223Sampler>
<hashTree>
<ResponseAssertion guiclass="AssertionGui" testclass="ResponseAssertion" testname="multiline assertion" enabled="true">
<collectionProp name="Asserion.test_strings">
<stringProp name="-1275901199">received:
expected:</stringProp>
</collectionProp>
<stringProp name="Assertion.custom_message"></stringProp>
<stringProp name="Assertion.test_field">Assertion.response_data</stringProp>
<boolProp name="Assertion.assume_success">false</boolProp>
<intProp name="Assertion.test_type">2</intProp>
</ResponseAssertion>
<hashTree/>
</hashTree>
<JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="normal multiline" enabled="true">
<stringProp name="cacheKey">true</stringProp>
<stringProp name="filename"></stringProp>
<stringProp name="parameters"></stringProp>
<stringProp name="script">"OK"</stringProp>
<stringProp name="scriptLanguage">groovy</stringProp>
</JSR223Sampler>
<hashTree>
<ResponseAssertion guiclass="AssertionGui" testclass="ResponseAssertion" testname="multiline assertion" enabled="true">
<collectionProp name="Asserion.test_strings">
<stringProp name="-1275901199">received:
expected:</stringProp>
</collectionProp>
<stringProp name="Assertion.custom_message"></stringProp>
<stringProp name="Assertion.test_field">Assertion.response_data</stringProp>
<boolProp name="Assertion.assume_success">false</boolProp>
<intProp name="Assertion.test_type">2</intProp>
</ResponseAssertion>
<hashTree/>
<JSR223Listener guiclass="TestBeanGUI" testclass="JSR223Listener" testname="replace newlines" enabled="true">
<stringProp name="cacheKey">true</stringProp>
<stringProp name="filename"></stringProp>
<stringProp name="parameters"></stringProp>
<stringProp name="script">sampleResult.assertionResults.each { it.failureMessage = it.failureMessage.replaceAll("\n", "\\\\n") }
log.info("prev: {}", sampleResult.assertionResults)</stringProp>
<stringProp name="scriptLanguage">groovy</stringProp>
</JSR223Listener>
<hashTree/>
</hashTree>
<JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="custom failure message" enabled="true">
<stringProp name="cacheKey">true</stringProp>
<stringProp name="filename"></stringProp>
<stringProp name="parameters"></stringProp>
<stringProp name="script">"OK"</stringProp>
<stringProp name="scriptLanguage">groovy</stringProp>
</JSR223Sampler>
<hashTree>
<ResponseAssertion guiclass="AssertionGui" testclass="ResponseAssertion" testname="multiline assertion with custom message" enabled="true">
<collectionProp name="Asserion.test_strings">
<stringProp name="-1275901199">received:
expected:</stringProp>
</collectionProp>
<stringProp name="Assertion.custom_message">FAILED</stringProp>
<stringProp name="Assertion.test_field">Assertion.response_data</stringProp>
<boolProp name="Assertion.assume_success">false</boolProp>
<intProp name="Assertion.test_type">2</intProp>
</ResponseAssertion>
<hashTree/>
</hashTree>
</hashTree>
</hashTree>
</hashTree>
</jmeterTestPlan>
OpenPGP_0xEA6C3728EA91C4AF.asc
Description: OpenPGP public key
OpenPGP_signature
Description: OpenPGP digital signature
