@@ -32,8 +32,10 @@ def test_anything(self):
32
32
"""
33
33
34
34
import codecs
35
+ import fasteners
35
36
import json
36
37
import logging
38
+ import math
37
39
import os
38
40
import re
39
41
import shutil
@@ -169,6 +171,8 @@ def open(self, url):
169
171
self.__check_browser()
170
172
if self.__needs_minimum_wait():
171
173
time.sleep(0.01)
174
+ if self.undetectable:
175
+ time.sleep(0.02)
172
176
pre_action_url = None
173
177
try:
174
178
pre_action_url = self.driver.current_url
@@ -243,6 +247,8 @@ def open(self, url):
243
247
self.wait_for_ready_state_complete()
244
248
if self.__needs_minimum_wait():
245
249
time.sleep(0.03) # Force a minimum wait, even if skipping waits.
250
+ if self.undetectable:
251
+ time.sleep(0.02)
246
252
self.__demo_mode_pause_if_active()
247
253
248
254
def get(self, url):
@@ -289,6 +295,8 @@ def click(
289
295
return
290
296
if self.browser == "safari":
291
297
self.wait_for_ready_state_complete()
298
+ if self.__needs_minimum_wait():
299
+ time.sleep(0.02)
292
300
element = page_actions.wait_for_element_visible(
293
301
self.driver,
294
302
selector,
@@ -467,26 +475,34 @@ def click(
467
475
except Exception:
468
476
pass
469
477
if self.__needs_minimum_wait():
470
- time.sleep(0.02 )
478
+ time.sleep(0.05 )
471
479
else:
472
480
# A smaller subset of self.wait_for_ready_state_complete()
473
481
try:
474
482
self.wait_for_angularjs(timeout=settings.MINI_TIMEOUT)
475
483
except Exception:
476
484
pass
477
485
if self.__needs_minimum_wait():
478
- time.sleep(0.01)
486
+ time.sleep(0.025)
487
+ if self.undetectable:
488
+ time.sleep(0.025)
479
489
try:
480
490
if self.driver.current_url != pre_action_url:
481
491
self.__ad_block_as_needed()
482
492
self.__disable_beforeunload_as_needed()
493
+ if self.__needs_minimum_wait():
494
+ time.sleep(0.025)
495
+ if self.undetectable:
496
+ time.sleep(0.025)
483
497
except Exception:
484
498
try:
485
499
self.wait_for_ready_state_complete()
486
500
except Exception:
487
501
pass
488
502
if self.__needs_minimum_wait():
489
- time.sleep(0.02)
503
+ time.sleep(0.025)
504
+ if self.undetectable:
505
+ time.sleep(0.025)
490
506
if self.demo_mode:
491
507
if self.driver.current_url != pre_action_url:
492
508
self.__demo_mode_pause_if_active()
@@ -642,6 +658,8 @@ def update_text(
642
658
self.__demo_mode_highlight_if_active(selector, by)
643
659
if not self.demo_mode and not self.slow_mode:
644
660
self.__scroll_to_element(element, selector, by)
661
+ if self.__needs_minimum_wait():
662
+ time.sleep(0.01)
645
663
try:
646
664
element.clear() # May need https://stackoverflow.com/a/50691625
647
665
backspaces = Keys.BACK_SPACE * 42 # Is the answer to everything
@@ -703,6 +721,10 @@ def update_text(
703
721
raise e
704
722
if settings.WAIT_FOR_RSC_ON_PAGE_LOADS:
705
723
self.wait_for_ready_state_complete()
724
+ if self.__needs_minimum_wait():
725
+ time.sleep(0.01)
726
+ if self.undetectable:
727
+ time.sleep(0.015)
706
728
if (
707
729
retry
708
730
and element.get_attribute("value") != text
@@ -2880,11 +2902,16 @@ def switch_to_frame(self, frame, timeout=None):
2880
2902
timeout = settings.LARGE_TIMEOUT
2881
2903
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
2882
2904
timeout = self.__get_new_timeout(timeout)
2905
+ if self.__needs_minimum_wait():
2906
+ time.sleep(0.03)
2883
2907
if type(frame) is str and self.is_element_visible(frame):
2884
2908
try:
2885
2909
self.scroll_to(frame, timeout=1)
2886
2910
except Exception:
2887
2911
pass
2912
+ else:
2913
+ if self.__needs_minimum_wait():
2914
+ time.sleep(0.03)
2888
2915
if self.recorder_mode and self._rec_overrides_switch:
2889
2916
url = self.get_current_url()
2890
2917
if url and len(url) > 0:
@@ -2908,6 +2935,8 @@ def switch_to_frame(self, frame, timeout=None):
2908
2935
time.sleep(0.02)
2909
2936
page_actions.switch_to_frame(self.driver, frame, timeout)
2910
2937
self.wait_for_ready_state_complete()
2938
+ if self.__needs_minimum_wait():
2939
+ time.sleep(0.01)
2911
2940
2912
2941
def switch_to_default_content(self):
2913
2942
"""Brings driver control outside the current iframe.
@@ -3763,7 +3792,7 @@ def wait_for_ready_state_complete(self, timeout=None):
3763
3792
and hasattr(settings, "SKIP_JS_WAITS")
3764
3793
and settings.SKIP_JS_WAITS
3765
3794
):
3766
- time.sleep(0.03 )
3795
+ time.sleep(0.05 )
3767
3796
return True
3768
3797
3769
3798
def wait_for_angularjs(self, timeout=None, **kwargs):
@@ -5041,6 +5070,10 @@ def highlight(self, selector, by="css selector", loops=None, scroll=True):
5041
5070
if self.browser == "ie":
5042
5071
loops = 1 # Override previous setting because IE is slow
5043
5072
loops = int(loops)
5073
+ if self.headless or self.headless2 or self.xvfb:
5074
+ # Headless modes have less need for highlighting elements.
5075
+ # However, highlight() may be used as a sleep alternative.
5076
+ loops = int(math.ceil(loops * 0.5))
5044
5077
5045
5078
o_bs = "" # original_box_shadow
5046
5079
try:
@@ -5615,13 +5648,16 @@ def ad_block(self):
5615
5648
5616
5649
def show_file_choosers(self):
5617
5650
"""Display hidden file-chooser input fields on sites if present."""
5651
+ self.wait_for_ready_state_complete()
5618
5652
css_selector = 'input[type="file"]'
5619
5653
try:
5620
5654
self.wait_for_element_present(
5621
5655
css_selector, timeout=settings.MINI_TIMEOUT
5622
5656
)
5623
5657
except Exception:
5624
5658
pass
5659
+ if self.__needs_minimum_wait():
5660
+ time.sleep(0.05)
5625
5661
try:
5626
5662
self.show_elements(css_selector)
5627
5663
except Exception:
@@ -5701,13 +5737,19 @@ def get_unique_links(self):
5701
5737
"a"->"href", "img"->"src", "link"->"href", and "script"->"src".
5702
5738
"""
5703
5739
self.wait_for_ready_state_complete()
5740
+ if self.__needs_minimum_wait():
5741
+ time.sleep(0.05)
5742
+ if self.undetectable:
5743
+ time.sleep(0.05)
5704
5744
try:
5705
5745
self.wait_for_element_present("body", timeout=1.5)
5706
5746
self.wait_for_element_visible("body", timeout=1.5)
5707
5747
except Exception:
5708
5748
pass
5709
5749
if self.__needs_minimum_wait():
5710
5750
time.sleep(0.25)
5751
+ if self.undetectable:
5752
+ time.sleep(0.123)
5711
5753
soup = self.get_beautiful_soup(self.get_page_source())
5712
5754
page_url = self.get_current_url()
5713
5755
links = page_utils._get_unique_links(page_url, soup)
@@ -11558,7 +11600,7 @@ def check_window(
11558
11600
"""
11559
11601
self.wait_for_ready_state_complete()
11560
11602
if self.__needs_minimum_wait():
11561
- time.sleep(0.02 ) # Force a minimum wait, even if skipping waits.
11603
+ time.sleep(0.05 ) # Force a minimum wait, even if skipping waits.
11562
11604
try:
11563
11605
self.wait_for_element_visible(
11564
11606
"body", timeout=settings.MINI_TIMEOUT
@@ -11792,8 +11834,6 @@ def check_window(
11792
11834
11793
11835
def __get_new_timeout(self, timeout):
11794
11836
"""When using --timeout_multiplier=#.#"""
11795
- import math
11796
-
11797
11837
self.__check_scope()
11798
11838
try:
11799
11839
timeout_multiplier = float(self.timeout_multiplier)
@@ -11889,7 +11929,7 @@ def deferred_assert_element(
11889
11929
try:
11890
11930
url = self.get_current_url()
11891
11931
if url == self.__last_url_of_deferred_assert:
11892
- timeout = 1 # Was already on page (full wait not needed)
11932
+ timeout = 0.6 # Was already on page (full wait not needed)
11893
11933
else:
11894
11934
self.__last_url_of_deferred_assert = url
11895
11935
except Exception:
@@ -11930,7 +11970,7 @@ def deferred_assert_element_present(
11930
11970
try:
11931
11971
url = self.get_current_url()
11932
11972
if url == self.__last_url_of_deferred_assert:
11933
- timeout = 1 # Was already on page (full wait not needed)
11973
+ timeout = 0.6 # Was already on page (full wait not needed)
11934
11974
else:
11935
11975
self.__last_url_of_deferred_assert = url
11936
11976
except Exception:
@@ -11971,7 +12011,7 @@ def deferred_assert_text(
11971
12011
try:
11972
12012
url = self.get_current_url()
11973
12013
if url == self.__last_url_of_deferred_assert:
11974
- timeout = 1 # Was already on page (full wait not needed)
12014
+ timeout = 0.6 # Was already on page (full wait not needed)
11975
12015
else:
11976
12016
self.__last_url_of_deferred_assert = url
11977
12017
except Exception:
@@ -12013,7 +12053,7 @@ def deferred_assert_exact_text(
12013
12053
try:
12014
12054
url = self.get_current_url()
12015
12055
if url == self.__last_url_of_deferred_assert:
12016
- timeout = 1 # Was already on page (full wait not needed)
12056
+ timeout = 0.6 # Was already on page (full wait not needed)
12017
12057
else:
12018
12058
self.__last_url_of_deferred_assert = url
12019
12059
except Exception:
@@ -12250,7 +12290,7 @@ def __click_with_offset(
12250
12290
12251
12291
self.wait_for_ready_state_complete()
12252
12292
if self.__needs_minimum_wait():
12253
- time.sleep(0.02 ) # Force a minimum wait, even if skipping waits.
12293
+ time.sleep(0.03 ) # Force a minimum wait, even if skipping waits.
12254
12294
if not timeout:
12255
12295
timeout = settings.SMALL_TIMEOUT
12256
12296
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
@@ -12300,7 +12340,9 @@ def __click_with_offset(
12300
12340
self.driver.execute_script(scroll_script)
12301
12341
time.sleep(0.1)
12302
12342
except Exception:
12303
- pass
12343
+ time.sleep(0.05)
12344
+ if self.__needs_minimum_wait():
12345
+ time.sleep(0.05)
12304
12346
try:
12305
12347
if selenium4_or_newer and not center:
12306
12348
element_rect = element.rect
@@ -12937,8 +12979,6 @@ def setUp(self, masterqa_mode=False):
12937
12979
self.dashboard = sb_config.dashboard
12938
12980
self._dash_initialized = sb_config._dashboard_initialized
12939
12981
if self.dashboard and self._multithreaded:
12940
- import fasteners
12941
-
12942
12982
self.dash_lock = fasteners.InterProcessLock(
12943
12983
constants.Dashboard.LOCKFILE
12944
12984
)
@@ -13693,8 +13733,6 @@ def __create_log_path_as_needed(self, test_logpath):
13693
13733
13694
13734
def _process_dashboard_entry(self, has_exception, init=False):
13695
13735
if self._multithreaded:
13696
- import fasteners
13697
-
13698
13736
self.dash_lock = fasteners.InterProcessLock(
13699
13737
constants.Dashboard.LOCKFILE
13700
13738
)
0 commit comments