Skip to content

Commit fa15dcc

Browse files
committed
Upgrade Recorder Mode
1 parent 63fdb24 commit fa15dcc

File tree

3 files changed

+146
-42
lines changed

3 files changed

+146
-42
lines changed

seleniumbase/extensions/recorder.zip

358 Bytes
Binary file not shown.

seleniumbase/fixtures/base_case.py

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def __init__(self, *args, **kwargs):
9696
self.__last_page_url = None
9797
self.__last_page_source = None
9898
self.__skip_reason = None
99+
self.__dont_record_js_click = False
99100
self.__overrided_default_timeouts = False
100101
self.__added_pytest_html_extra = None
101102
self.__deferred_assert_count = 0
@@ -1659,7 +1660,9 @@ def check_if_unchecked(self, selector, by=By.CSS_SELECTOR):
16591660
self.click(selector, by=by)
16601661
else:
16611662
selector = self.convert_to_css_selector(selector, by=by)
1663+
self.__dont_record_js_click = True
16621664
self.js_click(selector, by=By.CSS_SELECTOR)
1665+
self.__dont_record_js_click = False
16631666

16641667
def select_if_unselected(self, selector, by=By.CSS_SELECTOR):
16651668
""" Same as check_if_unchecked() """
@@ -1674,7 +1677,9 @@ def uncheck_if_checked(self, selector, by=By.CSS_SELECTOR):
16741677
self.click(selector, by=by)
16751678
else:
16761679
selector = self.convert_to_css_selector(selector, by=by)
1680+
self.__dont_record_js_click = True
16771681
self.js_click(selector, by=By.CSS_SELECTOR)
1682+
self.__dont_record_js_click = False
16781683

