Skip to content

Commit dc6fb95

Browse files
authored
Merge pull request #1863 from seleniumbase/gui-colors-and-fixes
GUI colors and fixes
2 parents 01238b3 + dccc8cf commit dc6fb95

File tree

10 files changed

+76
-31
lines changed

10 files changed

+76
-31
lines changed

examples/hack_the_planet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ def test_all_your_base_are_belong_to_us(self):
180180
self.highlight("#ctitle", loops=7, scroll=False)
181181

182182
self.open("https://www.nintendo.com/whatsnew/")
183-
self.set_text_content("h2", aybabtu)
184-
self.highlight("h2", loops=10, scroll=False)
183+
self.set_text_content("#main h2", aybabtu)
184+
self.highlight("#main h2", loops=10, scroll=False)
185185

186186
if not self.headless:
187187
self.open("https://support.gog.com/hc/en-us?product=gog")

help_docs/method_summary.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,8 @@ self.set_default_timeout(timeout)
546546

547547
self.reset_default_timeout()
548548

549+
self.fail(msg=None)
550+
549551
self.skip(reason="")
550552

551553
############

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ urllib3==1.26.12;python_version<"3.7"
3636
urllib3==1.26.15;python_version>="3.7"
3737
requests==2.27.1;python_version<"3.7"
3838
requests==2.29.0;python_version>="3.7"
39-
requests-toolbelt==0.10.1
40-
pynose==1.4.2
39+
requests-toolbelt==1.0.0
40+
pynose==1.4.3
4141
sniffio==1.3.0;python_version>="3.7"
4242
h11==0.14.0;python_version>="3.7"
4343
outcome==1.2.0;python_version>="3.7"
@@ -105,7 +105,7 @@ rich==13.3.5;python_version>="3.7"
105105
# ("pip install -r requirements.txt" also installs this, but "pip install -e ." won't.)
106106

107107
coverage==6.2;python_version<"3.7"
108-
coverage==7.2.4;python_version>="3.7"
108+
coverage==7.2.5;python_version>="3.7"
109109
pytest-cov==4.0.0
110110
flake8==5.0.4;python_version<"3.9"
111111
flake8==6.0.0;python_version>="3.9"

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__ = "4.14.4"
2+
__version__ = "4.14.5"

