Skip to content

Commit 12ac359

Browse files
committed
Make improvements to Recorder Mode
1 parent 5eb88d6 commit 12ac359

File tree

1 file changed

+83
-2
lines changed

1 file changed

+83
-2
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3763,6 +3763,7 @@ def __process_recorded_actions(self):
37633763
ext_actions.append("as_at")
37643764
ext_actions.append("as_te")
37653765
ext_actions.append("as_et")
3766+
ext_actions.append("wf_el")
37663767
ext_actions.append("sw_fr")
37673768
ext_actions.append("sw_dc")
37683769
ext_actions.append("sw_pf")
@@ -3775,6 +3776,11 @@ def __process_recorded_actions(self):
37753776
ext_actions.append("d_a_c")
37763777
ext_actions.append("e_mfa")
37773778
ext_actions.append("ss_tl")
3779+
ext_actions.append("da_el")
3780+
ext_actions.append("da_ep")
3781+
ext_actions.append("da_te")
3782+
ext_actions.append("da_et")
3783+
ext_actions.append("pr_da")
37783784
for n in range(len(srt_actions)):
37793785
if srt_actions[n][0] in ext_actions:
37803786
origin = srt_actions[n][2]
@@ -4023,6 +4029,12 @@ def __process_recorded_actions(self):
40234029
elif action[0] == "sleep":
40244030
method = "sleep"
40254031
sb_actions.append("self.%s(%s)" % (method, action[1]))
4032+
elif action[0] == "wf_el":
4033+
method = "wait_for_element"
4034+
if '"' not in action[1]:
4035+
sb_actions.append('self.%s("%s")' % (method, action[1]))
4036+
else:
4037+
sb_actions.append("self.%s('%s')" % (method, action[1]))
40264038
elif action[0] == "as_el":
40274039
method = "assert_element"
40284040
if '"' not in action[1]:
@@ -4097,13 +4109,22 @@ def __process_recorded_actions(self):
40974109
'self.%s(\'%s\', "%s")'
40984110
% (method, action[1][0], action[1][1])
40994111
)
4100-
elif action[0] == "as_te" or action[0] == "as_et":
4112+
elif (
4113+
action[0] == "as_te"
4114+
or action[0] == "as_et"
4115+
or action[0] == "da_te"
4116+
or action[0] == "da_et"
4117+
):
41014118
import unicodedata
41024119

