@@ -358,6 +358,11 @@ def click(
358
358
self .__switch_to_newest_window_if_not_blank ()
359
359
if settings .WAIT_FOR_RSC_ON_CLICKS :
360
360
self .wait_for_ready_state_complete ()
361
+ else :
362
+ # A smaller subset of self.wait_for_ready_state_complete()
363
+ self .wait_for_angularjs (timeout = settings .MINI_TIMEOUT )
364
+ if self .driver .current_url != pre_action_url :
365
+ self .__ad_block_as_needed ()
361
366
if self .demo_mode :
362
367
if self .driver .current_url != pre_action_url :
363
368
self .__demo_mode_pause_if_active ()
@@ -437,6 +442,11 @@ def double_click(self, selector, by=By.CSS_SELECTOR, timeout=None):
437
442
self .safe_execute_script (double_click_script )
438
443
if settings .WAIT_FOR_RSC_ON_CLICKS :
439
444
self .wait_for_ready_state_complete ()
445
+ else :
446
+ # A smaller subset of self.wait_for_ready_state_complete()
447
+ self .wait_for_angularjs (timeout = settings .MINI_TIMEOUT )
448
+ if self .driver .current_url != pre_action_url :
449
+ self .__ad_block_as_needed ()
440
450
if self .demo_mode :
441
451
if self .driver .current_url != pre_action_url :
442
452
self .__demo_mode_pause_if_active ()
@@ -1064,7 +1074,7 @@ def click_link_text(self, link_text, timeout=None):
1064
1074
)
1065
1075
):
1066
1076
self .__switch_to_newest_window_if_not_blank ()
1067
- if settings .WAIT_FOR_RSC_ON_CLICKS :
1077
+ if settings .WAIT_FOR_RSC_ON_PAGE_LOADS :
1068
1078
self .wait_for_ready_state_complete ()
1069
1079
if self .demo_mode :
1070
1080
if self .driver .current_url != pre_action_url :
@@ -1196,7 +1206,7 @@ def click_partial_link_text(self, partial_link_text, timeout=None):
1196
1206
)
1197
1207
):
1198
1208
self .__switch_to_newest_window_if_not_blank ()
1199
- if settings .WAIT_FOR_RSC_ON_CLICKS :
1209
+ if settings .WAIT_FOR_RSC_ON_PAGE_LOADS :
1200
1210
self .wait_for_ready_state_complete ()
1201
1211
if self .demo_mode :
1202
1212
if self .driver .current_url != pre_action_url :
@@ -1641,6 +1651,11 @@ def click_active_element(self):
1641
1651
self .__switch_to_newest_window_if_not_blank ()
1642
1652
if settings .WAIT_FOR_RSC_ON_CLICKS :
1643
1653
self .wait_for_ready_state_complete ()
1654
+ else :
1655
+ # A smaller subset of self.wait_for_ready_state_complete()
1656
+ self .wait_for_angularjs (timeout = settings .MINI_TIMEOUT )
1657
+ if self .driver .current_url != pre_action_url :
1658
+ self .__ad_block_as_needed ()
1644
1659
if self .demo_mode :
1645
1660
if self .driver .current_url != pre_action_url :
1646
1661
self .__demo_mode_pause_if_active ()
@@ -2142,6 +2157,9 @@ def __select_option(
2142
2157
self .__switch_to_newest_window_if_not_blank ()
2143
2158
if settings .WAIT_FOR_RSC_ON_CLICKS :
2144
2159
self .wait_for_ready_state_complete ()
2160
+ else :
2161
+ # A smaller subset of self.wait_for_ready_state_complete()
2162
+ self .wait_for_angularjs (timeout = settings .MINI_TIMEOUT )
2145
2163
if self .demo_mode :
2146
2164
if self .driver .current_url != pre_action_url :
2147
2165
self .__demo_mode_pause_if_active ()
@@ -3112,35 +3130,46 @@ def delete_saved_cookies(self, name="cookies.txt"):
3112
3130
if cookies_file_path .endswith (".txt" ):
3113
3131
os .remove (cookies_file_path )
3114
3132
3133
+ def __ad_block_as_needed (self ):
3134
+ """ This is an internal method for handling ad-blocking.
3135
+ Use "pytest --ad-block" to enable this during tests.
3136
+ When not Chromium or in headless mode, use the hack. """
3137
+ if self .ad_block_on and (self .headless or not self .is_chromium ()):
3138
+ # (Chromium browsers in headed mode use the extension instead)
3139
+ current_url = self .get_current_url ()
3140
+ if not current_url == self .__last_page_load_url :
3141
+ if page_actions .is_element_present (
3142
+ self .driver , "iframe" , By .CSS_SELECTOR
3143
+ ):
3144
+ self .ad_block ()
3145
+ self .__last_page_load_url = current_url
3146
+
3115
3147
def wait_for_ready_state_complete (self , timeout = None ):
3148
+ """ Waits for the "readyState" of the page to be "complete".
3149
+ Returns True when the method completes. """
3116
3150
self .__check_scope ()
3117
3151
self .__check_browser ()
3118
3152
if not timeout :
3119
3153
timeout = settings .EXTREME_TIMEOUT
3120
3154
if self .timeout_multiplier and timeout == settings .EXTREME_TIMEOUT :
3121
3155
timeout = self .__get_new_timeout (timeout )
3122
- is_ready = js_utils .wait_for_ready_state_complete (self .driver , timeout )
3156
+ js_utils .wait_for_ready_state_complete (self .driver , timeout )
3123
3157
self .wait_for_angularjs (timeout = settings .MINI_TIMEOUT )
3124
3158
if self .js_checking_on :
3125
3159
self .assert_no_js_errors ()
3126
- if self .ad_block_on and (self .headless or not self .is_chromium ()):
3127
- # For Chromium browsers in headed mode, the extension is used
3128
- current_url = self .get_current_url ()
3129
- if not current_url == self .__last_page_load_url :
3130
- if page_actions .is_element_present (
3131
- self .driver , "iframe" , By .CSS_SELECTOR
3132
- ):
3133
- self .ad_block ()
3134
- self .__last_page_load_url = current_url
3135
- return is_ready
3160
+ self .__ad_block_as_needed ()
3161
+ return True
3136
3162
3137
3163
def wait_for_angularjs (self , timeout = None , ** kwargs ):
3164
+ """ Waits for Angular components of the page to finish loading.
3165
+ Returns True when the method completes. """
3138
3166
self .__check_scope ()
3139
3167
if not timeout :
3140
- timeout = settings .LARGE_TIMEOUT
3141
- if self .timeout_multiplier and timeout == settings .LARGE_TIMEOUT :
3168
+ timeout = settings .MINI_TIMEOUT
3169
+ if self .timeout_multiplier and timeout == settings .MINI_TIMEOUT :
3142
3170
timeout = self .__get_new_timeout (timeout )
3143
3171
js_utils .wait_for_angularjs (self .driver , timeout , ** kwargs )
3172
+ return True
3144
3173
3145
3174
def sleep (self , seconds ):
3146
3175
self .__check_scope ()
0 commit comments