1919 --ko / --Korean | --pt / --Portuguese
2020 --ru / --Russian | --es / --Spanish
2121
22+ Syntax Formats:
23+ --bc / --basecase (BaseCase class inheritance)
24+ --pf / --pytest-fixture (sb pytest fixture)
25+ --cf / --class-fixture (class + sb pytest fixture)
26+ --cm / --context-manager (SB context manager)
27+ --dc / --driver-context (DriverContext manager)
28+ --dm / --driver-manager (Driver manager)
29+
2230Output:
2331 Creates a new SBase test file with boilerplate code.
2432 If the file already exists, an error is raised.
25- By default, uses English mode and creates a
26- boilerplate with the 5 most common SeleniumBase
27- methods, which are "open", "type", "click",
28- "assert_element", and "assert_text". If using the
29- basic boilerplate option, only the "open" method
30- is included .
33+ By default, uses English with BaseCase inheritance,
34+ and creates a boilerplate with common SeleniumBase
35+ methods: "open", "type", "click", "assert_element ",
36+ and "assert_text". If using the basic boilerplate
37+ option, only the "open" method is included. Only the
38+ BaseCase format supports Languages or Recorder Mode .
3139"""
3240import codecs
3341import colorama
@@ -51,15 +59,22 @@ def invalid_run_command(msg=None):
5159 exp += " --it / --Italian | --ja / --Japanese\n "
5260 exp += " --ko / --Korean | --pt / --Portuguese\n "
5361 exp += " --ru / --Russian | --es / --Spanish\n "
62+ exp += " Syntax Formats:\n "
63+ exp += " --bc / --basecase (BaseCase class inheritance)\n "
64+ exp += " --pf / --pytest-fixture (sb pytest fixture)\n "
65+ exp += " --cf / --class-fixture (class + sb pytest fixture)\n "
66+ exp += " --cm / --context-manager (SB context manager)\n "
67+ exp += " --dc / --driver-context (DriverContext manager)\n "
68+ exp += " --dm / --driver-manager (Driver manager)\n "
5469 exp += " Output:\n "
5570 exp += " Creates a new SBase test file with boilerplate code.\n "
5671 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 "
72+ exp += " By default, uses English with BaseCase inheritance, \n "
73+ exp += " and creates a boilerplate with common SeleniumBase\n "
74+ exp += ' methods: "open", "type", "click", "assert_element ",\n '
75+ exp += ' and "assert_text". If using the basic boilerplate \n '
76+ exp += ' option, only the "open" method is included. Only the \n '
77+ exp += " BaseCase format supports Languages or Recorder Mode .\n "
6378 if not msg :
6479 raise Exception ("INVALID RUN COMMAND!\n \n %s" % exp )
6580 elif msg == "help" :
@@ -86,6 +101,7 @@ def main():
86101 recorder = False
87102 error_msg = None
88103 invalid_cmd = None
104+ syntax = "BaseCase"
89105 language = "English"
90106
91107 command_args = sys .argv [2 :]
@@ -138,6 +154,18 @@ def main():
138154 language = "Russian"
139155 elif option == "--es" or option == "--spanish" :
140156 language = "Spanish"
157+ elif option == "--bc" or option == "--basecase" :
158+ syntax = "BaseCase"
159+ elif option == "--pf" or option == "--pytest-fixture" :
160+ syntax = "PytestFixture"
161+ elif option == "--cf" or option == "--class-fixture" :
162+ syntax = "ClassFixture"
163+ elif option == "--cm" or option == "--context-manager" :
164+ syntax = "ContextManager"
165+ elif option == "--dc" or option == "--driver-context" :
166+ syntax = "DriverContext"
167+ elif option == "--dm" or option == "--driver-manager" :
168+ syntax = "DriverManager"
141169 else :
142170 invalid_cmd = "\n ===> INVALID OPTION: >> %s <<\n " % option
143171 invalid_cmd = invalid_cmd .replace (">> " , ">>" + c5 + " " )
@@ -239,7 +267,70 @@ def main():
239267 data .append ("" )
240268
241269 new_data = []
242- if language == "English" :
270+ if language == "English" and syntax == "BaseCase" :
271+ new_data = data
272+ elif language == "English" and syntax == "PytestFixture" :
273+ data = []
274+ data .append ("def test_base(sb):" )
275+ data .append (' sb.open("data:text/html,<p>Hello<br><input>")' )
276+ if not basic :
277+ data .append (' sb.type("input", "Goodbye") # selector, text' )
278+ data .append (' sb.click("html body > p") # selector' )
279+ data .append (' sb.assert_element("body") # selector' )
280+ data .append (' sb.assert_text("Hello", "p") # text, selector' )
281+ data .append ("" )
282+ new_data = data
283+ elif language == "English" and syntax == "ClassFixture" :
284+ data = []
285+ data .append ("class %s:" % class_name )
286+ data .append (" def test_base(self, sb):" )
287+ data .append (' sb.open("data:text/html,<p>Hello<br><input>")' )
288+ if not basic :
289+ data .append (
290+ ' sb.type("input", "Goodbye") # selector, text'
291+ )
292+ data .append (' sb.click("html body > p") # selector' )
293+ data .append (' sb.assert_element("body") # selector' )
294+ data .append (
295+ ' sb.assert_text("Hello", "p") # text, selector'
296+ )
297+ data .append ("" )
298+ new_data = data
299+ elif language == "English" and syntax == "ContextManager" :
300+ data = []
301+ data .append ("from seleniumbase import SB" )
302+ data .append ("" )
303+ data .append ('with SB(browser="chrome") as sb:' )
304+ data .append (
305+ ' sb.open("data:text/html,<div>Hello<br><input></div>")'
306+ )
307+ if not basic :
308+ data .append (' sb.type("input", "Goodbye") # selector, text' )
309+ data .append (' sb.click("html body > div") # selector' )
310+ data .append (' sb.assert_element("input") # selector' )
311+ data .append (' sb.assert_text("Hello", "div") # text, selector' )
312+ data .append (' sb.highlight("div") # selector' )
313+ data .append (" sb.sleep(0.5) # seconds" )
314+ data .append ("" )
315+ new_data = data
316+ elif language == "English" and syntax == "DriverContext" :
317+ data = []
318+ data .append ("from seleniumbase import DriverContext" )
319+ data .append ("" )
320+ data .append ('with DriverContext(browser="chrome") as driver:' )
321+ data .append (' driver.get("data:text/html,<p>Hello<br><input>")' )
322+ data .append ("" )
323+ new_data = data
324+ elif language == "English" and syntax == "DriverManager" :
325+ data = []
326+ data .append ("from seleniumbase import Driver" )
327+ data .append ("" )
328+ data .append ('driver = Driver(browser="chrome")' )
329+ data .append ("try:" )
330+ data .append (' driver.get("data:text/html,<p>Hello<br><input>")' )
331+ data .append ("finally:" )
332+ data .append (" driver.quit()" )
333+ data .append ("" )
243334 new_data = data
244335 else :
245336 from seleniumbase .translate .master_dict import MD
0 commit comments