16791684
def unselect_if_selected(self, selector, by=By.CSS_SELECTOR):
16801685
""" Same as uncheck_if_checked() """
@@ -1860,7 +1865,9 @@ def hover_and_click(
18601865
self.__get_href_from_partial_link_text(click_selector)
18611866
)
18621867
else:
1868+
self.__dont_record_js_click = True
18631869
self.js_click(click_selector, by=click_by)
1870+
self.__dont_record_js_click = False
18641871
if outdated_driver:
18651872
pass # Already did the click workaround
18661873
elif self.mobile_emulator:
@@ -1943,7 +1950,9 @@ def hover_and_double_click(
19431950
self.__get_href_from_partial_link_text(click_selector)
19441951
)
19451952
else:
1953+
self.__dont_record_js_click = True
19461954
self.js_click(click_selector, click_by)
1955+
self.__dont_record_js_click = False
19471956
if not outdated_driver:
19481957
element = page_actions.hover_element_and_double_click(
19491958
self.driver,
@@ -3214,15 +3223,23 @@ def __process_recorded_actions(self):
32143223
and (
32153224
srt_actions[n-1][0] == "click"
32163225
or srt_actions[n-1][0] == "js_cl"
3226+
or srt_actions[n-1][0] == "js_ca"
32173227
)
32183228
):
32193229
url1 = srt_actions[n-1][2]
3220-
if srt_actions[n-1][0] == "js_cl":
3230+
if (
3231+
srt_actions[n-1][0] == "js_cl"
3232+
or srt_actions[n-1][0] == "js_ca"
3233+
):
32213234
url1 = srt_actions[n-1][2][0]
3222-
if url1.endswith("/"):
3235+
if url1.endswith("/#/"):
3236+
url1 = url1[:-3]
3237+
elif url1.endswith("/"):
32233238
url1 = url1[:-1]
32243239
url2 = srt_actions[n][2]
3225-
if url2.endswith("/"):
3240+
if url2.endswith("/#/"):
3241+
url2 = url1[:-3]
3242+
elif url2.endswith("/"):
32263243
url2 = url2[:-1]
32273244
if url1 == url2:
32283245
srt_actions[n][0] = "f_url"
@@ -3236,10 +3253,14 @@ def __process_recorded_actions(self):
32363253
)
32373254
):
32383255
url1 = srt_actions[n-1][2]
3239-
if url1.endswith("/"):
3256+
if url1.endswith("/#/"):
3257+
url1 = url1[:-3]
3258+
elif url1.endswith("/"):
32403259
url1 = url1[:-1]
32413260
url2 = srt_actions[n][2]
3242-
if url2.endswith("/"):
3261+
if url2.endswith("/#/"):
3262+
url2 = url1[:-3]
3263+
elif url2.endswith("/"):
32433264
url2 = url2[:-1]
32443265
if url1 == url2:
32453266
srt_actions[n-1][0] = "_skip"
@@ -3250,13 +3271,15 @@ def __process_recorded_actions(self):
32503271
and (
32513272
srt_actions[n-1][0] == "click"
32523273
or srt_actions[n-1][0] == "js_cl"
3274+
or srt_actions[n-1][0] == "js_ca"
32533275
or srt_actions[n-1][0] == "input"
32543276
)
32553277
and (int(srt_actions[n][3]) - int(srt_actions[n-1][3]) < 6500)
32563278
):
32573279
if (
32583280
srt_actions[n-1][0] == "click"
32593281
or srt_actions[n-1][0] == "js_cl"
3282+
or srt_actions[n-1][0] == "js_ca"
32603283
):
32613284
if (
32623285
srt_actions[n-1][1].startswith("input")
@@ -3311,6 +3334,7 @@ def __process_recorded_actions(self):
33113334
srt_actions[n-1][0] = "_skip"
33123335
ext_actions = []
33133336
ext_actions.append("js_cl")
3337+
ext_actions.append("js_ca")
33143338
ext_actions.append("as_el")
33153339
ext_actions.append("as_ep")
33163340
ext_actions.append("asenv")
@@ -3325,10 +3349,14 @@ def __process_recorded_actions(self):
33253349
ext_actions.append("s_c_f")
33263350
ext_actions.append("s_c_d")
33273351
ext_actions.append("sh_fc")
3352+
ext_actions.append("c_l_s")
33283353
for n in range(len(srt_actions)):
33293354
if srt_actions[n][0] in ext_actions:
33303355
origin = srt_actions[n][2]
3331-
if srt_actions[n][0] == "js_cl":
3356+
if (
3357+
srt_actions[n][0] == "js_cl"
3358+
or srt_actions[n][0] == "js_ca"
3359+
):
33323360
origin = srt_actions[n][2][1]
33333361
if origin.endswith("/"):
33343362
origin = origin[0:-1]
@@ -3353,6 +3381,12 @@ def __process_recorded_actions(self):
33533381
sb_actions.append('self.%s("%s")' % (method, action[1]))
33543382
else:
33553383
sb_actions.append("self.%s('%s')" % (method, action[1]))
3384+
elif action[0] == "js_ca":
3385+
method = "js_click_all"
3386+
if '"' not in action[1]:
3387+
sb_actions.append('self.%s("%s")' % (method, action[1]))
3388+
else:
3389+
sb_actions.append("self.%s('%s')" % (method, action[1]))
33563390
elif action[0] == "input":
33573391
method = "type"
33583392
text = action[2].replace("\n", "\\n")
@@ -3537,6 +3571,8 @@ def __process_recorded_actions(self):
35373571
elif action[0] == "sh_fc":
35383572
cb_method = "show_file_choosers"
35393573
sb_actions.append('self.%s()' % cb_method)
3574+
elif action[0] == "c_l_s":
3575+
sb_actions.append("self.clear_local_storage()")
35403576
elif action[0] == "c_box":
35413577
cb_method = "check_if_unchecked"
35423578
if action[2] == "no":
@@ -3963,7 +3999,7 @@ def js_click(
39633999
action = None
39644000
pre_action_url = self.driver.current_url
39654001
pre_window_count = len(self.driver.window_handles)
3966-
if self.recorder_mode:
4002+
if self.recorder_mode and not self.__dont_record_js_click:
39674003
time_stamp = self.execute_script("return Date.now();")
39684004
tag_name = None
39694005
href = ""
@@ -3979,6 +4015,8 @@ def js_click(
39794015
origin = self.get_origin()
39804016
href_origin = [href, origin]
39814017
action = ["js_cl", selector, href_origin, time_stamp]
4018+
if all_matches:
4019+
action[0] = "js_ca"
39824020
if not all_matches:
39834021
if ":contains\\(" not in css_selector:
39844022
self.__js_click(selector, by=by)
@@ -5786,6 +5824,11 @@ def remove_local_storage_item(self, key):
57865824
def clear_local_storage(self):
57875825
self.__check_scope()
57885826
self.execute_script("window.localStorage.clear();")
5827+
if self.recorder_mode:
5828+
time_stamp = self.execute_script("return Date.now();")
5829+
origin = self.get_origin()
5830+
action = ["c_l_s", "", origin, time_stamp]
5831+
self.__extra_actions.append(action)
57895832

57905833
def get_local_storage_keys(self):
57915834
self.__check_scope()

0 commit comments

Comments
 (0)