41034120
action[1][0] = unicodedata.normalize("NFKC", action[1][0])
41044121
method = "assert_text"
41054122
if action[0] == "as_et":
41064123
method = "assert_exact_text"
4124+
elif action[0] == "da_te":
4125+
method = "deferred_assert_text"
4126+
elif action[0] == "da_et":
4127+
method = "deferred_assert_exact_text"
41074128
if action[1][1] != "html":
41084129
if '"' not in action[1][0] and '"' not in action[1][1]:
41094130
sb_actions.append(
@@ -4134,12 +4155,26 @@ def __process_recorded_actions(self):
41344155
sb_actions.append(
41354156
"self.%s('%s')" % (method, action[1][0])
41364157
)
4158+
elif action[0] == "da_el":
4159+
method = "deferred_assert_element"
4160+
if '"' not in action[1]:
4161+
sb_actions.append('self.%s("%s")' % (method, action[1]))
4162+
else:
4163+
sb_actions.append("self.%s('%s')" % (method, action[1]))
4164+
elif action[0] == "da_ep":
4165+
method = "deferred_assert_element_present"
4166+
if '"' not in action[1]:
4167+
sb_actions.append('self.%s("%s")' % (method, action[1]))
4168+
else:
4169+
sb_actions.append("self.%s('%s')" % (method, action[1]))
41374170
elif action[0] == "ss_tl":
41384171
method = "save_screenshot_to_logs"
41394172
sb_actions.append("self.%s()" % method)
41404173
elif action[0] == "sh_fc":
41414174
method = "show_file_choosers"
41424175
sb_actions.append("self.%s()" % method)
4176+
elif action[0] == "pr_da":
4177+
sb_actions.append("self.process_deferred_asserts()")
41434178
elif action[0] == "c_l_s":
41444179
sb_actions.append("self.clear_local_storage()")
41454180
elif action[0] == "c_s_s":
@@ -9574,14 +9609,26 @@ def wait_for_element(self, selector, by="css selector", timeout=None):
95749609
timeout = settings.LARGE_TIMEOUT
95759610
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
95769611
timeout = self.__get_new_timeout(timeout)
9612+
original_selector = selector
95779613
selector, by = self.__recalculate_selector(selector, by)
9614+
if self.recorder_mode:
9615+
url = self.get_current_url()
9616+
if url and len(url) > 0:
9617+
if ("http:") in url or ("https:") in url or ("file:") in url:
9618+
if self.get_session_storage_item("pause_recorder") == "no":
9619+
if by == By.XPATH:
9620+
selector = original_selector
9621+
time_stamp = self.execute_script("return Date.now();")
9622+
origin = self.get_origin()
9623+
action = ["wf_el", selector, origin, time_stamp]
9624+
self.__extra_actions.append(action)
95789625
if self.__is_shadow_selector(selector):
95799626
return self.__wait_for_shadow_element_visible(selector, timeout)
95809627
return page_actions.wait_for_element_visible(
95819628
self.driver, selector, by, timeout
95829629
)
95839630

9584-
def get_element(self, selector, by=By.CSS_SELECTOR, timeout=None):
9631+
def get_element(self, selector, by="css selector", timeout=None):
95859632
"""Same as wait_for_element_present() - returns the element.
95869633
The element does not need be visible (it may be hidden)."""
95879634
self.__check_scope()
@@ -10919,6 +10966,15 @@ def deferred_assert_element(
1091910966
self.__last_url_of_deferred_assert = url
1092010967
except Exception:
1092110968
pass
10969+
if self.recorder_mode:
10970+
url = self.get_current_url()
10971+
if url and len(url) > 0:
10972+
if ("http:") in url or ("https:") in url or ("file:") in url:
10973+
if self.get_session_storage_item("pause_recorder") == "no":
10974+
time_stamp = self.execute_script("return Date.now();")
10975+
origin = self.get_origin()
10976+
action = ["da_el", selector, origin, time_stamp]
10977+
self.__extra_actions.append(action)
1092210978
try:
1092310979
self.wait_for_element_visible(selector, by=by, timeout=timeout)
1092410980
return True
@@ -10992,6 +11048,16 @@ def deferred_assert_text(
1099211048
self.__last_url_of_deferred_assert = url
1099311049
except Exception:
1099411050
pass
11051+
if self.recorder_mode:
11052+
url = self.get_current_url()
11053+
if url and len(url) > 0:
11054+
if ("http:") in url or ("https:") in url or ("file:") in url:
11055+
if self.get_session_storage_item("pause_recorder") == "no":
11056+
time_stamp = self.execute_script("return Date.now();")
11057+
origin = self.get_origin()
11058+
text_selector = [text, selector]
11059+
action = ["da_te", text_selector, origin, time_stamp]
11060+
self.__extra_actions.append(action)
1099511061
try:
1099611062
self.wait_for_text_visible(text, selector, by=by, timeout=timeout)
1099711063
return True
@@ -11024,6 +11090,16 @@ def deferred_assert_exact_text(
1102411090
self.__last_url_of_deferred_assert = url
1102511091
except Exception:
1102611092
pass
11093+
if self.recorder_mode:
11094+
url = self.get_current_url()
11095+
if url and len(url) > 0:
11096+
if ("http:") in url or ("https:") in url or ("file:") in url:
11097+
if self.get_session_storage_item("pause_recorder") == "no":
11098+
time_stamp = self.execute_script("return Date.now();")
11099+
origin = self.get_origin()
11100+
text_selector = [text, selector]
11101+
action = ["da_et", text_selector, origin, time_stamp]
11102+
self.__extra_actions.append(action)
1102711103
try:
1102811104
self.wait_for_exact_text_visible(
1102911105
text, selector, by=by, timeout=timeout
@@ -11076,6 +11152,11 @@ def process_deferred_asserts(self, print_only=False):
1107611152
the deferred asserts on a single html page so that the failure
1107711153
screenshot matches the location of the deferred asserts.
1107811154
If "print_only" is set to True, the exception won't get raised."""
11155+
if self.recorder_mode:
11156+
time_stamp = self.execute_script("return Date.now();")
11157+
origin = self.get_origin()
11158+
action = ["pr_da", "", origin, time_stamp]
11159+
self.__extra_actions.append(action)
1107911160
if self.__deferred_assert_failures:
1108011161
exception_output = ""
1108111162
exception_output += "\n***** DEFERRED ASSERTION FAILURES:\n"

0 commit comments

Comments
 (0)