Bug 1241067: Handle Invalid Selector values when finding elements r=ato

This allows us to now handle errors and return the appropriate
errors to the clients

--HG--
extra : commitid : K6Kqatm97sY
extra : rebase_source : 2f6ceefc910be77e6d88ed300d29650b41a171d9
extra : histedit_source : e636d2ca4b337140d54caba5a240ade7b7d8a01d
This commit is contained in:
David Burns 2016-01-21 21:07:36 +00:00
Родитель e9ce9ca165
Коммит 62c841c129
2 изменённых файлов: 51 добавлений и 1 удалений

Просмотреть файл

@ -181,3 +181,47 @@ class TestElements(MarionetteTestCase):
self.assertEqual(len(children), 2)
self.assertEqual("link1", children[0].get_attribute("name"))
self.assertEqual("link2", children[1].get_attribute("name"))
def test_should_throw_invalidselectorexception_when_invalid_xPath_in_driver_find_element(self):
test_html = self.marionette.absolute_url("formPage.html")
self.marionette.navigate(test_html)
self.assertRaises(InvalidSelectorException, self.marionette.find_element, By.XPATH, "count(//input)")
def test_should_throw_invalidselectorexception_when_invalid_xpath_in_driver_find_elements(self):
test_html = self.marionette.absolute_url("formPage.html")
self.marionette.navigate(test_html)
self.assertRaises(InvalidSelectorException, self.marionette.find_elements, By.XPATH, "count(//input)")
def test_should_throw_invalidselectorexception_when_invalid_xpath_in_element_find_element(self):
test_html = self.marionette.absolute_url("formPage.html")
self.marionette.navigate(test_html)
body = self.marionette.find_element(By.TAG_NAME, "body")
self.assertRaises(InvalidSelectorException, body.find_element, By.XPATH, "count(//input)")
def test_should_throw_invalidselectorexception_when_invalid_xpath_in_element_find_elements(self):
test_html = self.marionette.absolute_url("formPage.html")
self.marionette.navigate(test_html)
body = self.marionette.find_element(By.TAG_NAME, "body")
self.assertRaises(InvalidSelectorException, body.find_elements, By.XPATH, "count(//input)")
def test_should_throw_invalidselectorexception_when_css_is_empty_in_driver_find_element(self):
test_html = self.marionette.absolute_url("formPage.html")
self.marionette.navigate(test_html)
self.assertRaises(InvalidSelectorException, self.marionette.find_element, By.CSS_SELECTOR, "")
def test_should_throw_invalidselectorexception_when_css_is_empty_in_driver_find_elements(self):
test_html = self.marionette.absolute_url("formPage.html")
self.marionette.navigate(test_html)
self.assertRaises(InvalidSelectorException, self.marionette.find_elements, By.CSS_SELECTOR, "")
def test_should_throw_invalidselectorexception_when_css_is_empty_in_element_find_element(self):
test_html = self.marionette.absolute_url("formPage.html")
self.marionette.navigate(test_html)
body = self.marionette.find_element(By.TAG_NAME, "body")
self.assertRaises(InvalidSelectorException, body.find_element, By.CSS_SELECTOR, "")
def test_should_throw_invalidselectorexception_when_css_is_empty_in_element_find_elements(self):
test_html = self.marionette.absolute_url("formPage.html")
self.marionette.navigate(test_html)
body = self.marionette.find_element(By.TAG_NAME, "body")
self.assertRaises(InvalidSelectorException, body.find_elements, By.CSS_SELECTOR, "")

Просмотреть файл

@ -344,8 +344,14 @@ ElementManager.prototype = {
if (this.elementStrategies.indexOf(values.using) < 0) {
throw new InvalidSelectorError(`No such strategy: ${values.using}`);
}
let found = all ? this.findElements(values.using, values.value, rootNode, startNode) :
let found;
try {
found = all ? this.findElements(values.using, values.value, rootNode, startNode) :
this.findElement(values.using, values.value, rootNode, startNode);
} catch (e) {
throw new InvalidSelectorError(`Given ${values.using} expression "${values.value}" is invalid`);
}
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)) {