test_chrome_switch_frame.py (2289B)
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.errors import JavascriptException 10 from marionette_harness import MarionetteTestCase, WindowManagerMixin 11 12 # add this directory to the path 13 sys.path.append(os.path.dirname(__file__)) 14 15 from chrome_handler_mixin import ChromeHandlerMixin 16 17 18 class TestSwitchFrameChrome(ChromeHandlerMixin, WindowManagerMixin, MarionetteTestCase): 19 def setUp(self): 20 super(TestSwitchFrameChrome, self).setUp() 21 self.marionette.set_context("chrome") 22 23 new_window = self.open_chrome_window(self.chrome_base_url + "test.xhtml") 24 self.marionette.switch_to_window(new_window) 25 self.assertNotEqual( 26 self.start_window, self.marionette.current_chrome_window_handle 27 ) 28 29 def tearDown(self): 30 self.close_all_windows() 31 super(TestSwitchFrameChrome, self).tearDown() 32 33 def test_switch_simple(self): 34 self.assertIn( 35 "test.xhtml", self.marionette.get_url(), "Initial navigation has failed" 36 ) 37 self.marionette.switch_to_frame(0) 38 self.assertIn( 39 "test.xhtml", self.marionette.get_url(), "Switching by index failed" 40 ) 41 self.marionette.find_element(By.ID, "testBox") 42 self.marionette.switch_to_frame() 43 self.assertIn( 44 "test.xhtml", self.marionette.get_url(), "Switching by null failed" 45 ) 46 iframe = self.marionette.find_element(By.ID, "iframe") 47 self.marionette.switch_to_frame(iframe) 48 self.assertIn( 49 "test.xhtml", self.marionette.get_url(), "Switching by element failed" 50 ) 51 self.marionette.find_element(By.ID, "testBox") 52 53 def test_stack_trace(self): 54 self.assertIn( 55 "test.xhtml", self.marionette.get_url(), "Initial navigation has failed" 56 ) 57 self.marionette.switch_to_frame(0) 58 self.marionette.find_element(By.ID, "testBox") 59 try: 60 self.marionette.execute_async_script("foo();") 61 except JavascriptException as e: 62 self.assertIn("foo", str(e))