Skip to content

Commit 6fb5da4

Browse files
committed
Add a console script option to create a file for Recorder Mode
1 parent e17b16a commit 6fb5da4

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

seleniumbase/console_scripts/sb_mkfile.py

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
1212
Options:
1313
-b / --basic (Basic boilerplate / single-line test)
14+
-r / --recorder (Recorder Mode has ipdb breakpoint)
1415
1516
Language Options:
1617
--en / --English | --zh / --Chinese
@@ -39,27 +40,28 @@
3940
def invalid_run_command(msg=None):
4041
exp = " ** mkfile **\n\n"
4142
exp += " Usage:\n"
42-
exp += " seleniumbase mkfile [FILE.py] [OPTIONS]\n"
43-
exp += " OR sbase mkfile [FILE.py] [OPTIONS]\n"
43+
exp += " seleniumbase mkfile [FILE.py] [OPTIONS]\n"
44+
exp += " OR sbase mkfile [FILE.py] [OPTIONS]\n"
4445
exp += " Example:\n"
45-
exp += " sbase mkfile new_test.py\n"
46+
exp += " sbase mkfile new_test.py\n"
4647
exp += " Options:\n"
47-
exp += " -b / --basic (Basic boilerplate / single-line test)\n"
48+
exp += " -b / --basic (Basic boilerplate / single-line test)\n"
49+
exp += " -r / --recorder (Recorder Mode has ipdb breakpoint)\n"
4850
exp += " Language Options:\n"
49-
exp += " --en / --English | --zh / --Chinese\n"
50-
exp += " --nl / --Dutch | --fr / --French\n"
51-
exp += " --it / --Italian | --ja / --Japanese\n"
52-
exp += " --ko / --Korean | --pt / --Portuguese\n"
53-
exp += " --ru / --Russian | --es / --Spanish\n"
51+
exp += " --en / --English | --zh / --Chinese\n"
52+
exp += " --nl / --Dutch | --fr / --French\n"
53+
exp += " --it / --Italian | --ja / --Japanese\n"
54+
exp += " --ko / --Korean | --pt / --Portuguese\n"
55+
exp += " --ru / --Russian | --es / --Spanish\n"
5456
exp += " Output:\n"
55-
exp += " Creates a new SBase test file with boilerplate code.\n"
56-
exp += " If the file already exists, an error is raised.\n"
57-
exp += " By default, uses English mode and creates a\n"
58-
exp += " boilerplate with the 5 most common SeleniumBase\n"
59-
exp += ' methods, which are "open", "type", "click",\n'
60-
exp += ' "assert_element", and "assert_text". If using the\n'
61-
exp += ' basic boilerplate option, only the "open" method\n'
62-
exp += " is included.\n"
57+
exp += " Creates a new SBase test file with boilerplate code.\n"
58+
exp += " If the file already exists, an error is raised.\n"
59+
exp += " By default, uses English mode and creates a\n"
60+
exp += " boilerplate with the 5 most common SeleniumBase\n"
61+
exp += ' methods, which are "open", "type", "click",\n'
62+
exp += ' "assert_element", and "assert_text". If using the\n'
63+
exp += ' basic boilerplate option, only the "open" method\n'
64+
exp += " is included.\n"
6365
if not msg:
6466
raise Exception("INVALID RUN COMMAND!\n\n%s" % exp)
6567
elif msg == "help":
@@ -83,6 +85,7 @@ def main():
8385

8486
basic = False
8587
help_me = False
88+
recorder = False
8689
error_msg = None
8790
invalid_cmd = None
8891
language = "English"
@@ -113,6 +116,10 @@ def main():
113116
help_me = True
114117
elif option == "-b" or option == "--basic":
115118
basic = True
119+
elif option == "-r" or option == "--rec":
120+
recorder = True
121+
elif option == "--record" or option == "--recorder":
122+
recorder = True
116123
elif option == "--en" or option == "--english":
117124
language = "English"
118125
elif option == "--zh" or option == "--chinese":
@@ -155,8 +162,9 @@ def main():
155162
dir_name = os.getcwd()
156163
file_path = "%s/%s" % (dir_name, file_name)
157164

158-
body = "html > body"
159-
para = "body p"
165+
body = "body"
166+
para1 = "html body > p"
167+
para2 = "p"
160168
hello = "Hello"
161169
goodbye = "Goodbye"
162170
class_name = "MyTestClass"
@@ -200,9 +208,9 @@ def main():
200208
if basic:
201209
url = "about:blank"
202210
elif language not in ["English", "Dutch", "French", "Italian"]:
203-
url = "data:text/html,<meta charset='utf-8'><p>%s <input>" % hello
211+
url = "data:text/html,<meta charset='utf-8'><p>%s<br><input>" % hello
204212
else:
205-
url = "data:text/html,<p>%s<br><input></p>" % hello
213+
url = "data:text/html,<p>%s<br><input>" % hello
206214

207215
import_line = "from seleniumbase import BaseCase"
208216
parent_class = "BaseCase"
@@ -220,16 +228,20 @@ def main():
220228
data.append("")
221229
data.append("%s" % class_line)
222230
data.append(" def test_base(self):")
223-
data.append(' self.open("%s")' % url)
224-
if not basic:
231+
if not recorder:
232+
data.append(' self.open("%s")' % url)
233+
else:
234+
data.append(' if self.recorder_ext and not self.xvfb:')
235+
data.append(' import ipdb; ipdb.set_trace()')
236+
if not basic and not recorder:
225237
data.append(
226238
' self.type("input", "%s")' " # selector, text" % goodbye
227239
)
228-
data.append(' self.click("%s") # selector' % para)
240+
data.append(' self.click("%s") # selector' % para1)
229241
data.append(' self.assert_element("%s") # selector' % body)
230242
data.append(
231243
' self.assert_text("%s", "%s")'
232-
" # text, selector" % (hello, para)
244+
" # text, selector" % (hello, para2)
233245
)
234246
data.append("")
235247

@@ -271,6 +283,7 @@ def main():
271283
file = codecs.open(file_path, "w+", "utf-8")
272284
file.writelines("\r\n".join(data))
273285
file.close()
286+
os.system("sbase print %s -n" % file_name)
274287
success = (
275288
"\n" + c1 + '* Test file: "' + file_name + '" was created! *'
276289
"" + cr + "\n"

0 commit comments

Comments
 (0)