Bug 749862 - findElements should return all matching elements, r=jgriffin, a=test-only

This commit is contained in:
Malini Das 2012-05-07 14:00:30 -07:00
parent eda1d7b45b
commit a5e38a5f84
2 changed files with 25 additions and 4 deletions

View File

@ -71,6 +71,9 @@ class TestElements(MarionetteTestCase):
found_el = self.marionette.find_element("tag name", "body")
self.assertEqual(HTMLElement, type(found_el))
self.assertEqual(el.id, found_el.id)
found_el = self.marionette.find_elements("tag name", "body")[0]
self.assertEqual(HTMLElement, type(found_el))
self.assertEqual(el.id, found_el.id)
def test_class_name(self):
test_html = self.marionette.absolute_url("test.html")
@ -79,6 +82,9 @@ class TestElements(MarionetteTestCase):
found_el = self.marionette.find_element("class name", "linkClass")
self.assertEqual(HTMLElement, type(found_el));
self.assertEqual(el.id, found_el.id)
found_el = self.marionette.find_elements("class name", "linkClass")[0]
self.assertEqual(HTMLElement, type(found_el));
self.assertEqual(el.id, found_el.id)
def test_name(self):
test_html = self.marionette.absolute_url("test.html")
@ -87,6 +93,9 @@ class TestElements(MarionetteTestCase):
found_el = self.marionette.find_element("name", "myInput")
self.assertEqual(HTMLElement, type(found_el))
self.assertEqual(el.id, found_el.id)
found_el = self.marionette.find_elements("name", "myInput")[0]
self.assertEqual(HTMLElement, type(found_el))
self.assertEqual(el.id, found_el.id)
def test_selector(self):
test_html = self.marionette.absolute_url("test.html")
@ -95,6 +104,9 @@ class TestElements(MarionetteTestCase):
found_el = self.marionette.find_element("css selector", "h1")
self.assertEqual(HTMLElement, type(found_el))
self.assertEqual(el.id, found_el.id)
found_el = self.marionette.find_elements("css selector", "h1")[0]
self.assertEqual(HTMLElement, type(found_el))
self.assertEqual(el.id, found_el.id)
def test_link_text(self):
test_html = self.marionette.absolute_url("test.html")
@ -103,6 +115,9 @@ class TestElements(MarionetteTestCase):
found_el = self.marionette.find_element("link text", "Click me!")
self.assertEqual(HTMLElement, type(found_el))
self.assertEqual(el.id, found_el.id)
found_el = self.marionette.find_elements("link text", "Click me!")[0]
self.assertEqual(HTMLElement, type(found_el))
self.assertEqual(el.id, found_el.id)
def test_partial_link_text(self):
test_html = self.marionette.absolute_url("test.html")
@ -111,6 +126,9 @@ class TestElements(MarionetteTestCase):
found_el = self.marionette.find_element("partial link text", "Click m")
self.assertEqual(HTMLElement, type(found_el))
self.assertEqual(el.id, found_el.id)
found_el = self.marionette.find_elements("partial link text", "Click m")[0]
self.assertEqual(HTMLElement, type(found_el))
self.assertEqual(el.id, found_el.id)
def test_xpath(self):
test_html = self.marionette.absolute_url("test.html")
@ -119,6 +137,9 @@ class TestElements(MarionetteTestCase):
found_el = self.marionette.find_element("xpath", "id('mozLink')")
self.assertEqual(HTMLElement, type(found_el))
self.assertEqual(el.id, found_el.id)
found_el = self.marionette.find_elements("xpath", "id('mozLink')")[0]
self.assertEqual(HTMLElement, type(found_el))
self.assertEqual(el.id, found_el.id)
def test_not_found(self):
test_html = self.marionette.absolute_url("test.html")

View File

@ -402,9 +402,9 @@ ElementManager.prototype = {
elements = this.findByXPathAll(rootNode, value, startNode);
break;
case NAME:
element = startNode.getElementsByName ?
startNode.getElementsByName(value)[0] :
this.findByXPathAll(rootNode, './/*[@name="' + value + '"]', startNode);
elements = startNode.getElementsByName ?
startNode.getElementsByName(value) :
this.findByXPathAll(rootNode, './/*[@name="' + value + '"]', startNode);
break;
case CLASS_NAME:
elements = startNode.getElementsByClassName(value);
@ -427,7 +427,7 @@ ElementManager.prototype = {
}
break;
case SELECTOR:
elements = rootNode.querySelectorAll(value);
elements = Array.slice(rootNode.querySelectorAll(value));
break;
default:
throw new ElementException("No such strategy", 500, null);