Skip to content

Commit bee0d0b

Browse files
committed
Update console scripts
1 parent e489ac2 commit bee0d0b

File tree

4 files changed

+109
-41
lines changed

4 files changed

+109
-41
lines changed

seleniumbase/console_scripts/ReadMe.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@ Installs the specified webdriver.
3838
### mkdir
3939

4040
* Usage:
41-
``sbase mkdir [DIRECTORY]``
41+
``sbase mkdir [DIRECTORY] [OPTIONS]``
4242

4343
* Example:
4444
``sbase mkdir ui_tests``
4545

46+
* Options:
47+
``-b`` / ``--basic`` (Only config files. No tests added.)
48+
4649
* Output:
47-
Creates a new folder for running SeleniumBase scripts.
50+
Creates a new folder for running SBase scripts.
4851
The new folder contains default config files,
4952
sample tests for helping new users get started,
5053
and Python boilerplates for setting up customized

seleniumbase/console_scripts/run.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,12 @@ def show_mkdir_usage():
136136
print(sc)
137137
print("")
138138
print(" Usage:")
139-
print(" seleniumbase mkdir [DIRECTORY_NAME]")
140-
print(" OR: sbase mkdir [DIRECTORY_NAME]")
139+
print(" seleniumbase mkdir [DIRECTORY] [OPTIONS]")
140+
print(" OR: sbase mkdir [DIRECTORY] [OPTIONS]")
141141
print(" Example:")
142-
print(" sbase mkdir browser_tests")
142+
print(" sbase mkdir ui_tests")
143+
print(" Options:")
144+
print(" -b / --basic (Only config files. No tests added.)")
143145
print(" Output:")
144146
print(" Creates a new folder for running SBase scripts.")
145147
print(" The new folder contains default config files,")
@@ -162,13 +164,13 @@ def show_mkfile_usage():
162164
print(" Example:")
163165
print(" sbase mkfile new_test.py")
164166
print(" Options:")
165-
print(" -b / --basic (Basic boilerplate / single-line test)")
167+
print(" -b / --basic (Basic boilerplate / single-line test)")
166168
print(" Language Options:")
167-
print(" --en / --English | --zh / --Chinese")
168-
print(" --nl / --Dutch | --fr / --French")
169-
print(" --it / --Italian | --ja / --Japanese")
170-
print(" --ko / --Korean | --pt / --Portuguese")
171-
print(" --ru / --Russian | --es / --Spanish")
169+
print(" --en / --English | --zh / --Chinese")
170+
print(" --nl / --Dutch | --fr / --French")
171+
print(" --it / --Italian | --ja / --Japanese")
172+
print(" --ko / --Korean | --pt / --Portuguese")
173+
print(" --ru / --Russian | --es / --Spanish")
172174
print(" Output:")
173175
print(" Creates a new SBase test file with boilerplate code.")
174176
print(" If the file already exists, an error is raised.")

seleniumbase/console_scripts/sb_mkdir.py

