Skip to content

Commit 493c978

Browse files
committed
Add the "sbase methods" command to console scripts
1 parent b119283 commit 493c978

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ pip install seleniumbase
111111
112112
COMMANDS:
113113
install [DRIVER] [OPTIONS]
114+
methods (List common Python methods)
114115
options (List common pytest options)
115116
mkdir [DIRECTORY] [OPTIONS]
116117
mkfile [FILE.py] [OPTIONS]

seleniumbase/console_scripts/ReadMe.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ Installs the specified webdriver.
3535
(``iedriver`` is required for Internet Explorer automation)
3636
(``operadriver`` is required for Opera Browser automation)
3737

38+
### methods
39+
40+
* Usage:
41+
``sbase methods``
42+
43+
* Output:
44+
Displays common SeleniumBase Python methods.
45+
3846
### options
3947

4048
* Usage:

seleniumbase/console_scripts/run.py

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
88
Examples:
99
sbase install chromedriver
10+
sbase methods
11+
sbase options
1012
sbase mkdir ui_tests
1113
sbase mkfile new_test.py
1214
sbase mkpres new_presentation.py
13-
sbase options
1415
sbase convert webdriver_unittest_file.py
1516
sbase print my_first_test.py -n
1617
sbase translate my_first_test.py --zh -p
@@ -66,6 +67,7 @@ def show_basic_usage():
6667
sc += ("\n")
6768
sc += ("COMMANDS:\n")
6869
sc += (" install [DRIVER] [OPTIONS]\n")
70+
sc += (" methods (List common Python methods)\n")
6971
sc += (" options (List common pytest options)\n")
7072
sc += (" mkdir [DIRECTORY] [OPTIONS]\n")
7173
sc += (" mkfile [FILE.py] [OPTIONS]\n")
@@ -501,6 +503,62 @@ def show_package_location():
501503
print("%s" % location)
502504

503505

506+
def show_methods():
507+
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
508+
c2 = colorama.Fore.BLUE + colorama.Back.LIGHTGREEN_EX
509+
c3 = colorama.Fore.BLUE + colorama.Back.LIGHTYELLOW_EX
510+
c4 = colorama.Fore.MAGENTA + colorama.Back.LIGHTYELLOW_EX
511+
c5 = colorama.Fore.LIGHTRED_EX + colorama.Back.LIGHTGREEN_EX
512+
cr = colorama.Style.RESET_ALL
513+
sc = ("\n " + c2 + " ** " + c3 + " SeleniumBase Python Methods "
514+
"" + c2 + " ** " + cr)
515+
print(sc)
516+
print("")
517+
line = "Here are some common methods that come with SeleniumBase:"
518+
line = c1 + line + cr
519+
print(line)
520+
line = "(Some optional args are not shown here)"
521+
print(line)
522+
print("")
523+
sbm = ""
524+
sbm += ('*.open(url) => Navigate the browser window to the URL.\n')
525+
sbm += ('*.type(selector, text) => Update the field with the text.\n')
526+
sbm += ('*.click(selector) => Click the element with the selector.\n')
527+
sbm += ('*.click_link(link_text) => Click the link containing text.\n')
528+
sbm += ('*.go_back() => Navigate back to the previous URL.\n')
529+
sbm += ('*.select_option_by_text(dropdown_selector, option)\n')
530+
sbm += ('*.hover_and_click(hover_selector, click_selector)\n')
531+
sbm += ('*.drag_and_drop(drag_selector, drop_selector)\n')
532+
sbm += ('*.get_text(selector) => Get the text from the element.\n')
533+
sbm += ('*.get_current_url() => Get the URL of the current page.\n')
534+
sbm += ('*.get_page_source() => Get the HTML of the current page.\n')
535+
sbm += ('*.get_attribute(selector, attribute) => Get element attribute.\n')
536+
sbm += ('*.get_title() => Get the title of the current page.\n')
537+
sbm += ('*.switch_to_frame(frame) => Switch into the iframe container.\n')
538+
sbm += ('*.switch_to_default_content() => Leave the iframe container.\n')
539+
sbm += ('*.open_new_window() => Open a new window in the same browser.\n')
540+
sbm += ('*.switch_to_window(window) => Switch to the browser window.\n')
541+
sbm += ('*.switch_to_default_window() => Switch to the original window.\n')
542+
sbm += ('*.get_new_driver(OPTIONS) => Open a new driver with OPTIONS.\n')
543+
sbm += ('*.switch_to_driver(driver) => Switch to the browser driver.\n')
544+
sbm += ('*.switch_to_default_driver() => Switch to the original driver.\n')
545+
sbm += ('*.is_element_visible(selector) => Return True if item visible.\n')
546+
sbm += ('*.is_text_visible(text) => Return True if text is visible.\n')
547+
sbm += ('*.save_screenshot(name) => Save a screenshot in PNG format.\n')
548+
sbm += ('*.assert_element(selector) => Verify the element is visible.\n')
549+
sbm += ('*.assert_text(text, selector) => Verify text in the element.\n')
550+
sbm += ('*.assert_title(title) => Verify the title of the web page.\n')
551+
sbm += ('*.assert_downloaded_file(file) => Verify file was downloaded.\n')
552+
sbm += ('*.assert_no_404_errors() => Verify there are no broken links.\n')
553+
sbm += ('*.assert_no_js_errors() => Verify there are no JS errors.\n')
554+
sbm = sbm.replace("*.", "self." + c1).replace('(', cr + '(')
555+
sbm = sbm.replace("self.", c2 + "self" + c5 + "." + cr)
556+
sbm = sbm.replace('(', c3 + '(' + c4)
557+
sbm = sbm.replace(')', c3 + ')' + cr)
558+
print(sbm)
559+
print("")
560+
561+
504562
def show_options():
505563
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
506564
c2 = colorama.Fore.BLUE + colorama.Back.LIGHTGREEN_EX
@@ -739,6 +797,8 @@ def main():
739797
print()
740798
else:
741799
show_basic_usage()
800+
elif command == "methods" or command == "--methods":
801+
show_methods()
742802
elif command == "options" or command == "--options":
743803
show_options()
744804
elif command == "help" or command == "--help":

0 commit comments

Comments
 (0)