Protractor : e2e : I have a testcase in which I need to test whether that text is present or not

77 Views Asked by At

I have a test case in which I need to verify whether the API error toast message API service unavailable. Contact system admin displayed on top of the application is present or not.

If the API error message is displayed then My test case should fail and if the message is not displayed then the test case should pass.

But the problem is the toast message is only displayed when there is any API issue and it's very rare and occurs sometimes.

I have written the below code to verify the toast message element is present or not

 //To click on the overview option
await SpadesPageObj.ClientOverview.click();
//To verify does the toast message is present or not
expect(SpadesPageObj.SuccessMessage).toBeFalsy;

The problem here is -

  1. After clicking on the overview option the toast message appears when there is an API issue (It's Random)
  2. After clicking on the overview option the Toast Message can be displayed at any time.
  3. If the toast message is not displayed it means the application is working as expected.

I have also tried the below code and in this when there is no toast message displayed the timeout occurs

     //To click on the overview option
    await SpadesPageObj.ClientOverview.click();

   //Waiting for an elementtext for 3 sec to be visible
    await browser.wait(until.textToBePresentInElement(SpadesPageObj.SuccessMessage, 'API service 
    unavailable. Contact system admin'), 3000);

 //To verify does the toast message is present or not
    expect(SpadesPageObj.SuccessMessage).toBeFalsy;

Thanks

1

There are 1 best solutions below

0
On

I have tried try and catch and it worked for me!