Skip to content

Commit 8ea4351

Browse files
committed
Make improvements to Recorder Mode
1 parent d32c6cd commit 8ea4351

File tree

2 files changed

+44
-12
lines changed

2 files changed

+44
-12
lines changed

seleniumbase/behave/behave_helper.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ def generate_gherkin(srt_actions):
7070
if action[0] == "js_ty":
7171
method = "js_type"
7272
text = action[2].replace("\n", "\\n")
73-
if '"' not in action[1] and '"' not in text:
74-
sb_actions.append('Into "%s" type "%s"' % (action[1], text))
75-
elif '"' not in action[1] and '"' in text:
76-
sb_actions.append('Into "%s" type \'%s\'' % (action[1], text))
77-
elif '"' in action[1] and '"' not in text:
78-
sb_actions.append('Into \'%s\' type "%s"' % (action[1], text))
79-
elif '"' in action[1] and '"' in text:
80-
sb_actions.append("Into '%s' type '%s'" % (action[1], text))
73+
if '"' not in text and '"' not in action[1]:
74+
sb_actions.append('Type "%s" into "%s"' % (text, action[1]))
75+
elif '"' in text and '"' not in action[1]:
76+
sb_actions.append('Type \'%s\' into "%s"' % (text, action[1]))
77+
elif '"' not in text and '"' in action[1]:
78+
sb_actions.append('Type "%s" into \'%s\'' % (text, action[1]))
79+
elif '"' in text and '"' in action[1]:
80+
sb_actions.append("Type '%s' into '%s'" % (text, action[1]))
8181
elif action[0] == "hover":
8282
if '"' not in action[1]:
8383
sb_actions.append('Hover "%s"' % action[1])
@@ -310,6 +310,7 @@ def generate_gherkin(srt_actions):
310310
action[0] == "as_te"
311311
or action[0] == "as_et"
312312
or action[0] == "astnv"
313+
or action[0] == "aetnv"
313314
or action[0] == "da_te"
314315
or action[0] == "da_et"
315316
):
@@ -322,6 +323,8 @@ def generate_gherkin(srt_actions):
322323
method = "Assert exact text"
323324
elif action[0] == "astnv":
324325
method = "Assert text not visible"
326+
elif action[0] == "aetnv":
327+
method = "Assert exact text not visible"
325328
elif action[0] == "da_te":
326329
method = "Deferred assert text"
327330
elif action[0] == "da_et":
@@ -370,6 +373,10 @@ def generate_gherkin(srt_actions):
370373
sb_actions.append("Show file choosers")
371374
elif action[0] == "pr_da":
372375
sb_actions.append("Process deferred asserts")
376+
elif action[0] == "a_d_m":
377+
sb_actions.append("Activate Demo Mode")
378+
elif action[0] == "d_d_m":
379+
sb_actions.append("Deactivate Demo Mode")
373380
elif action[0] == "c_l_s":
374381
sb_actions.append("Clear Local Storage")
375382
elif action[0] == "c_s_s":

seleniumbase/fixtures/base_case.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,8 @@ def get_locale_code(self):
11381138

11391139
def go_back(self):
11401140
self.__check_scope()
1141+
if hasattr(self, "recorder_mode") and self.recorder_mode:
1142+
self.save_recorded_actions()
11411143
pre_action_url = self.driver.current_url
11421144
self.__last_page_load_url = None
11431145
self.driver.back()
@@ -1156,6 +1158,8 @@ def go_back(self):
11561158

11571159
def go_forward(self):
11581160
self.__check_scope()
1161+
if hasattr(self, "recorder_mode") and self.recorder_mode:
1162+
self.save_recorded_actions()
11591163
self.__last_page_load_url = None
11601164
self.driver.forward()
11611165
if self.recorder_mode:
@@ -3995,9 +3999,19 @@ def activate_jquery(self):
39953999

39964000
def activate_demo_mode(self):
39974001
self.demo_mode = True
4002+
if self.recorder_mode:
4003+
time_stamp = self.execute_script("return Date.now();")
4004+
origin = self.get_origin()
4005+
action = ["a_d_m", "", origin, time_stamp]
4006+
self.__extra_actions.append(action)
39984007

