Bug 1251763 - Correct type check on singular returned elements; r=automatedtester a=test-only
authorAndreas Tolfsen <ato@mozilla.com>
Tue, 08 Mar 2016 16:23:50 +0000
changeset 325284 b5e97e81ab9d750b5fe151503ae4ece009e7f4fc
parent 325283 6405c7fb1a53debf045c348e0dbbfa1ec1e8c99d
child 325285 c9166eb24b3fe9dc52f950bbbf55ce43e39fc5ab
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersautomatedtester, test-only
bugs1251763
milestone47.0a2
Bug 1251763 - Correct type check on singular returned elements; r=automatedtester a=test-only The return values from the different element search functions in searchFn have inconsistent return types, and a null check is usually not what we want. In order to have findElement consistently return a no such element error, we need to do a loose false test. This bug has affected the findElement command when using the tag name, name, class name, link text, and partial link text selectors. Other selectors were unaffected. MozReview-Commit-ID: C26R3YrqKyf
testing/marionette/element.js
testing/marionette/harness/marionette/tests/unit/test_findelement.py
--- a/testing/marionette/element.js
+++ b/testing/marionette/element.js
@@ -428,17 +428,17 @@ ElementManager.prototype = {
       res = searchFn(strategy, selector, rootNode, startNode);
     } catch (e) {
       throw new InvalidSelectorError(
           `Given ${strategy} expression "${selector}" is invalid`);
     }
 
     if (element.isElementCollection(res)) {
       return res;
-    } else if (res !== null) {
+    } else if (res) {
       return [res];
     }
     return [];
   },
 
   /**
    * Find a value by XPATH
    *
--- a/testing/marionette/harness/marionette/tests/unit/test_findelement.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_findelement.py
@@ -4,16 +4,20 @@
 
 from marionette import MarionetteTestCase
 from marionette_driver.marionette import HTMLElement
 from marionette_driver.by import By
 from marionette_driver.errors import NoSuchElementException, InvalidSelectorException
 
 
 class TestElements(MarionetteTestCase):
+    def setUp(self):
+        MarionetteTestCase.setUp(self)
+        self.marionette.set_search_timeout(0)
+
     def test_id(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
         el = self.marionette.execute_script("return window.document.getElementById('mozLink');")
         found_el = self.marionette.find_element(By.ID, "mozLink")
         self.assertEqual(HTMLElement, type(found_el))
         self.assertEqual(el, found_el)
 
@@ -114,22 +118,36 @@ class TestElements(MarionetteTestCase):
         found_el = self.marionette.find_element(By.XPATH, "id('mozLink')")
         self.assertEqual(HTMLElement, type(found_el))
         self.assertEqual(el, found_el)
         found_el = self.marionette.find_elements(By.XPATH, "id('mozLink')")[0]
         self.assertEqual(HTMLElement, type(found_el))
         self.assertEqual(el, found_el)
 
     def test_not_found(self):
-        test_html = self.marionette.absolute_url("test.html")
-        self.marionette.navigate(test_html)
-        self.marionette.set_search_timeout(1000)
-        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "I'm not on the page")
         self.marionette.set_search_timeout(0)
-        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "I'm not on the page")
+        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.CLASS_NAME, "cheese")
+        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.CSS_SELECTOR, "cheese")
+        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "cheese")
+        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.LINK_TEXT, "cheese")
+        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.NAME, "cheese")
+        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.PARTIAL_LINK_TEXT, "cheese")
+        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.TAG_NAME, "cheese")
+        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.XPATH, "cheese")
+
+    def test_not_found_implicit_wait(self):
+        self.marionette.set_search_timeout(50)
+        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.CLASS_NAME, "cheese")
+        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.CSS_SELECTOR, "cheese")
+        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "cheese")
+        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.LINK_TEXT, "cheese")
+        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.NAME, "cheese")
+        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.PARTIAL_LINK_TEXT, "cheese")
+        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.TAG_NAME, "cheese")
+        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.XPATH, "cheese")
 
     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")
         button.click()
         self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "newDiv")
         self.assertTrue(True, self.marionette.set_search_timeout(8000))