Lines changed: 70 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
# -*- coding: utf-8 -*-
12
"""
23
Creates a new folder for running SeleniumBase scripts.
34
45
Usage:
5-
seleniumbase mkdir [DIRECTORY]
6-
OR sbase mkdir [DIRECTORY]
6+
seleniumbase mkdir [DIRECTORY] [OPTIONS]
7+
OR sbase mkdir [DIRECTORY] [OPTIONS]
78
89
Example:
910
sbase mkdir ui_tests
1011
12+
Options:
13+
-b / --basic (Only config files. No tests added.)
14+
1115
Output:
1216
Creates a new folder for running SBase scripts.
1317
The new folder contains default config files,
@@ -25,10 +29,12 @@
2529
def invalid_run_command(msg=None):
2630
exp = (" ** mkdir **\n\n")
2731
exp += " Usage:\n"
28-
exp += " seleniumbase mkdir [DIRECTORY_NAME]\n"
29-
exp += " OR sbase mkdir [DIRECTORY_NAME]\n"
32+
exp += " seleniumbase mkdir [DIRECTORY] [OPTIONS]\n"
33+
exp += " OR sbase mkdir [DIRECTORY] [OPTIONS]\n"
3034
exp += " Example:\n"
31-
exp += " sbase mkdir browser_tests\n"
35+
exp += " sbase mkdir ui_tests\n"
36+
exp += " Options:\n"
37+
exp += " -b / --basic (Only config files. No tests added.)\n"
3238
exp += " Output:\n"
3339
exp += " Creates a new folder for running SBase scripts.\n"
3440
exp += " The new folder contains default config files,\n"
@@ -42,32 +48,68 @@ def invalid_run_command(msg=None):
4248

4349

4450
def main():
45-
colorama.init(autoreset=True)
46-
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
47-
c5 = colorama.Fore.RED + colorama.Back.LIGHTYELLOW_EX
48-
cr = colorama.Style.RESET_ALL
51+
c1 = ""
52+
c5 = ""
53+
c7 = ""
54+
cr = ""
55+
if "linux" not in sys.platform:
56+
colorama.init(autoreset=True)
57+
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
58+
c5 = colorama.Fore.RED + colorama.Back.LIGHTYELLOW_EX
59+
c7 = colorama.Fore.BLACK + colorama.Back.MAGENTA
60+
cr = colorama.Style.RESET_ALL
61+
62+
basic = False
63+
help_me = False
4964
error_msg = None
65+
invalid_cmd = None
66+
5067
command_args = sys.argv[2:]
51-
if len(command_args) != 1:
52-
invalid_run_command()
5368
dir_name = command_args[0]
5469
if len(str(dir_name)) < 2:
5570
error_msg = (
5671
'Directory name length must be at least 2 characters long!')
5772
elif "/" in str(dir_name) or "\\" in str(dir_name):
5873
error_msg = (
5974
'Directory name must not include slashes ("/", "\\")!')
75+
elif dir_name.startswith("-"):
76+
error_msg = 'Directory name cannot start with "-"!'
6077
elif os.path.exists(os.getcwd() + '/' + dir_name):
6178
error_msg = (
62-
'Directory "%s" already exists in the current path!' % dir_name)
79+
'Directory "%s" already exists in this directory!' % dir_name)
6380
if error_msg:
64-
error_msg = c5 + error_msg + cr
81+
error_msg = c5 + "ERROR: " + error_msg + cr
6582
invalid_run_command(error_msg)
6683

84+
if len(command_args) >= 2:
85+
options = command_args[1:]
86+
for option in options:
87+
option = option.lower()
88+
if option == "help" or option == "--help":
89+
help_me = True
90+
elif option == "-b" or option == "--basic":
91+
basic = True
92+
else:
93+
invalid_cmd = "\n===> INVALID OPTION: >> %s <<\n" % option
94+
invalid_cmd = invalid_cmd.replace('>> ', ">>" + c5 + " ")
95+
invalid_cmd = invalid_cmd.replace(' <<', " " + cr + "<<")
96+
invalid_cmd = invalid_cmd.replace('>>', c7 + ">>" + cr)
97+
invalid_cmd = invalid_cmd.replace('<<', c7 + "<<" + cr)
98+
help_me = True
99+
break
100+
if help_me:
101+
invalid_run_command(invalid_cmd)
102+
67103
os.mkdir(dir_name)
68104

69105
data = []
70-
data.append("seleniumbase")
106+
seleniumbase_req = "seleniumbase"
107+
try:
108+
from seleniumbase import __version__
109+
seleniumbase_req = "seleniumbase>=%s" % str(__version__)
110+
except Exception:
111+
pass
112+
data.append(seleniumbase_req)
71113
data.append("")
72114
file_path = "%s/%s" % (dir_name, "requirements.txt")
73115
file = codecs.open(file_path, "w+", "utf-8")
@@ -96,7 +138,11 @@ def main():
96138
data.append(" offline: custom marker")
97139
data.append(" develop: custom marker")
98140
data.append(" qa: custom marker")
141+
data.append(" ci: custom marker")
142+
data.append(" e2e: custom marker")
99143
data.append(" ready: custom marker")
144+
data.append(" smoke: custom marker")
145+
data.append(" deploy: custom marker")
100146
data.append(" active: custom marker")
101147
data.append(" master: custom marker")
102148
data.append(" release: custom marker")
@@ -202,6 +248,7 @@ def main():
202248
data.append("html_report.html")
203249
data.append("report.html")
204250
data.append("report.xml")
251+
data.append("dashboard.html")
205252
data.append("allure_report")
206253
data.append("allure-report")
207254
data.append("allure_results")
@@ -221,13 +268,20 @@ def main():
221268
data.append("archived_files")
222269
data.append("assets")
223270
data.append("temp")
224-
data.append("temp*")
271+
data.append("temp_")
225272
data.append("node_modules")
226273
file_path = "%s/%s" % (dir_name, ".gitignore")
227274
file = codecs.open(file_path, "w+", "utf-8")
228275
file.writelines("\r\n".join(data))
229276
file.close()
230277

278+
if basic:
279+
success = (
280+
'\n' + c1 + '* Directory "' + dir_name + '" was created '
281+
'with config files! *' + cr + '\n')
282+
print(success)
283+
return
284+
231285
data = []
232286
data.append("from seleniumbase import BaseCase")
233287
data.append("")
@@ -481,6 +535,7 @@ def main():
481535
file = codecs.open(file_path, "w+", "utf-8")
482536
file.writelines("\r\n".join(data))
483537
file.close()
538+
484539
success = (
485540
'\n' + c1 + '* Directory "' + dir_name + '" was created '
486541
'with config files and sample tests! *' + cr + '\n')

seleniumbase/console_scripts/sb_mkfile.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ def invalid_run_command(msg=None):
4444
exp += " Example:\n"
4545
exp += " sbase mkfile new_test.py\n"
4646
exp += " Options:\n"
47-
exp += " -b / --basic (Basic boilerplate / single-line test)\n"
47+
exp += " -b / --basic (Basic boilerplate / single-line test)\n"
4848
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"
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"
5454
exp += " Output:\n"
5555
exp += " Creates a new SBase test file with boilerplate code.\n"
5656
exp += " If the file already exists, an error is raised.\n"
@@ -67,11 +67,17 @@ def invalid_run_command(msg=None):
6767

6868

6969
def main():
70-
colorama.init(autoreset=True)
71-
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
72-
c5 = colorama.Fore.RED + colorama.Back.LIGHTYELLOW_EX
73-
c7 = colorama.Fore.BLACK + colorama.Back.MAGENTA
74-
cr = colorama.Style.RESET_ALL
70+
c1 = ""
71+
c5 = ""
72+
c7 = ""
73+
cr = ""
74+
if "linux" not in sys.platform:
75+
colorama.init(autoreset=True)
76+
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
77+
c5 = colorama.Fore.RED + colorama.Back.LIGHTYELLOW_EX
78+
c7 = colorama.Fore.BLACK + colorama.Back.MAGENTA
79+
cr = colorama.Style.RESET_ALL
80+
7581
basic = False
7682
help_me = False
7783
error_msg = None
@@ -81,16 +87,18 @@ def main():
8187
command_args = sys.argv[2:]
8288
file_name = command_args[0]
8389
if not file_name.endswith(".py"):
84-
error_msg = 'File Name must end with ".py"!'
90+
error_msg = 'File name must end with ".py"!'
8591
elif "*" in file_name or len(str(file_name)) < 4:
86-
error_msg = 'Invalid File Name!'
92+
error_msg = 'Invalid file name!'
93+
elif file_name.startswith("-"):
94+
error_msg = 'File name cannot start with "-"!'
8795
elif "/" in str(file_name) or "\\" in str(file_name):
8896
error_msg = 'File must be created in the current directory!'
8997
elif os.path.exists(os.getcwd() + '/' + file_name):
9098
error_msg = (
91-
'File "%s" already exists in the current path!' % file_name)
99+
'File "%s" already exists in this directory!' % file_name)
92100
if error_msg:
93-
error_msg = c5 + error_msg + cr
101+
error_msg = c5 + "ERROR: " + error_msg + cr
94102
invalid_run_command(error_msg)
95103

96104
if len(command_args) >= 2:

0 commit comments

Comments
 (0)