39994008
def deactivate_demo_mode(self):
40004009
self.demo_mode = False
4010+
if self.recorder_mode:
4011+
time_stamp = self.execute_script("return Date.now();")
4012+
origin = self.get_origin()
4013+
action = ["d_d_m", "", origin, time_stamp]
4014+
self.__extra_actions.append(action)
40014015

40024016
def activate_design_mode(self):
40034017
# Activate Chrome's Design Mode, which lets you edit a site directly.
@@ -4052,6 +4066,8 @@ def save_recorded_actions(self):
40524066
end of the test. This is only needed in special cases because most
40534067
actions that result in a new origin, (such as clicking on a link),
40544068
should automatically open a new tab while Recorder Mode is enabled."""
4069+
if self.driver is None:
4070+
return
40554071
url = self.get_current_url()
40564072
if url and len(url) > 0:
40574073
if ("http:") in url or ("https:") in url or ("file:") in url:
@@ -4087,6 +4103,8 @@ def __get_recorded_actions_on_active_tab(self):
40874103
return []
40884104

40894105
def __process_recorded_actions(self):
4106+
if self.driver is None:
4107+
return
40904108
import colorama
40914109

40924110
raw_actions = [] # All raw actions from sessionStorage
@@ -4351,6 +4369,8 @@ def __process_recorded_actions(self):
43514369
ext_actions.append("hover")
43524370
ext_actions.append("sleep")
43534371
ext_actions.append("sh_fc")
4372+
ext_actions.append("a_d_m")
4373+
ext_actions.append("d_d_m")
43544374
ext_actions.append("c_l_s")
43554375
ext_actions.append("c_s_s")
43564376
ext_actions.append("d_a_c")
@@ -4813,6 +4833,10 @@ def __process_recorded_actions(self):
48134833
sb_actions.append("self.%s()" % method)
48144834
elif action[0] == "pr_da":
48154835
sb_actions.append("self.process_deferred_asserts()")
4836+
elif action[0] == "a_d_m":
4837+
sb_actions.append("self.activate_demo_mode()")
4838+
elif action[0] == "d_d_m":
4839+
sb_actions.append("self.deactivate_demo_mode()")
48164840
elif action[0] == "c_l_s":
48174841
sb_actions.append("self.clear_local_storage()")
48184842
elif action[0] == "c_s_s":
@@ -5260,8 +5284,6 @@ def highlight(self, selector, by="css selector", loops=None, scroll=True):
52605284
box_end = style.find(";", box_start) + 1
52615285
original_box_shadow = style[box_start:box_end]
52625286
o_bs = original_box_shadow
5263-
5264-
orig_selector = selector
52655287
if ":contains" not in selector and ":first" not in selector:
52665288
selector = re.escape(selector)
52675289
selector = self.__escape_quotes_if_needed(selector)
@@ -5281,9 +5303,8 @@ def highlight(self, selector, by="css selector", loops=None, scroll=True):
52815303
if self.get_session_storage_item("pause_recorder") == "no":
52825304
time_stamp = self.execute_script("return Date.now();")
52835305
origin = self.get_origin()
5284-
action = ["hi_li", orig_selector, origin, time_stamp]
5306+
action = ["hi_li", selector, origin, time_stamp]
52855307
self.__extra_actions.append(action)
5286-
time.sleep(0.065)
52875308

52885309
def press_up_arrow(self, selector="html", times=1, by="css selector"):
52895310
"""Simulates pressing the UP Arrow on the keyboard.
@@ -14592,6 +14613,10 @@ def tearDown(self):
1459214613
return
1459314614
if hasattr(self, "recorder_mode") and self.recorder_mode:
1459414615
self.__process_recorded_actions()
14616+
try:
14617+
self.remove_session_storage_item("recorded_actions")
14618+
except Exception:
14619+
pass
1459514620
self.__called_teardown = True
1459614621
self.__called_setup = False
1459714622
try:

0 commit comments

Comments
 (0)