Skip to content

Commit b385e3e

Browse files
authored
Merge pull request #1281 from seleniumbase/sbase-commander
New feature: SeleniumBase Commander / GUI for pytest
2 parents 7191a8c + db396b2 commit b385e3e

22 files changed

+566
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta property="og:image" content="https://seleniumbase.io/cdn/img/mac_sb_logo_5.png" />
66
<link rel="icon" href="https://seleniumbase.io/img/green_logo.png" />
77

8-
<h3 align="center"><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.io/cdn/img/mac_sb_logo_5.png" alt="SeleniumBase" title="SeleniumBase" width="300" /></a></h3>
8+
<h3 align="center"><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.io/cdn/img/mac_sb_logo_3.png" alt="SeleniumBase" title="SeleniumBase" width="300" /></a></h3>
99
<!-- View on GitHub -->
1010
<h4 align="center">Better web testing with <a href="https://www.selenium.dev/documentation/" target="_blank">Selenium</a> and <a href="https://docs.pytest.org/en/stable/" target="_blank">pytest</a>.</h4>
1111
<p align="center">

examples/ReadMe.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ pytest upload_file_test.py
135135

136136
--------
137137

138+
Try the new SeleniumBase Commander! A GUI for pytest:
139+
140+
```bash
141+
sbase gui
142+
```
143+
144+
<img src="https://seleniumbase.io/cdn/img/sbase_commander.png" title="SeleniumBase Commander / GUI for pytest" /><br />
145+
146+
--------
147+
138148
<b>SeleniumBase tests can also be run with ``nosetests``:</b>
139149

140150
Run an example test with nosetests:

examples/test_agent.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ def test_user_agent(self):
88
original_user_agent = user_agent_detected
99
if not self.user_agent:
1010
# Using the built-in user-agent string
11-
print("\n\nUser-Agent:\n%s\n" % user_agent_detected)
11+
self._print("\n\nUser-Agent: %s" % user_agent_detected)
1212
else:
1313
# User-agent was overridden using: --agent=STRING
14-
print("\n\nUser-Agent override:\n%s\n" % user_agent_detected)
15-
print(self.get_text(".ip-address p"))
14+
self._print("\n\nUser-Agent override: %s" % user_agent_detected)
15+
print("\n" + self.get_text(".ip-address p"))
1616
self.sleep(3)
1717

1818
# Now change the user-agent using "execute_cdp_cmd()"
1919
if not self.is_chromium():
2020
msg = "\n* execute_cdp_cmd() is only for Chromium browsers"
21-
print(msg)
21+
self._print(msg)
2222
self.skip(msg)
2323
print("\n--------------------------")
2424
try:
@@ -33,8 +33,8 @@ def test_user_agent(self):
3333
)
3434
self.open("http://whatsmyuseragent.org/")
3535
user_agent_detected = self.get_text(".user-agent p")
36-
print("\nUser-Agent (after override):\n%s\n" % user_agent_detected)
37-
print(self.get_text(".ip-address p"))
36+
self._print("\nUser-Agent override: %s" % user_agent_detected)
37+
print("\n" + self.get_text(".ip-address p") + "\n")
3838
self.sleep(3)
3939
finally:
4040
# Reset the user-agent back to the original

examples/test_chinese_pdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def test_chinese_pdf(self):
88

99
# Get and print PDF text
1010
pdf_text = self.get_pdf_text(pdf, page=2)
11-
self._print("\n" + pdf_text)
11+
print("\n" + pdf_text)
1212

1313
# Assert PDF contains the expected text on Page 2
1414
self.assert_pdf_text(pdf, "个测试类", page=2)

examples/test_get_pdf_text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ def test_get_pdf_text(self):
88
"Automate_the_Boring_Stuff_sample_ch17.pdf"
99
)
1010
pdf_text = self.get_pdf_text(pdf, page=1)
11-
self._print("\n" + pdf_text)
11+
print("\n" + pdf_text)

