Merge pull request #1863 from seleniumbase/gui-colors-and-fixes

GUI colors and fixes
This commit is contained in:
Michael Mintz 2023-05-02 00:58:35 -04:00 committed by GitHub
commit dc6fb95b68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 76 additions and 31 deletions

View File

@ -180,8 +180,8 @@ class HackTests(BaseCase):
self.highlight("#ctitle", loops=7, scroll=False) self.highlight("#ctitle", loops=7, scroll=False)
self.open("https://www.nintendo.com/whatsnew/") self.open("https://www.nintendo.com/whatsnew/")
self.set_text_content("h2", aybabtu) self.set_text_content("#main h2", aybabtu)
self.highlight("h2", loops=10, scroll=False) self.highlight("#main h2", loops=10, scroll=False)
if not self.headless: if not self.headless:
self.open("https://support.gog.com/hc/en-us?product=gog") self.open("https://support.gog.com/hc/en-us?product=gog")

View File

@ -546,6 +546,8 @@ self.set_default_timeout(timeout)
self.reset_default_timeout() self.reset_default_timeout()
self.fail(msg=None)
self.skip(reason="") self.skip(reason="")
############ ############

View File

@ -36,8 +36,8 @@ urllib3==1.26.12;python_version<"3.7"
urllib3==1.26.15;python_version>="3.7" urllib3==1.26.15;python_version>="3.7"
requests==2.27.1;python_version<"3.7" requests==2.27.1;python_version<"3.7"
requests==2.29.0;python_version>="3.7" requests==2.29.0;python_version>="3.7"
requests-toolbelt==0.10.1 requests-toolbelt==1.0.0
pynose==1.4.2 pynose==1.4.3
sniffio==1.3.0;python_version>="3.7" sniffio==1.3.0;python_version>="3.7"
h11==0.14.0;python_version>="3.7" h11==0.14.0;python_version>="3.7"
outcome==1.2.0;python_version>="3.7" outcome==1.2.0;python_version>="3.7"
@ -105,7 +105,7 @@ rich==13.3.5;python_version>="3.7"
# ("pip install -r requirements.txt" also installs this, but "pip install -e ." won't.) # ("pip install -r requirements.txt" also installs this, but "pip install -e ." won't.)
coverage==6.2;python_version<"3.7" coverage==6.2;python_version<"3.7"
coverage==7.2.4;python_version>="3.7" coverage==7.2.5;python_version>="3.7"
pytest-cov==4.0.0 pytest-cov==4.0.0
flake8==5.0.4;python_version<"3.9" flake8==5.0.4;python_version<"3.9"
flake8==6.0.0;python_version>="3.9" flake8==6.0.0;python_version>="3.9"

View File

@ -1,2 +1,2 @@
# seleniumbase package # seleniumbase package
__version__ = "4.14.4" __version__ = "4.14.5"

View File

