test_chrome_action.py (2203B)
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 import By 9 from marionette_driver.keys import Keys 10 11 from marionette_harness import MarionetteTestCase, WindowManagerMixin 12 13 # add this directory to the path 14 sys.path.append(os.path.dirname(__file__)) 15 16 from chrome_handler_mixin import ChromeHandlerMixin 17 18 19 class TestPointerActions(ChromeHandlerMixin, WindowManagerMixin, MarionetteTestCase): 20 def setUp(self): 21 super(TestPointerActions, self).setUp() 22 23 self.mouse_chain = self.marionette.actions.sequence( 24 "pointer", "pointer_id", {"pointerType": "mouse"} 25 ) 26 self.key_chain = self.marionette.actions.sequence("key", "keyboard_id") 27 28 if self.marionette.session_capabilities["platformName"] == "mac": 29 self.mod_key = Keys.META 30 else: 31 self.mod_key = Keys.CONTROL 32 33 self.marionette.set_context("chrome") 34 35 self.win = self.open_chrome_window(self.chrome_base_url + "test.xhtml") 36 self.marionette.switch_to_window(self.win) 37 38 def tearDown(self): 39 self.marionette.actions.release() 40 self.close_all_windows() 41 42 super(TestPointerActions, self).tearDown() 43 44 def test_click_action(self): 45 box = self.marionette.find_element(By.ID, "testBox") 46 box.get_property("localName") 47 self.assertFalse( 48 self.marionette.execute_script( 49 "return document.getElementById('testBox').checked" 50 ) 51 ) 52 self.mouse_chain.click(element=box).perform() 53 self.assertTrue( 54 self.marionette.execute_script( 55 "return document.getElementById('testBox').checked" 56 ) 57 ) 58 59 def test_key_action(self): 60 self.marionette.find_element(By.ID, "textInput").click() 61 self.key_chain.send_keys("x").perform() 62 self.assertEqual( 63 self.marionette.execute_script( 64 "return document.getElementById('textInput').value" 65 ), 66 "testx", 67 )