Postman fails to assert long string in response value

How to assert response value with long string?

In our API design, the response contains multiple elements with base64 binary string values, which can be real long (e.g. 135,000 characters, or more), and I think this is causing the assertion failure.

This is a snippet of my test:
pm.test(“expected file”, () => {
const responseJson = pm.response.json();
pm.expect(responseJson.result.file).to.eql(“JVBERi0xLjMKJcK1wrYKCjEgMCBvYmoKPDwvVHlwZS9QYWdlcy9LaWRzWz… the rest is truncated, up to ~135k characters…”);
});

Have I done anything wrong or is there any way to get around this issue?

Can you please share a complete example? I don’t see a reason why this would fail, IF the data is actually equal.

That is the actual test function I’ve added. I cannot paste the full 135k long string to the reply as the forum doesn’t allow it but you get the idea.

The error I’m getting is:
expected file | AssertionError: expected 'JVBERi0xLjMKJcK1wrYK...' to deeply equal 'JVBERi0xLjMKJcK1wrYK...'
where the expected and actual strings are exact same.

I have also tested just comparing the ~135k long string to string like so:

pm.expect("JVBERi0xLjMKJcK1wrYKCjEgMCBvYmoKPDwvVHlwZS9QY...with the rest of 135k characters truncated...").to.eql("JVBERi0xLjMKJcK1wrYKCjEgMCBvYmoKPDwvVHlwZS9QY...with the rest of 135k characters truncated...");

and that works and passes as expected.

I don’t understand why when it’s comparing against the pm.response.json() value then it fails.

Hello, I am facing something similar, asserting will fail with deeply equal error, but if I’m checking both values manually, content will be identical.

var textData = pm.response.text();
pm.expect(textData).to.eql(environment.fileVar);

Check response body | AssertionError: expected ‘“Email Address”,“Status”,“Sub Status”,“Account”,“Domain”,“First Name”,“Last Name”,“Gender”,“Free Email”,“MX Found”,“MX Record”,“Provider”,“Did You Mean”\r\n”link”,”valid”,"",“email”,”link”,””,””,””,”false”,“True”,”link”,”g-suite”,””\r\n”link”,”valid”,"",“email”,“email.com”,"","","",“false”,“True”,”link”,”qq”,””\r\n”link”,”valid”,"",“email”,”link”,””,””,””,”true”,“True”,”link”,”google”,""\r\n’ to deeply equal ‘“Email Address”,“Status”,“Sub Status”,“Account”,“Domain”,“First Name”,“Last Name”,“Gender”,“Free Email”,“MX Found”,“MX Record”,“SMTP Provider”,“Did You Mean” “link”,”valid","",“stuart”,”link”,””,””,””,”false”,“True”,”link”,”g-suite”,"" “link”,”valid","",“email”,“email.com”,"","","",“false”,“True”,”link”,”qq”,"" “link”,”valid","",“email”,”link”,””,””,””,”true”,“True”,”link”,”google”,""’

Looks like assertion is adding \r\n?

Printing both textData and fileVar will result in the same data.

Any other way to compare this kind of data?

This behaviour looks similar to the issue reported here: Raw text when saved as request message body has new line characters ("\n") appended after each carriage return · Issue #9020 · postmanlabs/postman-app-support · GitHub

As a workaround, can you try removing '\r\n’before test script, i.e.

var textData = pm.response.text();
textData = textData.replace(‘\r\n’, ‘’);
pm.expect(textData).to.eql(environment.fileVar);

Please let me know if that works for you @yippie as well :slightly_smiling_face:

@andrei_m Nearly same kind of discussion is right here, this might be useful to you.

It worked with:
textData = textData.replace(/\r\n/g, ‘’);

Thank you, @taehoshino & @bpricilla

@andrei_m Awesome!!
Let us know if you have any more questions - more than happy to help!