Bug 1198542: Update Marionette element IDs to be valid UUID. r?ato draft
authorDavid Burns <dburns@mozilla.com>
Wed, 26 Aug 2015 19:52:09 +0100
changeset 288037 aa3f921bfd03a11ca9985ffa63fd0c68156cfc90
parent 287933 338581c45777d43bf9c9a7764e19cbf0e9878ca9
child 508722 6f3b73c7afa95d68f1b788d99da6487523afbeee
push id4789
push userdburns@mozilla.com
push dateWed, 26 Aug 2015 19:12:26 +0000
reviewersato
bugs1198542
milestone43.0a1
Bug 1198542: Update Marionette element IDs to be valid UUID. r?ato This allows WebDriver compatibility to create valid URI.
testing/marionette/client/marionette/tests/unit/test_findelement.py
testing/marionette/elements.js
--- a/testing/marionette/client/marionette/tests/unit/test_findelement.py
+++ b/testing/marionette/client/marionette/tests/unit/test_findelement.py
@@ -154,8 +154,18 @@ class TestElements(MarionetteTestCase):
         fbody = self.marionette.find_element(By.TAG_NAME, 'body')
         abody = self.marionette.get_active_element()
         self.assertEqual(fbody, abody)
 
     def test_throws_error_when_trying_to_use_invalid_selector_type(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
         self.assertRaises(InvalidSelectorException, self.marionette.find_element, "Brie Search Type", "doesn't matter")
+
+    def test_element_id_is_valid_uuid(self):
+        import re
+        test_html = self.marionette.absolute_url("test.html")
+        self.marionette.navigate(test_html)
+        el = self.marionette.find_element(By.TAG_NAME, "body")
+        uuid_regex = re.compile('^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$')
+        self.assertIsNotNone(re.search(uuid_regex, el.id),
+                             'UUID for the WebElement is not valid. ID is {}'\
+                             .format(el.id))
--- a/testing/marionette/elements.js
+++ b/testing/marionette/elements.js
@@ -228,17 +228,18 @@ ElementManager.prototype = {
         if (XPCNativeWrapper(foundEl) == XPCNativeWrapper(element)) {
           return i;
         }
       } else {
         // cleanup reference to GC'd element
         delete this.seenItems[i];
       }
     }
-    let id = uuidGen.generateUUID().toString();
+    let uuid = uuidGen.generateUUID().toString();
+    let id = uuid.substring(1, uuid.length - 1);
     this.seenItems[id] = Components.utils.getWeakReference(element);
     return id;
   },
 
   /**
    * Retrieve element from its unique ID
    *
    * @param String id