22
22
--url=URL (Sets the initial start page URL.)
23
23
--edge (Use Edge browser instead of Chrome.)
24
24
--gui / --headed (Use headed mode on Linux.)
25
+ --overwrite (Overwrite file when it exists.)
25
26
26
27
Output:
27
28
Creates a new SeleniumBase test using the Recorder.
36
37
37
38
38
39
def invalid_run_command (msg = None ):
39
- exp = " ** mkrec / codegen **\n \n "
40
+ exp = " ** mkrec / record / codegen **\n \n "
40
41
exp += " Usage:\n "
41
42
exp += " seleniumbase mkrec [FILE.py]\n "
42
- exp += " sbase mkrec [FILE.py]\n "
43
- exp += " seleniumbase codegen [FILE.py]\n "
44
- exp += " sbase codegen [FILE.py]\n "
43
+ exp += " OR: sbase mkrec [FILE.py]\n "
45
44
exp += " Examples:\n "
46
45
exp += " sbase mkrec new_test.py\n "
47
- exp += " sbase codegen new_test.py\n "
46
+ exp += " sbase mkrec new_test.py --url=wikipedia.org \n "
48
47
exp += " Options:\n "
49
48
exp += " --url=URL (Sets the initial start page URL.)\n "
50
49
exp += " --edge (Use Edge browser instead of Chrome.)\n "
51
50
exp += " --gui / --headed (Use headed mode on Linux.)\n "
51
+ exp += " --overwrite (Overwrite file when it exists.)\n "
52
52
exp += " Output:\n "
53
53
exp += " Creates a new SeleniumBase test using the Recorder.\n "
54
54
exp += " If the filename already exists, an error is raised.\n "
@@ -108,12 +108,23 @@ def main():
108
108
error_msg = "File must be created in the current directory!"
109
109
elif file_name == "abc.py" :
110
110
error_msg = '"abc.py" is a reserved Python module! Use another name!'
111
- elif os .path .exists (os .getcwd () + "/" + file_name ):
112
- error_msg = 'File "%s" already exists in this directory!' % file_name
113
111
if error_msg :
114
112
error_msg = c5 + "ERROR: " + error_msg + cr
115
113
invalid_run_command (error_msg )
116
114
115
+ dir_name = os .getcwd ()
116
+ file_path = os .path .join (dir_name , file_name )
117
+
118
+ if (
119
+ "--overwrite" in ' ' .join (command_args ).lower ()
120
+ and os .path .exists (file_path )
121
+ ):
122
+ os .remove (file_path )
123
+ if os .path .exists (file_path ):
124
+ error_msg = 'File "%s" already exists in this directory!' % file_name
125
+ error_msg = c5 + "ERROR: " + error_msg + cr
126
+ invalid_run_command (error_msg )
127
+
117
128
if len (command_args ) >= 2 :
118
129
options = command_args [1 :]
119
130
for option in options :
@@ -133,6 +144,8 @@ def main():
133
144
elif next_is_url :
134
145
start_page = option
135
146
next_is_url = False
147
+ elif option .lower () == "--overwrite" :
148
+ pass # Already handled if file existed
136
149
else :
137
150
invalid_cmd = "\n ===> INVALID OPTION: >> %s <<\n " % option
138
151
invalid_cmd = invalid_cmd .replace (">> " , ">>" + c5 + " " )
@@ -144,9 +157,6 @@ def main():
144
157
if help_me :
145
158
invalid_run_command (invalid_cmd )
146
159
147
- dir_name = os .getcwd ()
148
- file_path = "%s/%s" % (dir_name , file_name )
149
-
150
160
data = []
151
161
data .append ("from seleniumbase import BaseCase" )
152
162
data .append ("" )
0 commit comments