0

i am trying to make my script so robust so that if there is any error in my logic or on page, I want to notification with user defined message instead of that red color error messages like element on found or find Element().... is not a function. I implemented code Suggested

But it is not working.

i also tried with code mentioned on Suggested But it is also not working.

vijay kumar
  • 61
  • 2
  • 12

1 Answers1

0

You can use chai library for assertions.

See the documentation, eg. for equal:

https://www.chaijs.com/api/bdd/#method_equal

You can set custom message like as a second parameter:

expect('foo').to.equal('bar', 'Test failed with custom message');

Kacper
  • 1,201
  • 1
  • 9
  • 21
  • Hi @Kacper, Thank you for your quick response, however we are using jasmine in our project and we need to implement in jasmine only, please suggest – vijay kumar Feb 28 '19 at 04:12
  • In Jasmine it looks pretty the same. See answer here: https://stackoverflow.com/a/24980483/6331748 – Kacper Feb 28 '19 at 06:04
  • Hi @Kacper, Thanks again for your suggestion, i reviewed the information provided on above mentioned link. – vijay kumar Feb 28 '19 at 07:20
  • I reviewed the information provided on above mentioned link. and i observed that that logic is implemented with expect only and if my expect is not true then only that message will be printed. But i guess exception like "**get Text() not a function**" or "**Element Not Visible Error**" or "**staled element**" for any web element on page. How can we get such exception using code? – vijay kumar Feb 28 '19 at 07:26
  • Hi i tried with displaying with custom message way but it is not working can you please look and let me know what am i doing wrong. below is the code i tried with the output – vijay kumar Mar 04 '19 at 06:37
  • var calcObj = require('../PageElements/CalcPageobject'); var noExceptionOccur = true describe('Test Calculation initial opertaion', function () { it('Test first time', async function () { calcObj.appUrl(); calcObj.firstField().sendKeys('12') calcObj.secondField().sendKeys('12'); calcObj.goClick(); var final = calcObj.finalResult(); expect(final).toEqual('25', 'Result is not correct'); }); }); – vijay kumar Mar 04 '19 at 06:39
  • Output: 1) Test Calculation initial opertaion Test first time - Expected '24' to equal '25'. – vijay kumar Mar 04 '19 at 06:40
  • expect(final).toEqual('21',"This the reason of fail"); This is not working for me – vijay kumar Mar 04 '19 at 11:14