-
Notifications
You must be signed in to change notification settings - Fork 2.3k
TypeError: Cannot read property 'ELEMENT' of undefined #915
Comments
This is due to the breaking changes with ElementFinder in 0.24.0 - try it('should remove just created notes', function () {
tabElems.notes.element(by.repeater('note in page.notes')).each(function (noteElem) {
// Activate a note.
noteElem.element(by.css('.item-header')).click();
noteElem.element(by.css('.delete')).click();
});
tabElems.notes
.all(by.repeater('note in page.notes'))
.then(function (collection) {
expect(collection.length).toBe(0);
});
});
}); |
@juliemr Your code has mismatched brackets, I assume you meant: it('should remove just created notes', function () {
tabElems.notes.element(by.repeater('note in page.notes'))
.each(function (noteElem) {
// Activate a note.
noteElem.element(by.css('.item-header')).click();
noteElem.element(by.css('.delete')).click();
});
tabElems.notes
.all(by.repeater('note in page.notes'))
.then(function (collection) {
expect(collection.length).toBe(0);
});
}); (why did you change only the first part of the code?) Anyway, it doesn't work:
|
Ah, sorry, one more typo - you want to get an ElementArrayFinder, so you need to do: it('should remove just created notes', function () {
tabElems.notes.all(by.repeater('note in page.notes')) // Change here - .all instead of .element
.each(function (noteElem) {
// Activate a note.
noteElem.element(by.css('.item-header')).click();
noteElem.element(by.css('.delete')).click();
}); |
With the following code: it('should remove just created notes', function () {
tabElems.notes.all(by.repeater('note in page.notes'))
.each(function (noteElem) {
// Activate a note.
noteElem.element(by.css('.item-header')).click();
noteElem.element(by.css('.delete')).click();
});
}); I get the same error as at the beginning:
where line As for the change - how is it possible now to get the whole collection and not only iterate over it? I was using |
FYI we had a conversation about this at #922 |
Does this work for you? #922 (comment) The way you wrote your example (especially the count part) is not very clean, and can be cleaned up like this: it('should remove just created notes', function () {
var allElems = tabElems.notes.all(by.repeater('note in page.notes'));
allElems.then(function (collection) {
for (i = collection.length; i >= 0; --i) {
var noteElem = collection[i];
// Activate a note.
noteElem.element(by.css('.item-header')).click();
noteElem.element(by.css('.delete')).click();
}
});
expect(allElems.count()).toEqual(0);
}); I didn't try running this, so fix syntax as you encounter them |
See angular#915 - to make error more specific instead of propagate later
See #915 - to make error more specific instead of propagate later
I think this is resolve? Please reopen if necessary |
@hankduan The issue is not resolved for me, could you reopen? (I can't do it myself). I don't understand what you're proposing, could you elaborate what's different to what I currently have? I tried again with the newest Protractor 0.24.2 and the error is now less cryptic but still surprising. With the test: it('should remove just created notes', function () {
tabElems.notes.all(by.repeater('note in page.notes'))
.then(function (collection) {
collection.forEach(function (noteElem) {
noteElem.element(by.css(('.item-header')).click();
noteElem.element(by.css('.delete')).click();
});
});
}); I get the following error:
I get the same error when I change the test to what @juliemr suggested, i.e.: it('should remove just created notes', function () {
tabElems.notes.all(by.repeater('note in page.notes'))
.each(function (noteElem) {
noteElem.element(by.css('.item-header')).click();
noteElem.element(by.css('.delete')).click();
});
}); |
It's just like doing this in javascript:
You can see that the last element is undefined. In protractor, instead of returning undefined, we just throw an index out of bounds exception |
I don't understand what can return EDIT: Ah, my deleting notes might be causing the issue... Let me check. |
@hankduan You were right. :) It's a tricky one! I missed it because I just saw some selection and actions and I didn't add 2 plus 2 and see that elements are actually removed. I wonder if an error message might be a little more user-friendly in such cases. After all, if we're iterating over an array via This issue is resolved, though. Thanks! |
What output would you suggest that would make it less confusing? Protractor cannot fix the problem for the user because there is no way for protractor to know that someone removed an element, because the user is not removing the element via a protractor API. (they're just clicking and click could mean anything). But I can do something like. "Index out of bound (maybe the element no longer exists?)". However, this will be thrown even if someone does something like this |
Yeah, I can see the problem. Removing an element from an array is low-level and various high-level operations that might be bitten by it differ quite a bit. I think, though, that sth along the lines of I'm obviously biased, though by the issue that happened to me personally. Your call. :) |
FWIW I think the current error message is pretty good. "Index out of bounds" is exactly what's happening. |
I still see the problem in some of my protractor tests:
The code that hits this problem is:
|
Can you share the portion of the app you're testing? I just tested this and cannot reproduce. |
Using "protractor": "~0.24.0" The controller code is pasted in below. Perhaps the key is here the use of ng-grid. I search for items using an input field associated with the ng-grid. And after doing the search customersPage.search(100000), this makes ng-grid do a server side call and load data based on the search criteria, so the new data gets loaded in asynchronously (customerService.getCustomersAsync) and then I expect certain results/rows to be in the grid.
just calls into $http() posting a JSON request and getting back a JSON response: Note that sometimes I see the error and sometimes I don't.
And further below is the html, but specifically
is what customersPage.search(100000) enters text into in the test.
|
This is not the newest version, try 1.0.0-rc4. |
Upgraded to 1.0.0-rc4 and still see the same problem. If I have time I'll try to create a more distilled example of the problem. On Sun, Jul 13, 2014 at 5:19 PM, Michał Gołębiowski <
|
Any got work around for this or is it still an issue ? |
Not sure what the issue is in this case. The original issue is resolved. |
See angular/protractor#915 - to make error more specific instead of propagate later
When issues from #902 were resolved & Protractor 0.24.1 was released, I tried again to upgrade from 0.22.0. Unfortunately, I get a cryptic error:
The test itself is as follows (line 316 column 17 points to the
it
):The `beforeEach block:
The whole test file is quite complicated so for now I'm just sharing this info. The error should be more descriptive anyway, especially that it points just to the test definition and not to anything inside it. Does it say a lot to you? I can try to isolate sth further if there's a need but that might not be easy.
The text was updated successfully, but these errors were encountered: