1

I need somehow to catch ngToast message after some action. I tried different solutions from this site, but they didn't help me and I don't know why. Does anyone has a working solution ? My last attempt was like:

var HomePage = require('./home.pageObject');

describe('Home Page tests', function () {
  var homePage = new HomePage();
  var EC = protractor.ExpectedConditions;

  beforeEach(function () {
      browser.get('/#/');
  });

  it('should fail login', function () {
      var toast = $('.ng-toast');
      homePage.signinBtn.click();
      homePage.login('admin', 'Password')
          .then(function () {
              var toast = $('.alert');
              browser.wait(EC.visibilityOf(toast), 3000);
          });
  });
});

Thanks.

icharts
  • 81
  • 1
  • 6

2 Answers2

1

Inspect the toast element once it is shown and then try to grab the message using css.

In one of our projects where we use angular-toastr, this does the trick:

element(by.css('#toast-container .toast-message')
Fjut
  • 1,314
  • 12
  • 23
1

You can use this function and call it in the test: First I'm waiting presence in the dom, then visibility and then I return the text:

this.returnToastText= function(){

    browser.wait(EC.presenceOf(element(by.css(".alert"))), 3000).then(function () {
        browser.wait(EC.visibilityOf(element(by.css(".alert"))), 3000).then(function () {
            return toastText= element(by.css(".alert")).getText();
        })
    })

};
Sanja Paskova
  • 1,110
  • 8
  • 15
  • Thanks, this put me on the right track. I was trying to close the toast. Now I am using: `browser.waitForAngularEnabled(false); //Dont wait for toast timeout var closeToast = $(".close"); browser.wait(EC.presenceOf(closeToast)) .then(() => { console.log(`Toast is present`) return true; }) closeToast.click(); browser.waitForAngularEnabled(true);` – Tom Aug 26 '18 at 04:21