Skip to content

Commit 0288f5e

Browse files
committed
Upgrade the SeleniumBase Recorder and Test Generator
1 parent 2175de7 commit 0288f5e

File tree

7 files changed

+1774
-942
lines changed

7 files changed

+1774
-942
lines changed

seleniumbase/behave/behave_helper.py

Lines changed: 114 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ def generate_gherkin(srt_actions):
3939
sb_actions.append('Click "%s"' % action[1])
4040
else:
4141
sb_actions.append("Click '%s'" % action[1])
42+
elif action[0] == "dbclk":
43+
if '"' not in action[1]:
44+
sb_actions.append('Double click "%s"' % action[1])
45+
else:
46+
sb_actions.append("Double click '%s'" % action[1])
4247
elif action[0] == "js_cl":
4348
if '"' not in action[1]:
4449
sb_actions.append('JS click "%s"' % action[1])
@@ -49,6 +54,16 @@ def generate_gherkin(srt_actions):
4954
sb_actions.append('JS click all "%s"' % action[1])
5055
else:
5156
sb_actions.append("JS click all '%s'" % action[1])
57+
elif action[0] == "jq_cl":
58+
if '"' not in action[1]:
59+
sb_actions.append('jQuery click "%s"' % action[1])
60+
else:
61+
sb_actions.append("jQuery click '%s'" % action[1])
62+
elif action[0] == "jq_ca":
63+
if '"' not in action[1]:
64+
sb_actions.append('jQuery click all "%s"' % action[1])
65+
else:
66+
sb_actions.append("jQuery click all '%s'" % action[1])
5267
elif action[0] == "r_clk":
5368
if '"' not in action[1]:
5469
sb_actions.append('Context click "%s"' % action[1])
@@ -66,9 +81,7 @@ def generate_gherkin(srt_actions):
6681
sb_actions.append(
6782
"Click '%s' at (%s, %s)" % (selector, p_x, p_y)
6883
)
69-
elif action[0] == "input" or action[0] == "js_ty":
70-
if action[0] == "js_ty":
71-
method = "js_type"
84+
elif action[0] == "input":
7285
text = action[2].replace("\n", "\\n")
7386
if '"' not in text and '"' not in action[1]:
7487
sb_actions.append('Type "%s" into "%s"' % (text, action[1]))
@@ -78,6 +91,34 @@ def generate_gherkin(srt_actions):
7891
sb_actions.append('Type "%s" into \'%s\'' % (text, action[1]))
7992
elif '"' in text and '"' in action[1]:
8093
sb_actions.append("Type '%s' into '%s'" % (text, action[1]))
94+
elif action[0] == "js_ty":
95+
text = action[2].replace("\n", "\\n")
96+
if '"' not in text and '"' not in action[1]:
97+
sb_actions.append('JS type "%s" in "%s"' % (text, action[1]))
98+
elif '"' in text and '"' not in action[1]:
99+
sb_actions.append('JS type \'%s\' in "%s"' % (text, action[1]))
100+
elif '"' not in text and '"' in action[1]:
101+
sb_actions.append('JS type "%s" in \'%s\'' % (text, action[1]))
102+
elif '"' in text and '"' in action[1]:
103+
sb_actions.append("JS type '%s' in '%s'" % (text, action[1]))
104+
elif action[0] == "jq_ty":
105+
text = action[2].replace("\n", "\\n")
106+
if '"' not in text and '"' not in action[1]:
107+
sb_actions.append(
108+
'jQuery type "%s" in "%s"' % (text, action[1])
109+
)
110+
elif '"' in text and '"' not in action[1]:
111+
sb_actions.append(
112+
'jQuery type \'%s\' in "%s"' % (text, action[1])
113+
)
114+
elif '"' not in text and '"' in action[1]:
115+
sb_actions.append(
116+
'jQuery type "%s" in \'%s\'' % (text, action[1])
117+
)
118+
elif '"' in text and '"' in action[1]:
119+
sb_actions.append(
120+
"jQuery type '%s' in '%s'" % (text, action[1])
121+
)
81122
elif action[0] == "hover":
82123
if '"' not in action[1]:
83124
sb_actions.append('Hover "%s"' % action[1])
@@ -211,26 +252,64 @@ def generate_gherkin(srt_actions):
211252
method = "Wait for element"
212253
if '"' not in action[1]:
213254
sb_actions.append('%s "%s"' % (method, action[1]))
214-
else:
255+
elif "'" not in action[1]:
215256
sb_actions.append("%s '%s'" % (method, action[1]))
257+
else:
258+
sb_actions.append(
259+
"%s '%s'" % (method, action[1].replace("'", "\\'"))
260+
)
216261
elif action[0] == "as_el":
217262
method = "Assert element"
218263
if '"' not in action[1]:
219264
sb_actions.append('%s "%s"' % (method, action[1]))
220-
else:
265+
elif "'" not in action[1]:
221266
sb_actions.append("%s '%s'" % (method, action[1]))
267+
else:
268+
sb_actions.append(
269+
"%s '%s'" % (method, action[1].replace("'", "\\'"))
270+
)
222271
elif action[0] == "as_ep":
223272
method = "Assert element present"
224273
if '"' not in action[1]:
225274
sb_actions.append('%s "%s"' % (method, action[1]))
226-
else:
275+
elif "'" not in action[1]:
227276
sb_actions.append("%s '%s'" % (method, action[1]))
277+
else:
278+
sb_actions.append(
279+
"%s '%s'" % (method, action[1].replace("'", "\\'"))
280+
)
228281
elif action[0] == "asenv":
229282
method = "Assert element not visible"
230283
if '"' not in action[1]:
231284
sb_actions.append('%s "%s"' % (method, action[1]))
232-
else:
285+
elif "'" not in action[1]:
233286
sb_actions.append("%s '%s'" % (method, action[1]))
287+
else:
288+
sb_actions.append(
289+
"%s '%s'" % (method, action[1].replace("'", "\\'"))
290+
)
291+
elif action[0] == "s_at_" or action[0] == "s_ats":
292+
start = "Find"
293+
if action[0] == "s_ats":
294+
start = "Find all"
295+
if '"' not in action[1][0]:
296+
sb_actions.append(
297+
'%s "%s" and set %s to "%s"'
298+
% (start, action[1][0], action[1][1], action[1][2])
299+
)
300+
elif "'" not in action[1][0]:
301+
sb_actions.append(
302+
"%s '%s' and set %s to \"%s\""
303+
% (start, action[1][0], action[1][1], action[1][2])
304+
)
305+
else:
306+
sb_actions.append(
307+
'%s "%s" and set %s to "%s")'
308+
% (
309+
start.replace('"', '\\"'),
310+
action[1][0], action[1][1], action[1][2]
311+
)
312+
)
234313
elif action[0] == "acc_a":
235314
sb_actions.append("Accept alert")
236315
elif action[0] == "dis_a":
@@ -318,6 +397,7 @@ def generate_gherkin(srt_actions):
318397

