1

I got the following response - Pre-Note added with PIN (1368)

The PIN number will not be the same always, so, how can I write a re-runnable test to validate it?

Manu
  • 23
  • 4

1 Answers1

1
pm.expect(pm.response.text()).to.match(/<text>Pre-Note added with PIN ([\d]{4})<\/text>/);

you can use chai match method that uses regex , here this rehex will validate the pin is 4digit number

PDHide
  • 18,113
  • 2
  • 31
  • 46
  • Thanks, I will try this – Manu Mar 05 '21 at 02:35
  • I have tried the code but still getting errors, below is the response I got: Pre-Note added with PIN 1379 I have written in this format pm.test("60005-02 : Body matches string", function () { pm.expect(pm.response.text()).to.include("Pre-Note added with PIN [\d]{4}"); }); Please let me know if this correct? – Manu Mar 08 '21 at 22:33
  • ypu have to use match not include , use the code as it is – PDHide Mar 08 '21 at 22:39
  • I have used the code as it is, getting this error Body matches string | ReferenceError: a is not defined – Manu Mar 08 '21 at 22:45
  • repalce a with (pm.response.text()) – PDHide Mar 08 '21 at 22:47
  • please accept the answer by clickign the tick sign if it helped – PDHide Mar 08 '21 at 22:55