@ -256,7 +256,7 @@ def create_tkinter_gui(tests, command_string, t_count, f_count, s_tests):
if t_count == 1: if t_count == 1:
run_display = "Only ONE TEST was found and will be run:" run_display = "Only ONE TEST was found and will be run:"
tests = s_tests tests = s_tests
tk.Label(root, text=run_display, fg="blue").pack() tk.Label(root, text=run_display, bg="yellow", fg="magenta").pack()
text_area = ScrolledText( text_area = ScrolledText(
root, width=100, height=12, wrap="word", state=tk.DISABLED root, width=100, height=12, wrap="word", state=tk.DISABLED
) )
@ -271,7 +271,8 @@ def create_tkinter_gui(tests, command_string, t_count, f_count, s_tests):
cb = tk.Checkbutton( cb = tk.Checkbutton(
text_area, text_area,
text=(row), text=(row),
bg="white", bg="teal",
fg="yellow",
anchor="w", anchor="w",
pady=0, pady=0,
variable=ara[count], variable=ara[count],
@ -280,7 +281,8 @@ def create_tkinter_gui(tests, command_string, t_count, f_count, s_tests):
cb = tk.Checkbutton( cb = tk.Checkbutton(
text_area, text_area,
text=(row), text=(row),
bg="white", bg="teal",
fg="yellow",
anchor="w", anchor="w",
pady=0, pady=0,
borderwidth=0, borderwidth=0,
@ -297,7 +299,7 @@ def create_tkinter_gui(tests, command_string, t_count, f_count, s_tests):
tk.Label( tk.Label(
root, root,
text='Additional "behave" Options: (Eg. "-D incognito --junit")', text='Additional "behave" Options: (Eg. "-D incognito --junit")',
fg="blue", bg="yellow", fg="blue",
).pack() ).pack()
entry = tk.Entry(root, textvariable=aopts) entry = tk.Entry(root, textvariable=aopts)
entry.pack() entry.pack()
@ -326,6 +328,7 @@ def create_tkinter_gui(tests, command_string, t_count, f_count, s_tests):
root, root,
text="Run Selected Tests", text="Run Selected Tests",
fg="green", fg="green",
bg="gray",
command=lambda: do_behave_run( command=lambda: do_behave_run(
root, root,
tests, tests,

View File

@ -390,11 +390,8 @@ def create_tkinter_gui(tests, command_string):
"(Boilerplate Case Plans will be generated as needed)" "(Boilerplate Case Plans will be generated as needed)"
) )
run_display_2 = "(Tests with existing Case Plans are already checked)" run_display_2 = "(Tests with existing Case Plans are already checked)"
tk.Label(root, text=run_display, fg="blue").pack() tk.Label(root, text=run_display, bg="yellow", fg="green").pack()
try: tk.Label(root, text=run_display_2, bg="yellow", fg="magenta").pack()
tk.Label(root, text=run_display_2, fg="purple").pack()
except Exception:
tk.Label(root, text=run_display_2, fg="magenta").pack()
text_area = ScrolledText( text_area = ScrolledText(
root, width=100, height=12, wrap="word", state=tk.DISABLED root, width=100, height=12, wrap="word", state=tk.DISABLED
) )
@ -411,7 +408,8 @@ def create_tkinter_gui(tests, command_string):
cb = tk.Checkbutton( cb = tk.Checkbutton(
text_area, text_area,
text=(row), text=(row),
bg="white", bg="green",
fg="yellow",
anchor="w", anchor="w",
pady=0, pady=0,
variable=ara[count], variable=ara[count],
@ -420,7 +418,8 @@ def create_tkinter_gui(tests, command_string):
cb = tk.Checkbutton( cb = tk.Checkbutton(
text_area, text_area,
text=(row), text=(row),
bg="white", bg="green",
fg="yellow",
anchor="w", anchor="w",
pady=0, pady=0,
borderwidth=0, borderwidth=0,
@ -471,16 +470,14 @@ def create_tkinter_gui(tests, command_string):
try: try:
tk.Button( tk.Button(
root, root,
text=( text=("Generate Summary of existing Case Plans"),
"Generate Summary of existing Case Plans"),
fg="teal", fg="teal",
command=lambda: view_summary_of_existing_case_plans(root, tests), command=lambda: view_summary_of_existing_case_plans(root, tests),
).pack() ).pack()
except Exception: except Exception:
tk.Button( tk.Button(
root, root,
text=( text=("Generate Summary of existing Case Plans"),
"Generate Summary of existing Case Plans"),
fg="green", fg="green",
command=lambda: view_summary_of_existing_case_plans(root, tests), command=lambda: view_summary_of_existing_case_plans(root, tests),
).pack() ).pack()

View File

@ -291,7 +291,7 @@ def create_tkinter_gui(tests, command_string, files, solo_tests):
% (len(solo_tests)) % (len(solo_tests))
) )
tests = solo_tests tests = solo_tests
tk.Label(root, text=run_display, fg="blue").pack() tk.Label(root, text=run_display, bg="yellow", fg="magenta").pack()
text_area = ScrolledText( text_area = ScrolledText(
root, width=100, height=12, wrap="word", state=tk.DISABLED root, width=100, height=12, wrap="word", state=tk.DISABLED
) )
@ -306,7 +306,8 @@ def create_tkinter_gui(tests, command_string, files, solo_tests):
cb = tk.Checkbutton( cb = tk.Checkbutton(
text_area, text_area,
text=(row), text=(row),
bg="white", bg="green",
fg="yellow",
anchor="w", anchor="w",
pady=0, pady=0,
variable=ara[count], variable=ara[count],
@ -315,7 +316,8 @@ def create_tkinter_gui(tests, command_string, files, solo_tests):
cb = tk.Checkbutton( cb = tk.Checkbutton(
text_area, text_area,
text=(row), text=(row),
bg="white", bg="green",
fg="yellow",
anchor="w", anchor="w",
pady=0, pady=0,
borderwidth=0, borderwidth=0,
@ -332,7 +334,7 @@ def create_tkinter_gui(tests, command_string, files, solo_tests):
tk.Label( tk.Label(
root, root,
text='Additional "pytest" Options: (Eg. "--incognito --slow")', text='Additional "pytest" Options: (Eg. "--incognito --slow")',
fg="blue", bg="yellow", fg="blue",
).pack() ).pack()
entry = tk.Entry(root, textvariable=aopts) entry = tk.Entry(root, textvariable=aopts)
entry.pack() entry.pack()
@ -363,6 +365,7 @@ def create_tkinter_gui(tests, command_string, files, solo_tests):
root, root,
text="Run Selected Tests", text="Run Selected Tests",
fg="green", fg="green",
bg="gray",
command=lambda: do_pytest_run( command=lambda: do_pytest_run(
root, root,
tests, tests,

View File

@ -307,6 +307,7 @@ class BaseCase(unittest.TestCase):
pass # Odd issue where the open did happen. Continue. pass # Odd issue where the open did happen. Continue.
else: else:
raise raise
unittest.has_exception = False
if ( if (
self.undetectable self.undetectable
or ( or (
@ -4119,6 +4120,7 @@ class BaseCase(unittest.TestCase):
and settings.SKIP_JS_WAITS and settings.SKIP_JS_WAITS
): ):
time.sleep(0.05) time.sleep(0.05)
unittest.has_exception = False
return True return True
def wait_for_angularjs(self, timeout=None, **kwargs): def wait_for_angularjs(self, timeout=None, **kwargs):
@ -6360,12 +6362,14 @@ class BaseCase(unittest.TestCase):
) )
if type(page) is int: if type(page) is int:
if text not in pdf_text: if text not in pdf_text:
unittest.has_exception = True
raise Exception( raise Exception(
"PDF [%s] is missing expected text [%s] on " "PDF [%s] is missing expected text [%s] on "
"page [%s]!" % (pdf, text, page) "page [%s]!" % (pdf, text, page)
) )
else: else:
if text not in pdf_text: if text not in pdf_text:
unittest.has_exception = True
raise Exception( raise Exception(
"PDF [%s] is missing expected text [%s]!" % (pdf, text) "PDF [%s] is missing expected text [%s]!" % (pdf, text)
) )
@ -6740,40 +6744,52 @@ class BaseCase(unittest.TestCase):
def assert_true(self, expr, msg=None): def assert_true(self, expr, msg=None):
"""Asserts that the expression is True. """Asserts that the expression is True.
Will raise an exception if the statement if False.""" Will raise an exception if the statement if False."""
unittest.has_exception = True
self.assertTrue(expr, msg=msg) self.assertTrue(expr, msg=msg)
unittest.has_exception = False
def assert_false(self, expr, msg=None): def assert_false(self, expr, msg=None):
"""Asserts that the expression is False. """Asserts that the expression is False.
Will raise an exception if the statement if True.""" Will raise an exception if the statement if True."""
unittest.has_exception = True
self.assertFalse(expr, msg=msg) self.assertFalse(expr, msg=msg)
unittest.has_exception = False
def assert_equal(self, first, second, msg=None): def assert_equal(self, first, second, msg=None):
"""Asserts that the two values are equal. """Asserts that the two values are equal.
Will raise an exception if the values are not equal.""" Will raise an exception if the values are not equal."""
unittest.has_exception = True
self.assertEqual(first, second, msg=msg) self.assertEqual(first, second, msg=msg)
unittest.has_exception = False
def assert_not_equal(self, first, second, msg=None): def assert_not_equal(self, first, second, msg=None):
"""Asserts that the two values are not equal. """Asserts that the two values are not equal.
Will raise an exception if the values are equal.""" Will raise an exception if the values are equal."""
unittest.has_exception = True
self.assertNotEqual(first, second, msg=msg) self.assertNotEqual(first, second, msg=msg)
unittest.has_exception = False
def assert_in(self, first, second, msg=None): def assert_in(self, first, second, msg=None):
"""Asserts that the first string is in the second string. """Asserts that the first string is in the second string.
Will raise an exception if the first string is not in the second.""" Will raise an exception if the first string is not in the second."""
unittest.has_exception = True
self.assertIn(first, second, msg=msg) self.assertIn(first, second, msg=msg)
unittest.has_exception = False
def assert_not_in(self, first, second, msg=None): def assert_not_in(self, first, second, msg=None):
"""Asserts that the first string is not in the second string. """Asserts that the first string is not in the second string.
Will raise an exception if the first string is in the second string.""" Will raise an exception if the first string is in the second string."""
unittest.has_exception = True
self.assertNotIn(first, second, msg=msg) self.assertNotIn(first, second, msg=msg)
unittest.has_exception = False
def assert_raises(self, *args, **kwargs): def assert_raises(self, *args, **kwargs):
"""Asserts that the following block of code raises an exception. """Asserts that the following block of code raises an exception.
Will raise an exception if the block of code has no exception. Will raise an exception if the block of code has no exception.
Usage Example => Usage Example =>
# Verify that the expected exception is raised. # Verify that the expected exception is raised.
with self.assert_raises(Exception): with self.assert_raises(Exception):
raise Exception("Expected Exception!") """ raise Exception("Expected Exception!") """
return self.assertRaises(*args, **kwargs) return self.assertRaises(*args, **kwargs)
def wait_for_attribute( def wait_for_attribute(
@ -6884,9 +6900,11 @@ class BaseCase(unittest.TestCase):
self.wait_for_ready_state_complete() self.wait_for_ready_state_complete()
time.sleep(2) time.sleep(2)
actual = self.get_page_title().strip() actual = self.get_page_title().strip()
unittest.has_exception = True
self.assertEqual( self.assertEqual(
expected, actual, error % (expected, actual) expected, actual, error % (expected, actual)
) )
unittest.has_exception = False
if self.demo_mode and not self.recorder_mode: if self.demo_mode and not self.recorder_mode:
a_t = "ASSERT TITLE" a_t = "ASSERT TITLE"
if self._language != "English": if self._language != "English":
@ -6931,9 +6949,11 @@ class BaseCase(unittest.TestCase):
self.wait_for_ready_state_complete() self.wait_for_ready_state_complete()
time.sleep(2) time.sleep(2)
actual = self.get_page_title().strip() actual = self.get_page_title().strip()
unittest.has_exception = True
self.assertIn( self.assertIn(
expected, actual, error % (expected, actual) expected, actual, error % (expected, actual)
) )
unittest.has_exception = False
if self.demo_mode and not self.recorder_mode: if self.demo_mode and not self.recorder_mode:
a_t = "ASSERT TITLE CONTAINS" a_t = "ASSERT TITLE CONTAINS"
if self._language != "English": if self._language != "English":
@ -6968,7 +6988,9 @@ class BaseCase(unittest.TestCase):
self.wait_for_ready_state_complete() self.wait_for_ready_state_complete()
time.sleep(2) time.sleep(2)
actual = self.get_current_url().strip() actual = self.get_current_url().strip()
unittest.has_exception = True
self.assertEqual(expected, actual, error % (expected, actual)) self.assertEqual(expected, actual, error % (expected, actual))
unittest.has_exception = False
if self.demo_mode and not self.recorder_mode: if self.demo_mode and not self.recorder_mode:
a_u = "ASSERT URL" a_u = "ASSERT URL"
if self._language != "English": if self._language != "English":
@ -7006,7 +7028,9 @@ class BaseCase(unittest.TestCase):
self.wait_for_ready_state_complete() self.wait_for_ready_state_complete()
time.sleep(2) time.sleep(2)
actual = self.get_current_url().strip() actual = self.get_current_url().strip()
unittest.has_exception = True
self.assertIn(expected, actual, error % (expected, actual)) self.assertIn(expected, actual, error % (expected, actual))
unittest.has_exception = False
if self.demo_mode and not self.recorder_mode: if self.demo_mode and not self.recorder_mode:
a_u = "ASSERT URL CONTAINS" a_u = "ASSERT URL CONTAINS"
if self._language != "English": if self._language != "English":
@ -7103,6 +7127,7 @@ class BaseCase(unittest.TestCase):
er_str = str(errors) er_str = str(errors)
er_str = er_str.replace("[{", "[\n{").replace("}, {", "},\n{") er_str = er_str.replace("[{", "[\n{").replace("}, {", "},\n{")
current_url = self.get_current_url() current_url = self.get_current_url()
unittest.has_exception = True
raise Exception( raise Exception(
"JavaScript errors found on %s => %s" % (current_url, er_str) "JavaScript errors found on %s => %s" % (current_url, er_str)
) )
@ -7656,6 +7681,12 @@ class BaseCase(unittest.TestCase):
sb_config._is_timeout_changed = False sb_config._is_timeout_changed = False
self.__overrided_default_timeouts = False self.__overrided_default_timeouts = False
def fail(self, msg=None):
"""Fail immediately, with the given message."""
unittest.has_exception = True
super().fail(msg)
raise self.failureException(msg)
def skip(self, reason=""): def skip(self, reason=""):
"""Mark the test as Skipped.""" """Mark the test as Skipped."""
self.__check_scope() self.__check_scope()
@ -9806,6 +9837,7 @@ class BaseCase(unittest.TestCase):
def __check_scope(self): def __check_scope(self):
if hasattr(self, "browser"): # self.browser stores the type of browser if hasattr(self, "browser"): # self.browser stores the type of browser
unittest.has_exception = False
return # All good: setUp() already initialized variables in "self" return # All good: setUp() already initialized variables in "self"
else: else:
message = ( message = (
@ -9821,6 +9853,7 @@ class BaseCase(unittest.TestCase):
"\n variables, which are initialized during the setUp() method" "\n variables, which are initialized during the setUp() method"
"\n that runs automatically before all tests called by pytest." "\n that runs automatically before all tests called by pytest."
) )
unittest.has_exception = True
raise OutOfScopeException(message) raise OutOfScopeException(message)
############ ############
@ -10076,6 +10109,7 @@ class BaseCase(unittest.TestCase):
if print_only: if print_only:
print(exception_output) print(exception_output)
else: else:
unittest.has_exception = True
raise Exception(exception_output.replace("\\n", "\n")) raise Exception(exception_output.replace("\\n", "\n"))
############ ############
@ -13868,6 +13902,8 @@ class BaseCase(unittest.TestCase):
# Some actions such as hover-clicking are different on mobile. # Some actions such as hover-clicking are different on mobile.
self.mobile_emulator = False self.mobile_emulator = False
unittest.has_exception = False
# Configure the test time limit (if used). # Configure the test time limit (if used).
self.set_time_limit(self.time_limit) self.set_time_limit(self.time_limit)
@ -14152,6 +14188,8 @@ class BaseCase(unittest.TestCase):
has_exception = sys.exc_info()[1] is not None has_exception = sys.exc_info()[1] is not None
if self.__will_be_skipped and hasattr(self, "_using_sb_fixture"): if self.__will_be_skipped and hasattr(self, "_using_sb_fixture"):
has_exception = False has_exception = False
if python3_11_or_newer and unittest.has_exception:
has_exception = True
return has_exception return has_exception
def __get_test_id(self): def __get_test_id(self):

View File

@ -23,6 +23,7 @@ By.PARTIAL_LINK_TEXT # "partial link text"
import codecs import codecs
import os import os
import time import time
import unittest
from selenium.common.exceptions import ElementNotInteractableException from selenium.common.exceptions import ElementNotInteractableException
from selenium.common.exceptions import ElementNotVisibleException from selenium.common.exceptions import ElementNotVisibleException
from selenium.common.exceptions import NoAlertPresentException from selenium.common.exceptions import NoAlertPresentException
@ -224,6 +225,7 @@ def hover_element(driver, element):
def timeout_exception(exception, message): def timeout_exception(exception, message):
unittest.has_exception = True
exc, msg = shared_utils.format_exc(exception, message) exc, msg = shared_utils.format_exc(exception, message)
raise exc(msg) raise exc(msg)

View File

@ -160,8 +160,8 @@ setup(
'urllib3==1.26.15;python_version>="3.7"', 'urllib3==1.26.15;python_version>="3.7"',
'requests==2.27.1;python_version<"3.7"', 'requests==2.27.1;python_version<"3.7"',
'requests==2.29.0;python_version>="3.7"', 'requests==2.29.0;python_version>="3.7"',
'requests-toolbelt==0.10.1', 'requests-toolbelt==1.0.0',
"pynose==1.4.2", "pynose==1.4.3",
'sniffio==1.3.0;python_version>="3.7"', 'sniffio==1.3.0;python_version>="3.7"',
'h11==0.14.0;python_version>="3.7"', 'h11==0.14.0;python_version>="3.7"',
'outcome==1.2.0;python_version>="3.7"', 'outcome==1.2.0;python_version>="3.7"',
@ -241,7 +241,7 @@ setup(
# Usage: coverage run -m pytest; coverage html; coverage report # Usage: coverage run -m pytest; coverage html; coverage report
"coverage": [ "coverage": [
'coverage==6.2;python_version<"3.7"', 'coverage==6.2;python_version<"3.7"',
'coverage==7.2.4;python_version>="3.7"', 'coverage==7.2.5;python_version>="3.7"',
"pytest-cov==4.0.0", "pytest-cov==4.0.0",
], ],
# pip install -e .[flake8] # pip install -e .[flake8]