0

I'm attempting to validate the header (Text) of a given web page when making a successful submission.

My command:

async confirmSuccessfulSubmission() {
    return $("#contact_reply h1").getText().then((value) => {
        //incorrect text should be:Thank You for your Message!
        expect(value.to.equal("Thank You for your Message!2")); 
    });
}

Exception:

UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)

The correct heading is: Thank You for your Message! therefore if the heading is: Thank You for your Message!2 the test should fail (Chai assertion).

Any ideas?

Thanks for your help

SamP
  • 417
  • 5
  • 24

1 Answers1

1
async confirmSuccessfulSubmission() {
  try{
    let value = await $("#contact_reply h1").getText()
    if(value)
       return expect(value).to.equal("Thank You for your Message!2"); 
    return null
  } catch(e) {
    console.log(e)
  }
}

catch the exception so you could see what's wrong there

StackedQ
  • 3,999
  • 1
  • 27
  • 41
  • hi @kiarashws thanks for the comment, it seems im still seeing an exception, would you know the code required to catch the exception? [0-0] (node:4108) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3) – SamP Feb 23 '19 at 09:16
  • thanks @kiarashws , [0-0] TypeError: Cannot read property 'equal' of undefined at ContactUs_Page.confirmSuccessfulSubmission (C:\Users\GBruno\Desktop\webdriverioFramework\pageObjects\ContactUs_Page.js:51:32) at at process._tickDomainCallback (internal/process/next_tick.js:229:7) [0-0] TypeError: Cannot read property 'equal' of undefined at ContactUs_Page.confirmSuccessfulSubmission (C:\Users\GBruno\Desktop\webdriverioFramework\pageObjects\ContactUs_Page.js:51:32) at at process._tickDomainCallback (internal/process/next_tick.js:229:7) – SamP Feb 23 '19 at 09:21
  • im trying to implement something like the following: https://webdriver.io/docs/api.html#examples, appreciate your help – SamP Feb 23 '19 at 09:22
  • seems im seeing: [0-0] TypeError: value.toEqual is not a function, currently im using chai assertions: https://www.chaijs.com/ – SamP Feb 23 '19 at 09:24
  • thanks again, Im guessing i would need to make the assertion fail within the catch block? – SamP Feb 23 '19 at 09:43
  • Yes, but you can now remove `try/catch` since we discovered what exception was occurring. – StackedQ Feb 23 '19 at 09:45