Skip to content

Commit bbe7f3c

Browse files
committed
Fix issue with Recorder Mode and quotes in URLs
1 parent ddb2f4c commit bbe7f3c

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

seleniumbase/behave/behave_helper.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ def generate_gherkin(srt_actions):
1717
action[2] = unquote(action[2], errors="strict")
1818
except Exception:
1919
pass
20-
sb_actions.append('Open "%s"' % action[2])
20+
if '"' not in action[2]:
21+
sb_actions.append('Open "%s"' % action[2])
22+
elif "'" not in action[2]:
23+
sb_actions.append("Open '%s'" % action[2])
24+
else:
25+
sb_actions.append(
26+
'Open "%s"' % action[2].replace('"', '\\"')
27+
)
2128
elif action[0] == "f_url":
2229
if "%" in action[2] and python3:
2330
try:
@@ -26,7 +33,14 @@ def generate_gherkin(srt_actions):
2633
action[2] = unquote(action[2], errors="strict")
2734
except Exception:
2835
pass
29-
sb_actions.append('Open if not "%s"' % action[2])
36+
if '"' not in action[2]:
37+
sb_actions.append('Open if not "%s"' % action[2])
38+
elif "'" not in action[2]:
39+
sb_actions.append("Open if not '%s'" % action[2])
40+
else:
41+
sb_actions.append(
42+
'Open if not "%s"' % action[2].replace('"', '\\"')
43+
)
3044
elif action[0] == "click":
3145
if '"' not in action[1]:
3246
sb_actions.append('Click "%s"' % action[1])

seleniumbase/fixtures/base_case.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3898,7 +3898,14 @@ def __process_recorded_actions(self):
38983898
action[2] = unquote(action[2], errors="strict")
38993899
except Exception:
39003900
pass
3901-
sb_actions.append('self.open("%s")' % action[2])
3901+
if '"' not in action[2]:
3902+
sb_actions.append('self.open("%s")' % action[2])
3903+
elif "'" not in action[2]:
3904+
sb_actions.append("self.open('%s')" % action[2])
3905+
else:
3906+
sb_actions.append(
3907+
'self.open("%s")' % action[2].replace('"', '\\"')
3908+
)
39023909
elif action[0] == "f_url":
39033910
if "%" in action[2] and python3:
39043911
try:
@@ -3907,7 +3914,15 @@ def __process_recorded_actions(self):
39073914
action[2] = unquote(action[2], errors="strict")
39083915
except Exception:
39093916
pass
3910-
sb_actions.append('self.open_if_not_url("%s")' % action[2])
3917+
if '"' not in action[2]:
3918+
sb_actions.append('self.open_if_not_url("%s")' % action[2])
3919+
elif "'" not in action[2]:
3920+
sb_actions.append("self.open_if_not_url('%s')" % action[2])
3921+
else:
3922+
sb_actions.append(
3923+
'self.open_if_not_url("%s")'
3924+
% action[2].replace('"', '\\"')
3925+
)
39113926
elif action[0] == "click":
39123927
method = "click"
39133928
if '"' not in action[1]:

0 commit comments

Comments
 (0)