examples/user_agent_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ def test_user_agent(self):
88
original_user_agent = user_agent_detected
99
if not self.user_agent:
1010
# Using the built-in user-agent string
11-
print("\n\nUser-Agent = %s\n" % user_agent_detected)
11+
self._print("\n\nUser-Agent = %s\n" % user_agent_detected)
1212
else:
1313
# User-agent was overridden using: --agent=STRING
14-
print("\n\nUser-Agent override = %s\n" % user_agent_detected)
14+
self._print("\n\nUser-Agent override = %s\n" % user_agent_detected)
1515
self.sleep(3)
1616

1717
if not self.is_chromium():
1818
# Skip the rest of the test if not using a Chromium browser
1919
msg = "\n* execute_cdp_cmd() is only for Chromium browsers"
20-
print(msg)
20+
self._print(msg)
2121
self.skip(msg)
2222
try:
2323
# Now change the user-agent using "execute_cdp_cmd()"
@@ -33,7 +33,7 @@ def test_user_agent(self):
3333
)
3434
self.open("https://www.whatsmyua.info/")
3535
user_agent_detected = self.get_text("#custom-ua-string")
36-
print("\nUser-Agent (after override) = %s" % user_agent_detected)
36+
self._print("\nUser-Agent override = %s\n" % user_agent_detected)
3737
self.sleep(3)
3838
finally:
3939
# Reset the user-agent back to the original

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "2.4.35"
2+
__version__ = "2.5.0"

