I've disabled the control flow and started spreading async/await accross my e2e tests.
And here the problem arises that
Failed: Index out of bound. Trying to access element at index: 0, but there are only 0 elements that match locator By(css selector, .OneLine)
NoSuchElementError: Index out of bound. Trying to access element at index: 0, but there are only 0 elements that match locator By(css selector, .OneLine)
Here is my test
it('', async () => {
await page.dragElToCell('Text', {x: 1, y: 0});
// further some expectations that are not reached due to error thrown which points to page.dragElToCell
})
This is a page obj method
async dragElToCell(name: string, pos: {x: number, y: number}) {
const el = this.getDraggableEl(elName);
const cell = this.getCell(pos.x, pos.y);
return browser.actions().dragAndDrop(el, cell).perform();
}
getDraggableEl(name: string) {
return element(by.cssContainingText('.draggable', name);
}
getCell(x: number, y: number) {
return $$('.OneLine').get(y).$$('.Column').get(x);
}
This code was working pretty well inside control flow. As soon as I've disabled it it stopped working.
The trick is that if I execute
expect(await $$('.OneLine').get(0).$$('.Column').get(1).isPresent()).toBeTruthy();
inside my test suite it works fine and gives me true
.
I've also debugged getCell
and it receives proper numbers.
Also, I've set sleep for 10 sec to ensure that elements are visible (and for that also executed querySelectorAll
twice to repeat same sequence and got the element I'd expected to retrieve).