I have a series of tests, which close down modals and check to make sure the modal has disappeared. These are initially checked in Chrome, where they intermittently fail. Here is one such example (I have taken a similar approach elsewhere):
'use strict';
describe('Modal', function() {
var page;
beforeEach(function() {
browser.get('/#/components');
page = require('./modal');
page.ermAddErrorBtn.click();
page.ermAddErrorBtn.click();
page.ermAddInfoBtn.click();
});
it('should close the modal on clicking the modals cross icon', function () {
page.ermAlertBox.click().then(function() { //this just opens the modal
browser.wait(protractor.ExpectedConditions.presenceOf(page.ermModalEl), 30000, 'Modal never appeared');
browser.executeScript("$('.erm-modal').removeClass('fade');");
page.ermModalCloseBtn.click().then(function () {
browser.wait(protractor.ExpectedConditions.stalenessOf(page.ermModalEl), 30000, 'Modal never disappeared');
expect(page.ermModalEl.isPresent()).toBe(false);
});
});
});
});
Intermittently the modal times out and never closes (which gives the Modal never disappeared
message).
Later on in our build pipeline, this also gets checked using PhantomJS. I have tried multiple versions of the code above and one or the other (Chrome/PhantomJS) has problems.
I suspect it might be some kind of mis-timing issue, where it's trying to close something that doesn't yet exist.