9
9
sbase mkfile new_test.py
10
10
11
11
Options:
12
+ --uc (UC Mode boilerplate using SB context manager)
12
13
-b / --basic (Basic boilerplate / single-line test)
13
- -r / --rec (adds Pdb+ breakpoint for Recorder Mode)
14
- --url=URL (makes the test start on a specific page)
14
+ -r / --rec (Adds Pdb+ breakpoint for Recorder Mode)
15
+ --url=URL (Makes the test start on a specific page)
15
16
16
17
Language Options:
17
18
--en / --English | --zh / --Chinese
37
38
and "assert_text". If using the basic boilerplate
38
39
option, only the "open" method is included. Only the
39
40
BaseCase format supports Languages or Recorder Mode.
41
+ UC Mode automatically uses English with SB() format.
40
42
"""
41
43
import codecs
42
44
import colorama
@@ -52,9 +54,10 @@ def invalid_run_command(msg=None):
52
54
exp += " Example:\n "
53
55
exp += " sbase mkfile new_test.py\n "
54
56
exp += " Options:\n "
57
+ exp += " --uc (UC Mode boilerplate using SB context manager)\n "
55
58
exp += " -b / --basic (Basic boilerplate / single-line test)\n "
56
- exp += " -r / --rec (adds Pdb+ breakpoint for Recorder Mode)\n "
57
- exp += " --url=URL (makes the test start on a specific page)\n "
59
+ exp += " -r / --rec (Adds Pdb+ breakpoint for Recorder Mode)\n "
60
+ exp += " --url=URL (Makes the test start on a specific page)\n "
58
61
exp += " Language Options:\n "
59
62
exp += " --en / --English | --zh / --Chinese\n "
60
63
exp += " --nl / --Dutch | --fr / --French\n "
@@ -77,6 +80,7 @@ def invalid_run_command(msg=None):
77
80
exp += ' and "assert_text". If using the basic boilerplate\n '
78
81
exp += ' option, only the "open" method is included. Only the\n '
79
82
exp += " BaseCase format supports Languages or Recorder Mode.\n "
83
+ exp += " UC Mode automatically uses English with SB() format.\n "
80
84
if not msg :
81
85
raise Exception ("INVALID RUN COMMAND!\n \n %s" % exp )
82
86
elif msg == "help" :
@@ -105,6 +109,7 @@ def main():
105
109
cr = colorama .Style .RESET_ALL
106
110
107
111
basic = False
112
+ use_uc = False
108
113
help_me = False
109
114
recorder = False
110
115
error_msg = None
@@ -152,6 +157,9 @@ def main():
152
157
recorder = True
153
158
elif option == "--record" or option == "--recorder" :
154
159
recorder = True
160
+ elif use_uc :
161
+ # UC must use English & ContextManager formats
162
+ continue
155
163
elif option == "--en" or option == "--english" :
156
164
language = "English"
157
165
elif option == "--zh" or option == "--chinese" :
@@ -184,6 +192,11 @@ def main():
184
192
syntax = "DriverContext"
185
193
elif option == "--dm" or option == "--driver-manager" :
186
194
syntax = "DriverManager"
195
+ elif option == "--uc" :
196
+ basic = True
197
+ language = "English"
198
+ syntax = "ContextManager"
199
+ use_uc = True
187
200
else :
188
201
invalid_cmd = "\n ===> INVALID OPTION: >> %s <<\n " % option
189
202
invalid_cmd = invalid_cmd .replace (">> " , ">>" + c5 + " " )
@@ -319,16 +332,22 @@ def main():
319
332
data = []
320
333
data .append ("from seleniumbase import SB" )
321
334
data .append ("" )
322
- data .append ('with SB(browser="chrome") as sb:' )
323
- data .append (
324
- ' sb.open("data:text/html,<div>Hello<br><input></div>")'
325
- )
335
+ if use_uc :
336
+ data .append ('with SB(uc=True) as sb:' )
337
+ else :
338
+ data .append ('with SB(browser="chrome") as sb:' )
339
+ if use_uc :
340
+ data .append (' url = "%s"' % url )
341
+ data .append (" sb.uc_open_with_reconnect(url, 4)" )
342
+ data .append (" sb.uc_gui_click_captcha()" )
343
+ else :
344
+ data .append (' sb.open("%s")' % url )
326
345
if not basic :
327
346
data .append (' sb.type("input", "Goodbye") # selector, text' )
328
- data .append (' sb.click("html body > div ") # selector' )
347
+ data .append (' sb.click("html body > p ") # selector' )
329
348
data .append (' sb.assert_element("input") # selector' )
330
- data .append (' sb.assert_text("Hello", "div ") # text, selector' )
331
- data .append (' sb.highlight("div ") # selector' )
349
+ data .append (' sb.assert_text("Hello", "p ") # text, selector' )
350
+ data .append (' sb.highlight("p ") # selector' )
332
351
data .append (" sb.sleep(0.5) # seconds" )
333
352
data .append ("" )
334
353
new_data = data
@@ -337,7 +356,14 @@ def main():
337
356
data .append ("from seleniumbase import DriverContext" )
338
357
data .append ("" )
339
358
data .append ('with DriverContext(browser="chrome") as driver:' )
340
- data .append (' driver.get("data:text/html,<p>Hello<br><input>")' )
359
+ data .append (' driver.get("%s")' % url )
360
+ if not basic :
361
+ data .append (' driver.type("input", "Goodbye") # sel, text' )
362
+ data .append (' driver.click("html body > p") # selector' )
363
+ data .append (' driver.assert_element("input") # selector' )
364
+ data .append (' driver.assert_text("Hello", "p") # text, sel' )
365
+ data .append (' driver.highlight("p") # selector' )
366
+ data .append (" driver.sleep(0.5) # seconds" )
341
367
data .append ("" )
342
368
new_data = data
343
369
elif language == "English" and syntax == "DriverManager" :
@@ -346,7 +372,14 @@ def main():
346
372
data .append ("" )
347
373
data .append ('driver = Driver(browser="chrome")' )
348
374
data .append ("try:" )
349
- data .append (' driver.get("data:text/html,<p>Hello<br><input>")' )
375
+ data .append (' driver.get("%s")' % url )
376
+ if not basic :
377
+ data .append (' driver.type("input", "Goodbye") # sel, text' )
378
+ data .append (' driver.click("html body > p") # selector' )
379
+ data .append (' driver.assert_element("input") # selector' )
380
+ data .append (' driver.assert_text("Hello", "p") # text, sel' )
381
+ data .append (' driver.highlight("p") # selector' )
382
+ data .append (" driver.sleep(0.5) # seconds" )
350
383
data .append ("finally:" )
351
384
data .append (" driver.quit()" )
352
385
data .append ("" )
0 commit comments