tor-browser

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

test_chrome_element_state.py (2198B)


      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 os
      6 import sys
      7 
      8 from marionette_driver.by import By
      9 from marionette_harness import MarionetteTestCase, skip, WindowManagerMixin
     10 
     11 # add this directory to the path
     12 sys.path.append(os.path.dirname(__file__))
     13 
     14 from chrome_handler_mixin import ChromeHandlerMixin
     15 
     16 
     17 class TestElementState(ChromeHandlerMixin, WindowManagerMixin, MarionetteTestCase):
     18    def setUp(self):
     19        super(TestElementState, self).setUp()
     20 
     21        self.marionette.set_context("chrome")
     22 
     23        self.win = self.open_chrome_window(self.chrome_base_url + "test.xhtml")
     24        self.marionette.switch_to_window(self.win)
     25 
     26    def tearDown(self):
     27        self.close_all_windows()
     28 
     29        super(TestElementState, self).tearDown()
     30 
     31    def test_is_displayed(self):
     32        l = self.marionette.find_element(By.ID, "textInput")
     33        self.assertTrue(l.is_displayed())
     34        self.marionette.execute_script("arguments[0].hidden = true;", [l])
     35        self.assertFalse(l.is_displayed())
     36        self.marionette.execute_script("arguments[0].hidden = false;", [l])
     37 
     38    def test_enabled(self):
     39        l = self.marionette.find_element(By.ID, "textInput")
     40        self.assertTrue(l.is_enabled())
     41        self.marionette.execute_script("arguments[0].disabled = true;", [l])
     42        self.assertFalse(l.is_enabled())
     43        self.marionette.execute_script("arguments[0].disabled = false;", [l])
     44 
     45    def test_can_get_element_rect(self):
     46        l = self.marionette.find_element(By.ID, "textInput")
     47        rect = l.rect
     48        self.assertTrue(rect["x"] > 0)
     49        self.assertTrue(rect["y"] > 0)
     50 
     51    def test_get_attribute(self):
     52        el = self.marionette.execute_script(
     53            "return window.document.getElementById('textInput');"
     54        )
     55        self.assertEqual(el.get_attribute("id"), "textInput")
     56 
     57    def test_get_property(self):
     58        el = self.marionette.execute_script(
     59            "return window.document.getElementById('textInput');"
     60        )
     61        self.assertEqual(el.get_property("id"), "textInput")