test_timeouts.py (4192B)
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 from marionette_driver.by import By 6 from marionette_driver.errors import ( 7 MarionetteException, 8 NoSuchElementException, 9 ScriptTimeoutException, 10 ) 11 from marionette_driver.marionette import WebElement 12 13 from marionette_harness import MarionetteTestCase, run_if_manage_instance 14 15 16 class TestTimeouts(MarionetteTestCase): 17 def tearDown(self): 18 self.marionette.timeout.reset() 19 MarionetteTestCase.tearDown(self) 20 21 def test_get_timeout_fraction(self): 22 self.marionette.timeout.script = 0.5 23 self.assertEqual(self.marionette.timeout.script, 0.5) 24 25 def test_page_timeout_notdefinetimeout_pass(self): 26 test_html = self.marionette.absolute_url("test.html") 27 self.marionette.navigate(test_html) 28 29 def test_page_timeout_fail(self): 30 self.marionette.timeout.page_load = 0 31 test_html = self.marionette.absolute_url("slow") 32 with self.assertRaises(MarionetteException): 33 self.marionette.navigate(test_html) 34 35 def test_page_timeout_pass(self): 36 self.marionette.timeout.page_load = 60 37 test_html = self.marionette.absolute_url("test.html") 38 self.marionette.navigate(test_html) 39 40 def test_search_timeout_notfound_settimeout(self): 41 test_html = self.marionette.absolute_url("test.html") 42 self.marionette.navigate(test_html) 43 self.marionette.timeout.implicit = 1 44 with self.assertRaises(NoSuchElementException): 45 self.marionette.find_element(By.ID, "I'm not on the page") 46 self.marionette.timeout.implicit = 0 47 with self.assertRaises(NoSuchElementException): 48 self.marionette.find_element(By.ID, "I'm not on the page") 49 50 def test_search_timeout_found_settimeout(self): 51 test_html = self.marionette.absolute_url("test.html") 52 self.marionette.navigate(test_html) 53 button = self.marionette.find_element(By.ID, "createDivButton") 54 button.click() 55 self.marionette.timeout.implicit = 8 56 self.assertEqual( 57 WebElement, type(self.marionette.find_element(By.ID, "newDiv")) 58 ) 59 60 def test_search_timeout_found(self): 61 test_html = self.marionette.absolute_url("test.html") 62 self.marionette.navigate(test_html) 63 button = self.marionette.find_element(By.ID, "createDivButton") 64 button.click() 65 self.assertRaises( 66 NoSuchElementException, self.marionette.find_element, By.ID, "newDiv" 67 ) 68 69 @run_if_manage_instance("Only runnable if Marionette manages the instance") 70 def test_reset_timeout(self): 71 timeouts = [ 72 getattr(self.marionette.timeout, f) 73 for f in ( 74 "implicit", 75 "page_load", 76 "script", 77 ) 78 ] 79 80 def do_check(callback): 81 for timeout in timeouts: 82 timeout = 10000 83 self.assertEqual(timeout, 10000) 84 callback() 85 for timeout in timeouts: 86 self.assertNotEqual(timeout, 10000) 87 88 def callback_quit(): 89 self.marionette.quit() 90 self.marionette.start_session() 91 92 do_check(self.marionette.restart) 93 do_check(callback_quit) 94 95 def test_execute_async_timeout_settimeout(self): 96 test_html = self.marionette.absolute_url("test.html") 97 self.marionette.navigate(test_html) 98 self.marionette.timeout.script = 1 99 with self.assertRaises(ScriptTimeoutException): 100 self.marionette.execute_async_script("var x = 1;") 101 102 def test_no_timeout_settimeout(self): 103 test_html = self.marionette.absolute_url("test.html") 104 self.marionette.navigate(test_html) 105 self.marionette.timeout.script = 1 106 self.assertTrue( 107 self.marionette.execute_async_script( 108 """ 109 var callback = arguments[arguments.length - 1]; 110 setTimeout(function() { callback(true); }, 500); 111 """ 112 ) 113 )