diff --git a/testing/marionette/client/marionette/tests/unit/test_findelement.py b/testing/marionette/client/marionette/tests/unit/test_findelement.py index a8f2b603b43e..ea58380f401b 100644 --- a/testing/marionette/client/marionette/tests/unit/test_findelement.py +++ b/testing/marionette/client/marionette/tests/unit/test_findelement.py @@ -122,7 +122,7 @@ class TestElements(MarionetteTestCase): self.marionette.set_search_timeout(0) self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "I'm not on the page") - def test_timeout(self): + def test_timeout_element(self): test_html = self.marionette.absolute_url("test.html") self.marionette.navigate(test_html) button = self.marionette.find_element("id", "createDivButton") @@ -131,6 +131,15 @@ class TestElements(MarionetteTestCase): self.assertTrue(True, self.marionette.set_search_timeout(8000)) self.assertEqual(HTMLElement, type(self.marionette.find_element(By.ID, "newDiv"))) + def test_timeout_elements(self): + test_html = self.marionette.absolute_url("test.html") + self.marionette.navigate(test_html) + button = self.marionette.find_element("id", "createDivButton") + button.click() + self.assertEqual(len(self.marionette.find_elements(By.ID, "newDiv")), 0) + self.assertTrue(True, self.marionette.set_search_timeout(8000)) + self.assertEqual(len(self.marionette.find_elements(By.ID, "newDiv")), 1) + def test_css_selector_scope_doesnt_start_at_rootnode(self): test_html = self.marionette.absolute_url("test.html") self.marionette.navigate(test_html) diff --git a/testing/marionette/marionette-elements.js b/testing/marionette/marionette-elements.js index d13f9741229a..57de7a652791 100644 --- a/testing/marionette/marionette-elements.js +++ b/testing/marionette/marionette-elements.js @@ -297,30 +297,22 @@ ElementManager.prototype = { } let found = all ? this.findElements(values.using, values.value, win.document, startNode) : this.findElement(values.using, values.value, win.document, startNode); - if (found) { - let type = Object.prototype.toString.call(found); - if ((type == '[object Array]') || (type == '[object HTMLCollection]') || (type == '[object NodeList]')) { - let ids = [] - for (let i = 0 ; i < found.length ; i++) { - ids.push(this.addToKnownElements(found[i])); - } - on_success(ids, command_id); - } - else { - let id = this.addToKnownElements(found); - on_success({'ELEMENT':id}, command_id); - } - return; - } else { + let type = Object.prototype.toString.call(found); + let isArrayLike = ((type == '[object Array]') || (type == '[object HTMLCollection]') || (type == '[object NodeList]')); + if (found == null || (isArrayLike && found.length <= 0)) { if (!searchTimeout || new Date().getTime() - startTime > searchTimeout) { - // Format message depending on strategy if necessary - let message = "Unable to locate element: " + values.value; - if (values.using == ANON) { - message = "Unable to locate anonymous children"; - } else if (values.using == ANON_ATTRIBUTE) { - message = "Unable to locate anonymous element: " + JSON.stringify(values.value); + if (all) { + on_success([], command_id); // findElements should return empty list + } else { + // Format message depending on strategy if necessary + let message = "Unable to locate element: " + values.value; + if (values.using == ANON) { + message = "Unable to locate anonymous children"; + } else if (values.using == ANON_ATTRIBUTE) { + message = "Unable to locate anonymous element: " + JSON.stringify(values.value); + } + on_error(message, 7, null, command_id); } - on_error(message, 7, null, command_id); } else { values.time = startTime; this.timer.initWithCallback(this.find.bind(this, win, values, @@ -330,6 +322,18 @@ ElementManager.prototype = { 100, Components.interfaces.nsITimer.TYPE_ONE_SHOT); } + } else { + if (isArrayLike) { + let ids = [] + for (let i = 0 ; i < found.length ; i++) { + ids.push(this.addToKnownElements(found[i])); + } + on_success(ids, command_id); + } else { + let id = this.addToKnownElements(found); + on_success({'ELEMENT':id}, command_id); + } + return; } },