-1

Hi I have the following assertion in postman but it is failing

pm.test("Body matches string", function() {
    pm.expect(pm.response.text()).to.include('Success') 
        || pm.expect(pm.response.text()).to.include('Request already submitted');
});

My Response contains text success or Request already submitted. Please help.

Christian Baumann
  • 3,188
  • 3
  • 20
  • 37

1 Answers1

2
pm.test("Body matches string", function () {
    let a = "Success"
    "Request already submitted" === a ? pm.expect("Request already submitted").to.be.equal('Request already submitted') : pm.expect(a).to.be.equal('Success')
});


pm.test("Body matches string", function () {
    let a = "Success"
    try {
        pm.expect("Request already submitted").to.be.equal('Request already submitted')
    }
    catch (e) { pm.expect(a).to.be.equal('Success') }
});

pm.test("Body matches string", function () {
    let a = "Success"
    pm.expect(a).to.be.oneOf(['Success', 'Request already submitted']);
});

expect does not return a boolean it throws an error, so either catch it or use the oneof methed, or first check a condition and then assert

PDHide
  • 18,113
  • 2
  • 31
  • 46