-
Notifications
You must be signed in to change notification settings - Fork 2.3k
"Reusing" element promises leads to StaleElementReferenceError #1903
Comments
I should've mentioned that I'm running protractor from master, and using Chrome v40.0.2214.115 on Linux. (If I run the test with Firefox v34, the same basic thing happens, but the exception message is slightly different. So my |
You've hit a bug with it('demonstrates isPresent bug', function() {
browser.get('http://angular.github.io/protractor/#/api', 90 * 1000);
element.all(by.tagName('li')).then(function(elements) {
var disappearingElem = elements[100];
expect(disappearingElem.isPresent()).toBeTruthy();
$('#searchInput').sendKeys('something unique and a bit long')
expect(disappearingElem.isPresent()).toBeFalsy(); // This will fail
});
}); I would like to point it out that part of this bug is because of your usage, as I'm not sure why you have var deferred = protractor.promise.defer();
element.all(by.tagName('li')).then(function(elements) {
var elProms = [];
elements.forEach(function(elProm) {
elProms.push(elProm);
});
deferred.fulfill(elProms);
});
deferred.promise.then(...) instead of the following which is shorter and much more readable: var elemArrFinder = element.all(by.tagName('li'));
elemArrFinder.then(...) That being said, it's still a bug nonetheless, and the fix is here: #1907 |
Ah, that fix makes sense! Thanks for tracking this down. Yeah, the weird usage in my example is because its reduced from some real code I have. In my real code I'm wrapping all the Modal dialogs that are on the screen, and my specs use my "page object"-like wrapper for the Modal dialogs, so I need (? I think?) the explicit promise and the |
Not 100% sure what your set up is that requires explicit |
As the fix from #1907 is in, I believe we can close this. |
@juliemr, I'm running the latest 2.0 with the fix mentioned by @hankduan. I have the following piece to make sure an element is not visible or does not exist:
I intermittently get a |
This should be how it's used (in fact, the
If it's not working, then there is possibly a bug. Can you open a new issue with some code to reproduce this? |
@hankduan
it seems like we don't check for |
stalenessof == not(presenseOf) |
This was a regression caused by angular#1903 and angular@2a765c7, but was causing ElementArrayFinder.prototype.count to be slow because of the extranous checks that must be performed. However, the checks could be delayed into the isPresent check, which will mitigate this issue
I'm trying to test how a page changes in response to user input. As such, the DOM is mutating, and I believe these mutations make any
element
promise from before the change suspect. Given that mutating the DOM is the Angular Way, and ExpectedConditions are supposed to help test for an element's visibility/presence, it seems like EC should be hiding this problem?However, I'm not clear if holding on to such promises across DOM mutations is just "bad form" (and I should always re-"locate" any elements that I think may have changed/moved) or if Protractor should implicitly re-locate elements for me. (Those both seem problematic, so I think this is an EC issue?)
The Selenium page on the exception is useful/frustrating reading: http://docs.seleniumhq.org/exceptions/stale_element_reference.jsp
It really seems like the case of navigating to a different page should be separated from the case of an element being destroyed and re-created which should also be separated from the case of an element being removed from the DOM. (So maybe this is a Selenium bug?)
Here is a simplified test case that demonstrates a variant on my problem using the protractor API page. Note that the test catches exceptions from the ExpectedConditions, but I'm just doing that to count the failures (I don't think every use of ExpectedConditions should do this).
The text was updated successfully, but these errors were encountered: