tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_element_id.py (1870B)


      1 # This Source Code Form is subject to the terms of the Mozilla Public
      2 # License, v. 2.0. If a copy of the MPL was not distributed with this
      3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      4 
      5 import re
      6 from urllib.parse import quote
      7 
      8 from marionette_driver.by import By
      9 from marionette_driver.errors import NoSuchElementException, InvalidSelectorException
     10 from marionette_driver.marionette import WebElement
     11 
     12 from marionette_harness import MarionetteTestCase
     13 
     14 
     15 def inline(doc):
     16    return "data:text/html;charset=utf-8,{}".format(quote(doc))
     17 
     18 
     19 id_html = inline("<p id=foo></p>")
     20 
     21 
     22 class TestElementID(MarionetteTestCase):
     23    def setUp(self):
     24        MarionetteTestCase.setUp(self)
     25        self.marionette.timeout.implicit = 0
     26 
     27    def test_id_is_valid_uuid(self):
     28        self.marionette.navigate(id_html)
     29        el = self.marionette.find_element(By.TAG_NAME, "p")
     30        uuid_regex = re.compile(
     31            "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
     32        )
     33        self.assertIsNotNone(
     34            re.search(uuid_regex, el.id),
     35            "UUID for the WebElement is not valid. ID is {}".format(el.id),
     36        )
     37 
     38    def test_id_identical_for_the_same_element(self):
     39        self.marionette.navigate(id_html)
     40        found = self.marionette.find_element(By.ID, "foo")
     41        self.assertIsInstance(found, WebElement)
     42 
     43        found_again = self.marionette.find_element(By.ID, "foo")
     44        self.assertEqual(found_again, found)
     45 
     46    def test_id_unique_per_session(self):
     47        self.marionette.navigate(id_html)
     48        found = self.marionette.find_element(By.ID, "foo")
     49        self.assertIsInstance(found, WebElement)
     50 
     51        self.marionette.delete_session()
     52        self.marionette.start_session()
     53 
     54        found_again = self.marionette.find_element(By.ID, "foo")
     55        self.assertNotEqual(found_again.id, found.id)