Skip to content

Commit aedf06e

Browse files
committed
Add "--url=URL" & "--edge" as options to "mkrec" / "codegen"
1 parent c2df7f4 commit aedf06e

File tree

2 files changed

+56
-16
lines changed

2 files changed

+56
-16
lines changed

seleniumbase/console_scripts/run.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
sbase options
1212
sbase mkdir ui_tests
1313
sbase mkfile new_test.py
14-
sbase mkrec new_test.py # Same as "sbase codegen new_test.py"
14+
sbase mkrec new_test.py
15+
sbase mkrec new_test.py --url=wikipedia.org
16+
sbase codegen new_test.py --url=wikipedia.org
1517
sbase mkpres new_presentation.py
1618
sbase mkchart new_chart.py
1719
sbase convert webdriver_unittest_file.py
@@ -75,7 +77,7 @@ def show_basic_usage():
7577
sc += " options (List common pytest options)\n"
7678
sc += " mkdir [DIRECTORY] [OPTIONS]\n"
7779
sc += " mkfile [FILE.py] [OPTIONS]\n"
78-
sc += " mkrec / codegen [FILE.py]\n"
80+
sc += " mkrec / codegen [FILE.py] [OPTIONS]\n"
7981
sc += " mkpres [FILE.py] [LANG]\n"
8082
sc += " mkchart [FILE.py] [LANG]\n"
8183
sc += " print [FILE] [OPTIONS]\n"
@@ -203,10 +205,14 @@ def show_mkrec_usage():
203205
print(sc)
204206
print("")
205207
print(" Usage:")
206-
print(" seleniumbase mkrec [FILE.py]")
207-
print(" OR: sbase mkrec [FILE.py]")
208-
print(" Example:")
208+
print(" seleniumbase mkrec [FILE.py] [OPTIONS]")
209+
print(" OR: sbase mkrec [FILE.py] [OPTIONS]")
210+
print(" Examples:")
209211
print(" sbase mkrec new_test.py")
212+
print(" sbase mkrec new_test.py --url=wikipedia.org")
213+
print(" Options:")
214+
print(" --url=URL (Sets the initial start page URL.)")
215+
print(" --edge (Use Edge browser instead of Chrome.)")
210216
print(" Output:")
211217
print(" Creates a new SeleniumBase test using the Recorder.")
212218
print(" If the filename already exists, an error is raised.")
@@ -221,10 +227,14 @@ def show_codegen_usage():
221227
print(sc)
222228
print("")
223229
print(" Usage:")
224-
print(" seleniumbase codegen [FILE.py]")
225-
print(" OR: sbase codegen [FILE.py]")
226-
print(" Example:")
230+
print(" seleniumbase codegen [FILE.py] [OPTIONS]")
231+
print(" OR: sbase codegen [FILE.py] [OPTIONS]")
232+
print(" Examples:")
227233
print(" sbase codegen new_test.py")
234+
print(" sbase codegen new_test.py --url=wikipedia.org")
235+
print(" Options:")
236+
print(" --url=URL (Sets the initial start page URL.)")
237+
print(" --edge (Use Edge browser instead of Chrome.)")
228238
print(" Output:")
229239
print(" Creates a new SeleniumBase test using the Recorder.")
230240
print(" If the filename already exists, an error is raised.")

seleniumbase/console_scripts/sb_mkrec.py

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
Creates a new SeleniumBase test file using the Recorder.
44
55
Usage:
6-
seleniumbase mkrec [FILE.py]
7-
sbase mkrec [FILE.py]
8-
seleniumbase codegen [FILE.py]
9-
sbase codegen [FILE.py]
6+
seleniumbase mkrec [FILE.py] [OPTIONS]
7+
sbase mkrec [FILE.py] [OPTIONS]
8+
seleniumbase codegen [FILE.py] [OPTIONS]
9+
sbase codegen [FILE.py] [OPTIONS]
1010
1111
Examples:
1212
sbase mkrec new_test.py
13+
sbase mkrec new_test.py --url=seleniumbase.io
1314
sbase codegen new_test.py
15+
sbase codegen new_test.py --url=wikipedia.org
16+
17+
Options:
18+
--url=URL (Sets the initial start page URL.)
19+
--edge (Use Edge browser instead of Chrome.)
1420
1521
Output:
1622
Creates a new SeleniumBase test using the Recorder.
@@ -34,6 +40,9 @@ def invalid_run_command(msg=None):
3440
exp += " Examples:\n"
3541
exp += " sbase mkrec new_test.py\n"
3642
exp += " sbase codegen new_test.py\n"
43+
exp += " Options:\n"
44+
exp += " --url=URL (Sets the initial start page URL.)\n"
45+
exp += " --edge (Use Edge browser instead of Chrome.)\n"
3746
exp += " Output:\n"
3847
exp += " Creates a new SeleniumBase test using the Recorder.\n"
3948
exp += " If the filename already exists, an error is raised.\n"
@@ -65,6 +74,9 @@ def main():
6574
help_me = False
6675
error_msg = None
6776
invalid_cmd = None
77+
use_edge = False
78+
start_page = None
79+
next_is_url = False
6880

6981
command_args = sys.argv[2:]
7082
file_name = command_args[0]
@@ -87,9 +99,17 @@ def main():
8799
if len(command_args) >= 2:
88100
options = command_args[1:]
89101
for option in options:
90-
option = option.lower()
91-
if option == "-h" or option == "--help":
102+
if option.lower() == "-h" or option.lower() == "--help":
92103
help_me = True
104+
elif option.lower() == "--edge":
105+
use_edge = True
106+
elif option.lower().startswith("--url="):
107+
start_page = option[len("--url="):]
108+
elif option.lower() == "--url":
109+
next_is_url = True
110+
elif next_is_url:
111+
start_page = option
112+
next_is_url = False
93113
else:
94114
invalid_cmd = "\n===> INVALID OPTION: >> %s <<\n" % option
95115
invalid_cmd = invalid_cmd.replace(">> ", ">>" + c5 + " ")
@@ -121,8 +141,18 @@ def main():
121141
"" + c1 + file_name + "" + cr + "\n"
122142
)
123143
print(success)
124-
print("pytest %s --rec -q -s" % file_name)
125-
os.system("pytest %s --rec -q -s" % file_name)
144+
if not start_page:
145+
run_cmd = "pytest %s --rec -q -s" % file_name
146+
if use_edge:
147+
run_cmd += " --edge"
148+
print(run_cmd)
149+
os.system(run_cmd)
150+
else:
151+
run_cmd = "pytest %s --rec -q -s --url=%s" % (file_name, start_page)
152+
if use_edge:
153+
run_cmd += " --edge"
154+
print(run_cmd)
155+
os.system(run_cmd)
126156
if os.path.exists(file_path):
127157
os.remove(file_path)
128158
recorded_filename = file_name[:-3] + "_rec.py"

0 commit comments

Comments
 (0)