319398
action[1][0] = unicodedata.normalize("NFKC", action[1][0])
320399
action[1][0] = action[1][0].replace("\n", "\\n")
400+
action[1][0] = action[1][0].replace("\u00B6", "")
321401
method = "Assert text"
322402
if action[0] == "as_et":
323403
method = "Assert exact text"
@@ -367,6 +447,33 @@ def generate_gherkin(srt_actions):
367447
sb_actions.append('%s "%s"' % (method, action[1]))
368448
else:
369449
sb_actions.append("%s '%s'" % (method, action[1]))
450+
elif action[0] == "s_scr":
451+
method = "Save screenshot as"
452+
if '"' not in action[1]:
453+
sb_actions.append('%s "%s"' % (method, action[1]))
454+
else:
455+
sb_actions.append("%s '%s'" % (method, action[1]))
456+
elif action[0] == "ss_tf":
457+
if '"' not in action[2] and '"' not in action[1]:
458+
sb_actions.append(
459+
'Save screenshot to "%s" as "%s"'
460+
% (action[2], action[1])
461+
)
462+
elif '"' not in action[2] and '"' in action[1]:
463+
sb_actions.append(
464+
'Save screenshot to "%s" as \'%s\''
465+
% (action[2], action[1])
466+
)
467+
elif '"' in action[2] and '"' not in action[1]:
468+
sb_actions.append(
469+
'Save screenshot to \'%s\' as "%s"'
470+
% (action[2], action[1])
471+
)
472+
elif '"' in action[2] and '"' in action[1]:
473+
sb_actions.append(
474+
"Save screenshot to '%s' as '%s'"
475+
% (action[2], action[1])
476+
)
370477
elif action[0] == "ss_tl":
371478
sb_actions.append("Save screenshot to logs")
372479
elif action[0] == "sh_fc":

0 commit comments

Comments
 (0)