@@ -74,6 +74,7 @@ def __init__(self, *args, **kwargs):
74
74
self .__last_page_url = None
75
75
self .__last_page_source = None
76
76
self .__skip_reason = None
77
+ self .__overrided_default_timeouts = False
77
78
self .__added_pytest_html_extra = None
78
79
self .__deferred_assert_count = 0
79
80
self .__deferred_assert_failures = []
@@ -3648,6 +3649,46 @@ def set_time_limit(self, time_limit):
3648
3649
sb_config .time_limit = None
3649
3650
sb_config .time_limit_ms = None
3650
3651
3652
+ def set_default_timeout (self , timeout ):
3653
+ """ This method changes the default timeout values of test methods
3654
+ for the duration of the current test.
3655
+ Effected timeouts: (used by methods that wait for elements)
3656
+ * settings.SMALL_TIMEOUT - (default value: 6 seconds)
3657
+ * settings.LARGE_TIMEOUT - (default value: 10 seconds)
3658
+ The minimum allowable default timeout is: 0.5 seconds.
3659
+ The maximum allowable default timeout is: 60.0 seconds.
3660
+ (Test methods can still override timeouts outside that range.)
3661
+ """
3662
+ self .__check_scope ()
3663
+ if not type (timeout ) is int and not type (timeout ) is float :
3664
+ raise Exception ('Expecting a numeric value for "timeout"!' )
3665
+ if timeout < 0 :
3666
+ raise Exception ('The "timeout" cannot be a negative number!' )
3667
+ timeout = float (timeout )
3668
+ # Min default timeout: 0.5 seconds. Max default timeout: 60.0 seconds.
3669
+ min_timeout = 0.5
3670
+ max_timeout = 60.0
3671
+ if timeout < min_timeout :
3672
+ logging .info ("Minimum default timeout = %s" % min_timeout )
3673
+ timeout = min_timeout
3674
+ elif timeout > max_timeout :
3675
+ logging .info ("Maximum default timeout = %s" % max_timeout )
3676
+ timeout = max_timeout
3677
+ self .__overrided_default_timeouts = True
3678
+ sb_config ._is_timeout_changed = True
3679
+ settings .SMALL_TIMEOUT = timeout
3680
+ settings .LARGE_TIMEOUT = timeout
3681
+
3682
+ def reset_default_timeout (self ):
3683
+ """ Reset default timeout values to the original from settings.py
3684
+ This method reverts the changes made by set_default_timeout() """
3685
+ if self .__overrided_default_timeouts :
3686
+ if sb_config ._SMALL_TIMEOUT and sb_config ._LARGE_TIMEOUT :
3687
+ settings .SMALL_TIMEOUT = sb_config ._SMALL_TIMEOUT
3688
+ settings .LARGE_TIMEOUT = sb_config ._LARGE_TIMEOUT
3689
+ sb_config ._is_timeout_changed = False
3690
+ self .__overrided_default_timeouts = False
3691
+
3651
3692
def skip (self , reason = "" ):
3652
3693
""" Mark the test as Skipped. """
3653
3694
self .__check_scope ()
@@ -7383,6 +7424,17 @@ def setUp(self, masterqa_mode=False):
7383
7424
""" >>> "pip install -r requirements.txt"\n """
7384
7425
""" >>> "python setup.py install" """ )
7385
7426
7427
+ if not hasattr (sb_config , '_is_timeout_changed' ):
7428
+ # Should only be reachable from pure Python runs
7429
+ sb_config ._is_timeout_changed = False
7430
+ sb_config ._SMALL_TIMEOUT = settings .SMALL_TIMEOUT
7431
+ sb_config ._LARGE_TIMEOUT = settings .LARGE_TIMEOUT
7432
+
7433
+ if sb_config ._is_timeout_changed :
7434
+ if sb_config ._SMALL_TIMEOUT and sb_config ._LARGE_TIMEOUT :
7435
+ settings .SMALL_TIMEOUT = sb_config ._SMALL_TIMEOUT
7436
+ settings .LARGE_TIMEOUT = sb_config ._LARGE_TIMEOUT
7437
+
7386
7438
# Parse the settings file
7387
7439
if self .settings_file :
7388
7440
from seleniumbase .core import settings_parser
@@ -8037,6 +8089,14 @@ def tearDown(self):
8037
8089
# *** Start tearDown() officially ***
8038
8090
self .__slow_mode_pause_if_active ()
8039
8091
has_exception = self .__has_exception ()
8092
+ if self .__overrided_default_timeouts :
8093
+ # Reset default timeouts in case there are more tests
8094
+ # These were changed in set_default_timeout()
8095
+ if sb_config ._SMALL_TIMEOUT and sb_config ._LARGE_TIMEOUT :
8096
+ settings .SMALL_TIMEOUT = sb_config ._SMALL_TIMEOUT
8097
+ settings .LARGE_TIMEOUT = sb_config ._LARGE_TIMEOUT
8098
+ sb_config ._is_timeout_changed = False
8099
+ self .__overrided_default_timeouts = False
8040
8100
if self .__deferred_assert_failures :
8041
8101
print (
8042
8102
"\n When using self.deferred_assert_*() methods in your tests, "
0 commit comments