seleniumbase/console_scripts/ReadMe.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ COMMANDS:
1717
install [DRIVER] [OPTIONS]
1818
methods (List common Python methods)
1919
options (List common pytest options)
20+
commander / gui [OPTIONAL PATH or TEST FILE]
2021
mkdir [DIRECTORY] [OPTIONS]
2122
mkfile [FILE.py] [OPTIONS]
2223
mkrec / codegen [FILE.py] [OPTIONS]
@@ -143,6 +144,21 @@ that are available when using SeleniumBase.
143144
For the full list of command-line options, type: "pytest --help".
144145
```
145146

147+
<h3>commander / gui</h3>
148+
149+
* Usage:
150+
``sbase commander [OPTIONAL PATH or TEST FILE]``
151+
``sbase gui [OPTIONAL PATH or TEST FILE]``
152+
153+
* Examples:
154+
``sbase gui``
155+
``sbase gui -k agent``
156+
``sbase gui examples/``
157+
``sbase gui test_suite.py``
158+
159+
* Output:
160+
Launches SeleniumBase Commander | GUI for pytest.
161+
146162
<h3>mkdir</h3>
147163

148164
* Usage:

seleniumbase/console_scripts/run.py

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
sbase install chromedriver
1010
sbase methods
1111
sbase options
12+
sbase commander
1213
sbase mkdir ui_tests
1314
sbase mkfile new_test.py
1415
sbase mkrec new_test.py
@@ -78,6 +79,7 @@ def show_basic_usage():
7879
sc += " install [DRIVER] [OPTIONS]\n"
7980
sc += " methods (List common Python methods)\n"
8081
sc += " options (List common pytest options)\n"
82+
sc += " commander / gui [OPTIONAL PATH or TEST FILE]\n"
8183
sc += " mkdir [DIRECTORY] [OPTIONS]\n"
8284
sc += " mkfile [FILE.py] [OPTIONS]\n"
8385
sc += " mkrec / codegen [FILE.py] [OPTIONS]\n"
@@ -146,6 +148,28 @@ def show_install_usage():
146148
print("")
147149

148150

151+
def show_commander_usage():
152+
c2 = colorama.Fore.BLUE + colorama.Back.LIGHTGREEN_EX
153+
c3 = colorama.Fore.BLUE + colorama.Back.LIGHTYELLOW_EX
154+
cr = colorama.Style.RESET_ALL
155+
sc = " " + c2 + "** " + c3 + "commander" + c2 + " **" + cr
156+
print(sc)
157+
print("")
158+
print(" Usage:")
159+
print(" seleniumbase commander [OPTIONAL PATH or TEST FILE]")
160+
print(" OR: sbase commander [OPTIONAL PATH or TEST FILE]")
161+
print(" OR: seleniumbase gui [OPTIONAL PATH or TEST FILE]")
162+
print(" OR: sbase gui [OPTIONAL PATH or TEST FILE]")
163+
print(" Examples:")
164+
print(" sbase gui")
165+
print(" sbase gui -k agent")
166+
print(" sbase gui examples/")
167+
print(" sbase gui test_suite.py")
168+
print(" Output:")
169+
print(" Launches SeleniumBase Commander | GUI for pytest.")
170+
print("")
171+
172+
149173
def show_mkdir_usage():
150174
c2 = colorama.Fore.BLUE + colorama.Back.LIGHTGREEN_EX
151175
c3 = colorama.Fore.BLUE + colorama.Back.LIGHTYELLOW_EX
@@ -250,6 +274,21 @@ def show_codegen_usage():
250274
print("")
251275

252276

277+
def show_recorder_usage():
278+
c2 = colorama.Fore.BLUE + colorama.Back.LIGHTGREEN_EX
279+
c3 = colorama.Fore.BLUE + colorama.Back.LIGHTYELLOW_EX
280+
cr = colorama.Style.RESET_ALL
281+
sc = " " + c2 + "** " + c3 + "recorder" + c2 + " **" + cr
282+
print(sc)
283+
print("")
284+
print(" Usage:")
285+
print(" seleniumbase recorder")
286+
print(" OR: sbase recorder")
287+
print(" Output:")
288+
print(" Launches the SeleniumBase Recorder Desktop App.")
289+
print("")
290+
291+
253292
def show_mkpres_usage():
254293
c2 = colorama.Fore.BLUE + colorama.Back.LIGHTGREEN_EX
255294
c3 = colorama.Fore.BLUE + colorama.Back.LIGHTYELLOW_EX
@@ -629,7 +668,8 @@ def show_methods():
629668
sbm += "*.get_attribute(selector, attribute) => Get element attribute.\n"
630669
sbm += "*.get_title() => Get the title of the current page.\n"
631670
sbm += "*.switch_to_frame(frame) => Switch into the iframe container.\n"
632-
sbm += "*.switch_to_default_content() => Leave the iframe container.\n"
671+
sbm += "*.switch_to_default_content() => Exit all iframe containers.\n"
672+
sbm += "*.switch_to_parent_frame() => Exit from the current iframe.\n"
633673
sbm += "*.open_new_window() => Open a new window in the same browser.\n"
634674
sbm += "*.switch_to_window(window) => Switch to the browser window.\n"
635675
sbm += "*.switch_to_default_window() => Switch to the original window.\n"
@@ -735,10 +775,12 @@ def show_detailed_help():
735775
print(c6 + " " + c2 + " Commands: " + c6 + " ")
736776
print(cr)
737777
show_install_usage()
778+
show_commander_usage()
738779
show_mkdir_usage()
739780
show_mkfile_usage()
740781
show_mkrec_usage()
741782
show_codegen_usage()
783+
show_recorder_usage()
742784
show_mkpres_usage()
743785
show_mkchart_usage()
744786
show_convert_usage()
@@ -779,6 +821,10 @@ def main():
779821
else:
780822
show_basic_usage()
781823
show_install_usage()
824+
elif command == "commander" or command == "gui":
825+
from seleniumbase.console_scripts import sb_commander
826+
827+
sb_commander.main()
782828
elif (
783829
command == "recorder"
784830
or (command == "record" and len(command_args) == 0)
@@ -960,6 +1006,14 @@ def main():
9601006
print("")
9611007
show_install_usage()
9621008
return
1009+
elif command_args[0] == "commander":
1010+
print("")
1011+
show_commander_usage()
1012+
return
1013+
elif command_args[0] == "gui":
1014+
print("")
1015+
show_commander_usage()
1016+
return
9631017
elif command_args[0] == "mkdir":
9641018
print("")
9651019
show_mkdir_usage()
@@ -976,6 +1030,10 @@ def main():
9761030
print("")
9771031
show_codegen_usage()
9781032
return
1033+
elif command_args[0] == "recorder":
1034+
print("")
1035+
show_recorder_usage()
1036+
return
9791037
elif command_args[0] == "mkpres":
9801038
print("")
9811039
show_mkpres_usage()

0 commit comments

Comments
 (0)