seleniumbase/console_scripts/sb_behave_gui.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def create_tkinter_gui(tests, command_string, t_count, f_count, s_tests):
256256
if t_count == 1:
257257
run_display = "Only ONE TEST was found and will be run:"
258258
tests = s_tests
259-
tk.Label(root, text=run_display, fg="blue").pack()
259+
tk.Label(root, text=run_display, bg="yellow", fg="magenta").pack()
260260
text_area = ScrolledText(
261261
root, width=100, height=12, wrap="word", state=tk.DISABLED
262262
)
@@ -271,7 +271,8 @@ def create_tkinter_gui(tests, command_string, t_count, f_count, s_tests):
271271
cb = tk.Checkbutton(
272272
text_area,
273273
text=(row),
274-
bg="white",
274+
bg="teal",
275+
fg="yellow",
275276
anchor="w",
276277
pady=0,
277278
variable=ara[count],
@@ -280,7 +281,8 @@ def create_tkinter_gui(tests, command_string, t_count, f_count, s_tests):
280281
cb = tk.Checkbutton(
281282
text_area,
282283
text=(row),
283-
bg="white",
284+
bg="teal",
285+
fg="yellow",
284286
anchor="w",
285287
pady=0,
286288
borderwidth=0,
@@ -297,7 +299,7 @@ def create_tkinter_gui(tests, command_string, t_count, f_count, s_tests):
297299
tk.Label(
298300
root,
299301
text='Additional "behave" Options: (Eg. "-D incognito --junit")',
300-
fg="blue",
302+
bg="yellow", fg="blue",
301303
).pack()
302304
entry = tk.Entry(root, textvariable=aopts)
303305
entry.pack()
@@ -326,6 +328,7 @@ def create_tkinter_gui(tests, command_string, t_count, f_count, s_tests):
326328
root,
327329
text="Run Selected Tests",
328330
fg="green",
331+
bg="gray",
329332
command=lambda: do_behave_run(
330333
root,
331334
tests,

seleniumbase/console_scripts/sb_caseplans.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,8 @@ def create_tkinter_gui(tests, command_string):
390390
"(Boilerplate Case Plans will be generated as needed)"
391391
)
392392
run_display_2 = "(Tests with existing Case Plans are already checked)"
393-
tk.Label(root, text=run_display, fg="blue").pack()
394-
try:
395-
tk.Label(root, text=run_display_2, fg="purple").pack()
396-
except Exception:
397-
tk.Label(root, text=run_display_2, fg="magenta").pack()
393+
tk.Label(root, text=run_display, bg="yellow", fg="green").pack()
394+
tk.Label(root, text=run_display_2, bg="yellow", fg="magenta").pack()
398395
text_area = ScrolledText(
399396
root, width=100, height=12, wrap="word", state=tk.DISABLED
400397
)
@@ -411,7 +408,8 @@ def create_tkinter_gui(tests, command_string):
411408
cb = tk.Checkbutton(
412409
text_area,
413410
text=(row),
414-
bg="white",
411+
bg="green",
412+
fg="yellow",
415413
anchor="w",
416414
pady=0,
417415
variable=ara[count],
@@ -420,7 +418,8 @@ def create_tkinter_gui(tests, command_string):
420418
cb = tk.Checkbutton(
421419
text_area,
422420
text=(row),
423-
bg="white",
421+
bg="green",
422+
fg="yellow",
424423
anchor="w",
425424
pady=0,
426425
borderwidth=0,
@@ -471,16 +470,14 @@ def create_tkinter_gui(tests, command_string):
471470
try:
472471
tk.Button(
473472
root,
474-
text=(
475-
"Generate Summary of existing Case Plans"),
473+
text=("Generate Summary of existing Case Plans"),
476474
fg="teal",
477475
command=lambda: view_summary_of_existing_case_plans(root, tests),
478476
).pack()
479477
except Exception:
480478
tk.Button(
481479
root,
482-
text=(
483-
"Generate Summary of existing Case Plans"),
480+
text=("Generate Summary of existing Case Plans"),
484481
fg="green",
485482
command=lambda: view_summary_of_existing_case_plans(root, tests),
486483
).pack()

seleniumbase/console_scripts/sb_commander.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def create_tkinter_gui(tests, command_string, files, solo_tests):
291291
% (len(solo_tests))
292292
)
293293
tests = solo_tests
294-
tk.Label(root, text=run_display, fg="blue").pack()
294+
tk.Label(root, text=run_display, bg="yellow", fg="magenta").pack()
295295
text_area = ScrolledText(
296296
root, width=100, height=12, wrap="word", state=tk.DISABLED
297297
)
@@ -306,7 +306,8 @@ def create_tkinter_gui(tests, command_string, files, solo_tests):
306306
cb = tk.Checkbutton(
307307
text_area,
308308
text=(row),
309-
bg="white",
309+
bg="green",
310+
fg="yellow",
310311
anchor="w",
311312
pady=0,
312313
variable=ara[count],
@@ -315,7 +316,8 @@ def create_tkinter_gui(tests, command_string, files, solo_tests):
315316
cb = tk.Checkbutton(
316317
text_area,
317318
text=(row),
318-
bg="white",
319+
bg="green",
320+
fg="yellow",
319321
anchor="w",
320322
pady=0,
321323
borderwidth=0,
@@ -332,7 +334,7 @@ def create_tkinter_gui(tests, command_string, files, solo_tests):
332334
tk.Label(
333335
root,
334336
text='Additional "pytest" Options: (Eg. "--incognito --slow")',
335-
fg="blue",
337+
bg="yellow", fg="blue",
336338
).pack()
337339
entry = tk.Entry(root, textvariable=aopts)
338340
entry.pack()
@@ -363,6 +365,7 @@ def create_tkinter_gui(tests, command_string, files, solo_tests):
363365
root,
364366
text="Run Selected Tests",
365367
fg="green",
368+
bg="gray",
366369
command=lambda: do_pytest_run(
367370
root,
368371
tests,

seleniumbase/fixtures/base_case.py

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ def open(self, url):
307307
pass # Odd issue where the open did happen. Continue.
308308
else:
309309
raise
310+
unittest.has_exception = False
310311
if (
311312
self.undetectable
312313
or (
@@ -4119,6 +4120,7 @@ def wait_for_ready_state_complete(self, timeout=None):
41194120
and settings.SKIP_JS_WAITS
41204121
):
41214122
time.sleep(0.05)
4123+
unittest.has_exception = False
41224124
return True
41234125

41244126
def wait_for_angularjs(self, timeout=None, **kwargs):
@@ -6360,12 +6362,14 @@ def assert_pdf_text(
63606362
)
63616363
if type(page) is int:
63626364
if text not in pdf_text:
6365+
unittest.has_exception = True
63636366
raise Exception(
63646367
"PDF [%s] is missing expected text [%s] on "
63656368
"page [%s]!" % (pdf, text, page)
63666369
)
63676370
else:
63686371
if text not in pdf_text:
6372+
unittest.has_exception = True
63696373
raise Exception(
63706374
"PDF [%s] is missing expected text [%s]!" % (pdf, text)
63716375
)
@@ -6740,40 +6744,52 @@ def assert_downloaded_file(self, file, timeout=None, browser=False):
67406744
def assert_true(self, expr, msg=None):
67416745
"""Asserts that the expression is True.
67426746
Will raise an exception if the statement if False."""
6747+
unittest.has_exception = True
67436748
self.assertTrue(expr, msg=msg)
6749+
unittest.has_exception = False
67446750

67456751
def assert_false(self, expr, msg=None):
67466752
"""Asserts that the expression is False.
67476753
Will raise an exception if the statement if True."""
6754+
unittest.has_exception = True
67486755
self.assertFalse(expr, msg=msg)
6756+
unittest.has_exception = False
67496757

67506758
def assert_equal(self, first, second, msg=None):
67516759
"""Asserts that the two values are equal.
67526760
Will raise an exception if the values are not equal."""
6761+
unittest.has_exception = True
67536762
self.assertEqual(first, second, msg=msg)
6763+
unittest.has_exception = False
67546764

67556765
def assert_not_equal(self, first, second, msg=None):
67566766
"""Asserts that the two values are not equal.
67576767
Will raise an exception if the values are equal."""
6768+
unittest.has_exception = True
67586769
self.assertNotEqual(first, second, msg=msg)
6770+
unittest.has_exception = False
67596771

67606772
def assert_in(self, first, second, msg=None):
67616773
"""Asserts that the first string is in the second string.
67626774
Will raise an exception if the first string is not in the second."""
6775+
unittest.has_exception = True
67636776
self.assertIn(first, second, msg=msg)
6777+
unittest.has_exception = False
67646778

67656779
def assert_not_in(self, first, second, msg=None):
67666780
"""Asserts that the first string is not in the second string.
67676781
Will raise an exception if the first string is in the second string."""
6782+
unittest.has_exception = True
67686783
self.assertNotIn(first, second, msg=msg)
6784+
unittest.has_exception = False
67696785

67706786
def assert_raises(self, *args, **kwargs):
67716787
"""Asserts that the following block of code raises an exception.
67726788
Will raise an exception if the block of code has no exception.
67736789
Usage Example =>
6774-
# Verify that the expected exception is raised.
6775-
with self.assert_raises(Exception):
6776-
raise Exception("Expected Exception!") """
6790+
# Verify that the expected exception is raised.
6791+
with self.assert_raises(Exception):
6792+
raise Exception("Expected Exception!") """
67776793
return self.assertRaises(*args, **kwargs)
67786794

67796795
def wait_for_attribute(
@@ -6884,9 +6900,11 @@ def assert_title(self, title):
68846900
self.wait_for_ready_state_complete()
68856901
time.sleep(2)
68866902
actual = self.get_page_title().strip()
6903+
unittest.has_exception = True
68876904
self.assertEqual(
68886905
expected, actual, error % (expected, actual)
68896906
)
6907+
unittest.has_exception = False
68906908
if self.demo_mode and not self.recorder_mode:
68916909
a_t = "ASSERT TITLE"
68926910
if self._language != "English":
@@ -6931,9 +6949,11 @@ def assert_title_contains(self, substring):
69316949
self.wait_for_ready_state_complete()
69326950
time.sleep(2)
69336951
actual = self.get_page_title().strip()
6952+
unittest.has_exception = True
69346953
self.assertIn(
69356954
expected, actual, error % (expected, actual)
69366955
)
6956+
unittest.has_exception = False
69376957
if self.demo_mode and not self.recorder_mode:
69386958
a_t = "ASSERT TITLE CONTAINS"
69396959
if self._language != "English":
@@ -6968,7 +6988,9 @@ def assert_url(self, url):
69686988
self.wait_for_ready_state_complete()
69696989
time.sleep(2)
69706990
actual = self.get_current_url().strip()
6991+
unittest.has_exception = True
69716992
self.assertEqual(expected, actual, error % (expected, actual))
6993+
unittest.has_exception = False
69726994
if self.demo_mode and not self.recorder_mode:
69736995
a_u = "ASSERT URL"
69746996
if self._language != "English":
@@ -7006,7 +7028,9 @@ def assert_url_contains(self, substring):
70067028
self.wait_for_ready_state_complete()
70077029
time.sleep(2)
70087030
actual = self.get_current_url().strip()
7031+
unittest.has_exception = True
70097032
self.assertIn(expected, actual, error % (expected, actual))
7033+
unittest.has_exception = False
70107034
if self.demo_mode and not self.recorder_mode:
70117035
a_u = "ASSERT URL CONTAINS"
70127036
if self._language != "English":
@@ -7103,6 +7127,7 @@ def assert_no_js_errors(self, exclude=[]):
71037127
er_str = str(errors)
71047128
er_str = er_str.replace("[{", "[\n{").replace("}, {", "},\n{")
71057129
current_url = self.get_current_url()
7130+
unittest.has_exception = True
71067131
raise Exception(
71077132
"JavaScript errors found on %s => %s" % (current_url, er_str)
71087133
)
@@ -7656,6 +7681,12 @@ def reset_default_timeout(self):
76567681
sb_config._is_timeout_changed = False
76577682
self.__overrided_default_timeouts = False
76587683

7684+
def fail(self, msg=None):
7685+
"""Fail immediately, with the given message."""
7686+
unittest.has_exception = True
7687+
super().fail(msg)
7688+
raise self.failureException(msg)
7689+
76597690
def skip(self, reason=""):
76607691
"""Mark the test as Skipped."""
76617692
self.__check_scope()
@@ -9806,6 +9837,7 @@ def __get_new_timeout(self, timeout):
98069837

98079838
def __check_scope(self):
98089839
if hasattr(self, "browser"): # self.browser stores the type of browser
9840+
unittest.has_exception = False
98099841
return # All good: setUp() already initialized variables in "self"
98109842
else:
98119843
message = (
@@ -9821,6 +9853,7 @@ def __check_scope(self):
98219853
"\n variables, which are initialized during the setUp() method"
98229854
"\n that runs automatically before all tests called by pytest."
98239855
)
9856+
unittest.has_exception = True
98249857
raise OutOfScopeException(message)
98259858

98269859
############
@@ -10076,6 +10109,7 @@ def process_deferred_asserts(self, print_only=False):
1007610109
if print_only:
1007710110
print(exception_output)
1007810111
else:
10112+
unittest.has_exception = True
1007910113
raise Exception(exception_output.replace("\\n", "\n"))
1008010114

1008110115
############
@@ -13868,6 +13902,8 @@ def setUp(self, masterqa_mode=False):
1386813902
# Some actions such as hover-clicking are different on mobile.
1386913903
self.mobile_emulator = False
1387013904

13905+
unittest.has_exception = False
13906+
1387113907
# Configure the test time limit (if used).
1387213908
self.set_time_limit(self.time_limit)
1387313909

@@ -14152,6 +14188,8 @@ def __has_exception(self):
1415214188
has_exception = sys.exc_info()[1] is not None
1415314189
if self.__will_be_skipped and hasattr(self, "_using_sb_fixture"):
1415414190
has_exception = False
14191+
if python3_11_or_newer and unittest.has_exception:
14192+
has_exception = True
1415514193
return has_exception
1415614194

1415714195
def __get_test_id(self):

seleniumbase/fixtures/page_actions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import codecs
2424
import os
2525
import time
26+
import unittest
2627
from selenium.common.exceptions import ElementNotInteractableException
2728
from selenium.common.exceptions import ElementNotVisibleException
2829
from selenium.common.exceptions import NoAlertPresentException
@@ -224,6 +225,7 @@ def hover_element(driver, element):
224225

225226

226227
def timeout_exception(exception, message):
228+
unittest.has_exception = True
227229
exc, msg = shared_utils.format_exc(exception, message)
228230
raise exc(msg)
229231

0 commit comments

Comments
 (0)