seleniumbase 4.30.8__py3-none-any.whl → 4.31.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. sbase/__init__.py +1 -0
  2. seleniumbase/__init__.py +2 -3
  3. seleniumbase/__version__.py +1 -1
  4. seleniumbase/behave/behave_sb.py +47 -9
  5. seleniumbase/config/settings.py +4 -0
  6. seleniumbase/console_scripts/sb_behave_gui.py +5 -5
  7. seleniumbase/console_scripts/sb_caseplans.py +6 -6
  8. seleniumbase/console_scripts/sb_commander.py +5 -5
  9. seleniumbase/console_scripts/sb_install.py +10 -2
  10. seleniumbase/console_scripts/sb_recorder.py +4 -4
  11. seleniumbase/core/browser_launcher.py +138 -103
  12. seleniumbase/core/mysql.py +1 -4
  13. seleniumbase/core/recorder_helper.py +24 -5
  14. seleniumbase/core/sb_driver.py +2 -3
  15. seleniumbase/core/settings_parser.py +4 -0
  16. seleniumbase/fixtures/base_case.py +307 -492
  17. seleniumbase/fixtures/js_utils.py +19 -52
  18. seleniumbase/fixtures/page_actions.py +3 -6
  19. seleniumbase/fixtures/page_utils.py +20 -58
  20. seleniumbase/plugins/base_plugin.py +2 -3
  21. seleniumbase/plugins/driver_manager.py +169 -3
  22. seleniumbase/plugins/pytest_plugin.py +34 -21
  23. seleniumbase/plugins/sb_manager.py +170 -3
  24. seleniumbase/plugins/selenium_plugin.py +52 -6
  25. seleniumbase/undetected/__init__.py +13 -38
  26. seleniumbase/undetected/dprocess.py +4 -6
  27. seleniumbase/undetected/options.py +3 -6
  28. seleniumbase/undetected/patcher.py +2 -3
  29. {seleniumbase-4.30.8.dist-info → seleniumbase-4.31.0.dist-info}/METADATA +108 -123
  30. {seleniumbase-4.30.8.dist-info → seleniumbase-4.31.0.dist-info}/RECORD +34 -45
  31. {seleniumbase-4.30.8.dist-info → seleniumbase-4.31.0.dist-info}/WHEEL +1 -1
  32. sbase/ReadMe.txt +0 -2
  33. seleniumbase/ReadMe.md +0 -25
  34. seleniumbase/common/ReadMe.md +0 -71
  35. seleniumbase/console_scripts/ReadMe.md +0 -734
  36. seleniumbase/drivers/ReadMe.md +0 -27
  37. seleniumbase/extensions/ReadMe.md +0 -12
  38. seleniumbase/masterqa/ReadMe.md +0 -61
  39. seleniumbase/resources/ReadMe.md +0 -31
  40. seleniumbase/resources/favicon.ico +0 -0
  41. seleniumbase/utilities/selenium_grid/ReadMe.md +0 -84
  42. seleniumbase/utilities/selenium_ide/ReadMe.md +0 -111
  43. {seleniumbase-4.30.8.dist-info → seleniumbase-4.31.0.dist-info}/LICENSE +0 -0
  44. {seleniumbase-4.30.8.dist-info → seleniumbase-4.31.0.dist-info}/entry_points.txt +0 -0
  45. {seleniumbase-4.30.8.dist-info → seleniumbase-4.31.0.dist-info}/top_level.txt +0 -0
@@ -33,6 +33,7 @@ Page elements are given enough time to load before WebDriver acts on them.
33
33
  Code becomes greatly simplified and easier to maintain."""
34
34
 
35
35
  import codecs
36
+ import colorama
36
37
  import fasteners
37
38
  import json
38
39
  import logging
@@ -45,7 +46,7 @@ import textwrap
45
46
  import time
46
47
  import unittest
47
48
  import urllib3
48
- from contextlib import contextmanager
49
+ from contextlib import contextmanager, suppress
49
50
  from selenium.common.exceptions import (
50
51
  ElementClickInterceptedException as ECI_Exception,
51
52
  ElementNotInteractableException as ENI_Exception,
@@ -57,6 +58,7 @@ from selenium.common.exceptions import (
57
58
  TimeoutException,
58
59
  WebDriverException,
59
60
  )
61
+ from selenium.webdriver.common.action_chains import ActionChains
60
62
  from selenium.webdriver.common.by import By
61
63
  from selenium.webdriver.common.keys import Keys
62
64
  from selenium.webdriver.remote.remote_connection import LOGGER
@@ -73,9 +75,11 @@ from seleniumbase.common.exceptions import (
73
75
  VisualException,
74
76
  )
75
77
  from seleniumbase.config import settings
78
+ from seleniumbase.core import browser_launcher
76
79
  from seleniumbase.core import download_helper
77
80
  from seleniumbase.core import log_helper
78
81
  from seleniumbase.core import session_helper
82
+ from seleniumbase.core import visual_helper
79
83
  from seleniumbase.fixtures import constants
80
84
  from seleniumbase.fixtures import css_to_xpath
81
85
  from seleniumbase.fixtures import js_utils
@@ -180,6 +184,8 @@ class BaseCase(unittest.TestCase):
180
184
  self._chart_series_count = {}
181
185
  self._tour_steps = {}
182
186
  self._xvfb_display = None
187
+ self._xvfb_width = None
188
+ self._xvfb_height = None
183
189
 
184
190
  @classmethod
185
191
  def main(self, name, file, *args):
@@ -221,10 +227,8 @@ class BaseCase(unittest.TestCase):
221
227
  if self.__needs_minimum_wait():
222
228
  time.sleep(0.04)
223
229
  pre_action_url = None
224
- try:
230
+ with suppress(Exception):
225
231
  pre_action_url = self.driver.current_url
226
- except Exception:
227
- pass
228
232
  url = str(url).strip() # Remove leading and trailing whitespace
229
233
  if not self.__looks_like_a_page_url(url):
230
234
  # url should start with one of the following:
@@ -352,18 +356,12 @@ class BaseCase(unittest.TestCase):
352
356
  if self.undetectable:
353
357
  self.__uc_frame_layer = 0
354
358
  if self.demo_mode:
355
- if (
356
- self.driver.current_url.startswith("http")
357
- or self.driver.current_url.startswith("file")
358
- or self.driver.current_url.startswith("data")
359
- ):
359
+ if self.driver.current_url.startswith(("http", "file", "data")):
360
360
  if not js_utils.is_jquery_activated(self.driver):
361
- try:
361
+ with suppress(Exception):
362
362
  js_utils.add_js_link(
363
363
  self.driver, constants.JQuery.MIN_JS
364
364
  )
365
- except Exception:
366
- pass
367
365
  self.__demo_mode_pause_if_active()
368
366
 
369
367
  def get(self, url):
@@ -421,10 +419,8 @@ class BaseCase(unittest.TestCase):
421
419
  if scroll and not self.demo_mode and not self.slow_mode:
422
420
  self.__scroll_to_element(element, selector, by)
423
421
  pre_action_url = None
424
- try:
422
+ with suppress(Exception):
425
423
  pre_action_url = self.driver.current_url
426
- except Exception:
427
- pass
428
424
  pre_window_count = len(self.driver.window_handles)
429
425
  try:
430
426
  if (
@@ -438,7 +434,7 @@ class BaseCase(unittest.TestCase):
438
434
  href = None
439
435
  new_tab = False
440
436
  onclick = None
441
- try:
437
+ with suppress(Exception):
442
438
  if self.headless and element.tag_name.lower() == "a":
443
439
  # Handle a special case of opening a new tab (headless)
444
440
  href = element.get_attribute("href").strip()
@@ -448,20 +444,14 @@ class BaseCase(unittest.TestCase):
448
444
  new_tab = True
449
445
  if new_tab and self.__looks_like_a_page_url(href):
450
446
  if onclick:
451
- try:
447
+ with suppress(Exception):
452
448
  self.execute_script(onclick)
453
- except Exception:
454
- pass
455
449
  current_window = self.driver.current_window_handle
456
450
  self.open_new_window()
457
- try:
451
+ with suppress(Exception):
458
452
  self.open(href)
459
- except Exception:
460
- pass
461
453
  self.switch_to_window(current_window)
462
454
  return
463
- except Exception:
464
- pass
465
455
  # Normal click
466
456
  self.__element_click(element)
467
457
  except Stale_Exception:
@@ -474,10 +464,8 @@ class BaseCase(unittest.TestCase):
474
464
  timeout=timeout,
475
465
  original_selector=original_selector,
476
466
  )
477
- try:
467
+ with suppress(Exception):
478
468
  self.__scroll_to_element(element, selector, by)
479
- except Exception:
480
- pass
481
469
  if self.browser == "safari" and by == By.LINK_TEXT:
482
470
  self.__jquery_click(selector, by=by)
483
471
  elif self.browser == "safari":
@@ -485,7 +473,7 @@ class BaseCase(unittest.TestCase):
485
473
  else:
486
474
  self.__element_click(element)
487
475
  except ENI_Exception as e:
488
- try:
476
+ with suppress(Exception):
489
477
  if (
490
478
  "element has zero size" in e.msg
491
479
  and element.tag_name.lower() == "a"
@@ -497,8 +485,6 @@ class BaseCase(unittest.TestCase):
497
485
  if self.__needs_minimum_wait():
498
486
  time.sleep(0.04)
499
487
  return
500
- except Exception:
501
- pass
502
488
  self.wait_for_ready_state_complete()
503
489
  time.sleep(0.1)
504
490
  element = page_actions.wait_for_element_visible(
@@ -511,12 +497,10 @@ class BaseCase(unittest.TestCase):
511
497
  if not page_actions.is_element_clickable(
512
498
  self.driver, selector, by
513
499
  ):
514
- try:
500
+ with suppress(Exception):
515
501
  self.wait_for_element_clickable(
516
502
  selector, by, timeout=1.8
517
503
  )
518
- except Exception:
519
- pass # Find out which element would get the click instead
520
504
  element = page_actions.wait_for_element_visible(
521
505
  self.driver,
522
506
  selector,
@@ -527,7 +511,7 @@ class BaseCase(unittest.TestCase):
527
511
  href = None
528
512
  new_tab = False
529
513
  onclick = None
530
- try:
514
+ with suppress(Exception):
531
515
  if element.tag_name.lower() == "a":
532
516
  # Handle a special case of opening a new tab (non-headless)
533
517
  href = element.get_attribute("href").strip()
@@ -537,20 +521,14 @@ class BaseCase(unittest.TestCase):
537
521
  new_tab = True
538
522
  if new_tab and self.__looks_like_a_page_url(href):
539
523
  if onclick:
540
- try:
524
+ with suppress(Exception):
541
525
  self.execute_script(onclick)
542
- except Exception:
543
- pass
544
526
  current_window = self.driver.current_window_handle
545
527
  self.open_new_window()
546
- try:
528
+ with suppress(Exception):
547
529
  self.open(href)
548
- except Exception:
549
- pass
550
530
  self.switch_to_window(current_window)
551
531
  return
552
- except Exception:
553
- pass
554
532
  if scroll and not self.demo_mode and not self.slow_mode:
555
533
  self.__scroll_to_element(element, selector, by)
556
534
  if self.browser == "firefox" or self.browser == "safari":
@@ -632,10 +610,8 @@ class BaseCase(unittest.TestCase):
632
610
  self.switch_to_window(-1)
633
611
  if settings.WAIT_FOR_RSC_ON_CLICKS:
634
612
  if not self.undetectable:
635
- try:
613
+ with suppress(Exception):
636
614
  self.wait_for_ready_state_complete()
637
- except Exception:
638
- pass
639
615
  if self.__needs_minimum_wait() or self.browser == "safari":
640
616
  time.sleep(0.05)
641
617
  else:
@@ -643,10 +619,8 @@ class BaseCase(unittest.TestCase):
643
619
  else:
644
620
  if not self.undetectable:
645
621
  # A smaller subset of self.wait_for_ready_state_complete()
646
- try:
622
+ with suppress(Exception):
647
623
  self.wait_for_angularjs(timeout=settings.MINI_TIMEOUT)
648
- except Exception:
649
- pass
650
624
  if self.__needs_minimum_wait() or self.browser == "safari":
651
625
  time.sleep(0.045)
652
626
  try:
@@ -656,10 +630,8 @@ class BaseCase(unittest.TestCase):
656
630
  if self.__needs_minimum_wait():
657
631
  time.sleep(0.075)
658
632
  except Exception:
659
- try:
633
+ with suppress(Exception):
660
634
  self.wait_for_ready_state_complete()
661
- except Exception:
662
- pass
663
635
  if self.__needs_minimum_wait():
664
636
  time.sleep(0.05)
665
637
  else:
@@ -697,8 +669,6 @@ class BaseCase(unittest.TestCase):
697
669
  self.click(selector, by=by, timeout=timeout, delay=0.25)
698
670
 
699
671
  def double_click(self, selector, by="css selector", timeout=None):
700
- from selenium.webdriver.common.action_chains import ActionChains
701
-
702
672
  self.__check_scope()
703
673
  if not timeout:
704
674
  timeout = settings.SMALL_TIMEOUT
@@ -729,10 +699,8 @@ class BaseCase(unittest.TestCase):
729
699
  original_selector=original_selector,
730
700
  )
731
701
  pre_action_url = None
732
- try:
702
+ with suppress(Exception):
733
703
  pre_action_url = self.driver.current_url
734
- except Exception:
735
- pass
736
704
  try:
737
705
  if self.browser == "safari":
738
706
  # Jump to the "except" block where the other script should work
@@ -782,8 +750,6 @@ class BaseCase(unittest.TestCase):
782
750
 
783
751
  def context_click(self, selector, by="css selector", timeout=None):
784
752
  """(A context click is a right-click that opens a context menu.)"""
785
- from selenium.webdriver.common.action_chains import ActionChains
786
-
787
753
  self.__check_scope()
788
754
  if not timeout:
789
755
  timeout = settings.SMALL_TIMEOUT
@@ -814,10 +780,8 @@ class BaseCase(unittest.TestCase):
814
780
  original_selector=original_selector,
815
781
  )
816
782
  pre_action_url = None
817
- try:
783
+ with suppress(Exception):
818
784
  pre_action_url = self.driver.current_url
819
- except Exception:
820
- pass
821
785
  try:
822
786
  if self.browser == "safari":
823
787
  # Jump to the "except" block where the other script should work
@@ -935,19 +899,15 @@ class BaseCase(unittest.TestCase):
935
899
  element = self.wait_for_element_clickable(
936
900
  selector, by=by, timeout=timeout
937
901
  )
938
- try:
902
+ with suppress(Exception):
939
903
  element.clear()
940
- except Exception:
941
- pass # Clearing the text field first might not be necessary
942
904
  except Exception:
943
905
  pass # Clearing the text field first might not be necessary
944
906
  self.__demo_mode_pause_if_active(tiny=True)
945
907
  pre_action_url = None
946
908
  if self.demo_mode:
947
- try:
909
+ with suppress(Exception):
948
910
  pre_action_url = self.driver.current_url
949
- except Exception:
950
- pass
951
911
  text = self.__get_type_checked_text(text)
952
912
  try:
953
913
  if not text.endswith("\n"):
@@ -1057,10 +1017,8 @@ class BaseCase(unittest.TestCase):
1057
1017
  self.__scroll_to_element(element, selector, by)
1058
1018
  pre_action_url = None
1059
1019
  if self.demo_mode:
1060
- try:
1020
+ with suppress(Exception):
1061
1021
  pre_action_url = self.driver.current_url
1062
- except Exception:
1063
- pass
1064
1022
  text = self.__get_type_checked_text(text)
1065
1023
  try:
1066
1024
  if not text.endswith("\n"):
@@ -1233,11 +1191,9 @@ class BaseCase(unittest.TestCase):
1233
1191
  selector, by=by, timeout=timeout
1234
1192
  )
1235
1193
  element.clear()
1236
- try:
1194
+ with suppress(Exception):
1237
1195
  backspaces = Keys.BACK_SPACE * 42 # Autofill Defense
1238
1196
  element.send_keys(backspaces)
1239
- except Exception:
1240
- pass
1241
1197
  except Exception:
1242
1198
  element.clear()
1243
1199
 
@@ -1334,17 +1290,13 @@ class BaseCase(unittest.TestCase):
1334
1290
  if hasattr(self, "recorder_mode") and self.recorder_mode:
1335
1291
  self.save_recorded_actions()
1336
1292
  pre_action_url = None
1337
- try:
1293
+ with suppress(Exception):
1338
1294
  pre_action_url = self.driver.current_url
1339
- except Exception:
1340
- pass
1341
1295
  self.__last_page_load_url = None
1342
1296
  self.driver.back()
1343
- try:
1297
+ with suppress(Exception):
1344
1298
  if pre_action_url == self.driver.current_url:
1345
1299
  self.driver.back() # Again because the page was redirected
1346
- except Exception:
1347
- pass
1348
1300
  if self.recorder_mode:
1349
1301
  time_stamp = self.execute_script("return Date.now();")
1350
1302
  origin = self.get_origin()
@@ -1424,6 +1376,7 @@ class BaseCase(unittest.TestCase):
1424
1376
  self.open(url)
1425
1377
 
1426
1378
  def is_element_present(self, selector, by="css selector"):
1379
+ """Returns whether the element exists in the HTML."""
1427
1380
  self.wait_for_ready_state_complete()
1428
1381
  selector, by = self.__recalculate_selector(selector, by)
1429
1382
  if self.__is_shadow_selector(selector):
@@ -1431,6 +1384,7 @@ class BaseCase(unittest.TestCase):
1431
1384
  return page_actions.is_element_present(self.driver, selector, by)
1432
1385
 
1433
1386
  def is_element_visible(self, selector, by="css selector"):
1387
+ """Returns whether the element is visible on the page."""
1434
1388
  self.wait_for_ready_state_complete()
1435
1389
  selector, by = self.__recalculate_selector(selector, by)
1436
1390
  if self.__is_shadow_selector(selector):
@@ -1452,6 +1406,7 @@ class BaseCase(unittest.TestCase):
1452
1406
  return page_actions.is_element_enabled(self.driver, selector, by)
1453
1407
 
1454
1408
  def is_text_visible(self, text, selector="html", by="css selector"):
1409
+ """Returns whether the text substring is visible in the element."""
1455
1410
  self.wait_for_ready_state_complete()
1456
1411
  time.sleep(0.01)
1457
1412
  selector, by = self.__recalculate_selector(selector, by)
@@ -1460,6 +1415,8 @@ class BaseCase(unittest.TestCase):
1460
1415
  return page_actions.is_text_visible(self.driver, text, selector, by)
1461
1416
 
1462
1417
  def is_exact_text_visible(self, text, selector="html", by="css selector"):
1418
+ """Returns whether the text is exactly equal to the element text.
1419
+ (Leading and trailing whitespace is ignored in the verification.)"""
1463
1420
  self.wait_for_ready_state_complete()
1464
1421
  time.sleep(0.01)
1465
1422
  selector, by = self.__recalculate_selector(selector, by)
@@ -1498,6 +1455,7 @@ class BaseCase(unittest.TestCase):
1498
1455
  )
1499
1456
 
1500
1457
  def is_link_text_visible(self, link_text):
1458
+ """Returns whether there's an exact match for the link text."""
1501
1459
  self.wait_for_ready_state_complete()
1502
1460
  time.sleep(0.01)
1503
1461
  return page_actions.is_element_visible(
@@ -1505,6 +1463,7 @@ class BaseCase(unittest.TestCase):
1505
1463
  )
1506
1464
 
1507
1465
  def is_partial_link_text_visible(self, partial_link_text):
1466
+ """Returns whether there's a substring match for the link text."""
1508
1467
  self.wait_for_ready_state_complete()
1509
1468
  time.sleep(0.01)
1510
1469
  return page_actions.is_element_visible(
@@ -1633,10 +1592,8 @@ class BaseCase(unittest.TestCase):
1633
1592
  if self.__needs_minimum_wait():
1634
1593
  time.sleep(0.04)
1635
1594
  pre_action_url = None
1636
- try:
1595
+ with suppress(Exception):
1637
1596
  pre_action_url = self.driver.current_url
1638
- except Exception:
1639
- pass
1640
1597
  pre_window_count = len(self.driver.window_handles)
1641
1598
  try:
1642
1599
  element = self.wait_for_link_text_visible(link_text, timeout=0.2)
@@ -1707,10 +1664,8 @@ class BaseCase(unittest.TestCase):
1707
1664
  # switch to the last one if it exists.
1708
1665
  self.switch_to_window(-1)
1709
1666
  if settings.WAIT_FOR_RSC_ON_PAGE_LOADS:
1710
- try:
1667
+ with suppress(Exception):
1711
1668
  self.wait_for_ready_state_complete()
1712
- except Exception:
1713
- pass
1714
1669
  if self.demo_mode:
1715
1670
  if self.driver.current_url != pre_action_url:
1716
1671
  if not js_utils.is_jquery_activated(self.driver):
@@ -1736,10 +1691,8 @@ class BaseCase(unittest.TestCase):
1736
1691
  partial_link_text, timeout=timeout
1737
1692
  )
1738
1693
  pre_action_url = None
1739
- try:
1694
+ with suppress(Exception):
1740
1695
  pre_action_url = self.driver.current_url
1741
- except Exception:
1742
- pass
1743
1696
  pre_window_count = len(self.driver.window_handles)
1744
1697
  try:
1745
1698
  element = self.wait_for_partial_link_text(
@@ -1822,10 +1775,8 @@ class BaseCase(unittest.TestCase):
1822
1775
  # switch to the last one if it exists.
1823
1776
  self.switch_to_window(-1)
1824
1777
  if settings.WAIT_FOR_RSC_ON_PAGE_LOADS:
1825
- try:
1778
+ with suppress(Exception):
1826
1779
  self.wait_for_ready_state_complete()
1827
- except Exception:
1828
- pass
1829
1780
  if self.demo_mode:
1830
1781
  if self.driver.current_url != pre_action_url:
1831
1782
  if not js_utils.is_jquery_activated(self.driver):
@@ -1941,10 +1892,8 @@ class BaseCase(unittest.TestCase):
1941
1892
  original_attribute = attribute
1942
1893
  original_value = value
1943
1894
  if scroll and self.is_element_visible(selector, by=by):
1944
- try:
1895
+ with suppress(Exception):
1945
1896
  self.scroll_to(selector, by=by, timeout=timeout)
1946
- except Exception:
1947
- pass
1948
1897
  attribute = re.escape(attribute)
1949
1898
  attribute = self.__escape_quotes_if_needed(attribute)
1950
1899
  value = re.escape(value)
@@ -1989,10 +1938,8 @@ class BaseCase(unittest.TestCase):
1989
1938
  attribute,
1990
1939
  value,
1991
1940
  )
1992
- try:
1941
+ with suppress(Exception):
1993
1942
  self.execute_script(script)
1994
- except Exception:
1995
- pass
1996
1943
  if self.recorder_mode and self.__current_url_is_recordable():
1997
1944
  if self.get_session_storage_item("pause_recorder") == "no":
1998
1945
  time_stamp = self.execute_script("return Date.now();")
@@ -2021,10 +1968,8 @@ class BaseCase(unittest.TestCase):
2021
1968
  timeout = self.__get_new_timeout(timeout)
2022
1969
  selector, by = self.__recalculate_selector(selector, by)
2023
1970
  if self.is_element_visible(selector, by=by):
2024
- try:
1971
+ with suppress(Exception):
2025
1972
  self.scroll_to(selector, by=by, timeout=timeout)
2026
- except Exception:
2027
- pass
2028
1973
  attribute = re.escape(attribute)
2029
1974
  attribute = self.__escape_quotes_if_needed(attribute)
2030
1975
  css_selector = self.convert_to_css_selector(selector, by=by)
@@ -2053,10 +1998,8 @@ class BaseCase(unittest.TestCase):
2053
1998
  css_selector,
2054
1999
  attribute,
2055
2000
  )
2056
- try:
2001
+ with suppress(Exception):
2057
2002
  self.execute_script(script)
2058
- except Exception:
2059
- pass
2060
2003
 
2061
2004
  def get_property(
2062
2005
  self, selector, property, by="css selector", timeout=None
@@ -2202,20 +2145,16 @@ class BaseCase(unittest.TestCase):
2202
2145
  element = self.wait_for_element_present(
2203
2146
  selector, by=by, timeout=timeout
2204
2147
  )
2205
- try:
2148
+ with suppress(Exception):
2206
2149
  # If the first element isn't visible, wait a little.
2207
2150
  if not element.is_displayed():
2208
2151
  time.sleep(0.16)
2209
2152
  if self.undetectable:
2210
2153
  time.sleep(0.06)
2211
- except Exception:
2212
- pass
2213
2154
  elements = self.find_elements(selector, by=by)
2214
2155
  pre_action_url = None
2215
- try:
2156
+ with suppress(Exception):
2216
2157
  pre_action_url = self.driver.current_url
2217
- except Exception:
2218
- pass
2219
2158
  pre_window_count = len(self.driver.window_handles)
2220
2159
  click_count = 0
2221
2160
  for element in elements:
@@ -2298,10 +2237,8 @@ class BaseCase(unittest.TestCase):
2298
2237
  number = 0
2299
2238
  element = elements[number]
2300
2239
  pre_action_url = None
2301
- try:
2240
+ with suppress(Exception):
2302
2241
  pre_action_url = self.driver.current_url
2303
- except Exception:
2304
- pass
2305
2242
  pre_window_count = len(self.driver.window_handles)
2306
2243
  try:
2307
2244
  self.__scroll_to_element(element)
@@ -2344,22 +2281,18 @@ class BaseCase(unittest.TestCase):
2344
2281
  if self.is_element_visible(selector, by=by):
2345
2282
  self.click(selector, by=by)
2346
2283
  elif timeout > 0:
2347
- try:
2284
+ with suppress(Exception):
2348
2285
  self.wait_for_element_visible(
2349
2286
  selector, by=by, timeout=timeout
2350
2287
  )
2351
- except Exception:
2352
- pass
2353
2288
  if self.is_element_visible(selector, by=by):
2354
2289
  self.click(selector, by=by)
2355
2290
 
2356
2291
  def click_active_element(self):
2357
2292
  self.wait_for_ready_state_complete()
2358
2293
  pre_action_url = None
2359
- try:
2294
+ with suppress(Exception):
2360
2295
  pre_action_url = self.driver.current_url
2361
- except Exception:
2362
- pass
2363
2296
  pre_window_count = len(self.driver.window_handles)
2364
2297
  if self.recorder_mode:
2365
2298
  selector = js_utils.get_active_element_css(self.driver)
@@ -2492,12 +2425,10 @@ class BaseCase(unittest.TestCase):
2492
2425
  )
2493
2426
  # Handle switches that sit on checkboxes with zero opacity:
2494
2427
  # Change the opacity a bit to allow the click to succeed.
2495
- try:
2428
+ with suppress(Exception):
2496
2429
  self.execute_script(
2497
2430
  'arguments[0].style.opacity="0.001";', element
2498
2431
  )
2499
- except Exception:
2500
- pass
2501
2432
  if self.is_element_visible(selector, by=by):
2502
2433
  self.click(selector, by=by)
2503
2434
  else:
@@ -2505,14 +2436,12 @@ class BaseCase(unittest.TestCase):
2505
2436
  self.__dont_record_js_click = True
2506
2437
  self.js_click(selector, by="css selector")
2507
2438
  self.__dont_record_js_click = False
2508
- try:
2439
+ with suppress(Exception):
2509
2440
  self.execute_script(
2510
2441
  'arguments[0].style.opacity="arguments[1]";',
2511
2442
  element,
2512
2443
  opacity,
2513
2444
  )
2514
- except Exception:
2515
- pass
2516
2445
 
2517
2446
  def select_if_unselected(self, selector, by="css selector"):
2518
2447
  """Same as check_if_unchecked()"""
@@ -2532,12 +2461,10 @@ class BaseCase(unittest.TestCase):
2532
2461
  )
2533
2462
  # Handle switches that sit on checkboxes with zero opacity:
2534
2463
  # Change the opacity a bit to allow the click to succeed.
2535
- try:
2464
+ with suppress(Exception):
2536
2465
  self.execute_script(
2537
2466
  'arguments[0].style.opacity="0.001";', element
2538
2467
  )
2539
- except Exception:
2540
- pass
2541
2468
  if self.is_element_visible(selector, by=by):
2542
2469
  self.click(selector, by=by)
2543
2470
  else:
@@ -2545,14 +2472,12 @@ class BaseCase(unittest.TestCase):
2545
2472
  self.__dont_record_js_click = True
2546
2473
  self.js_click(selector, by="css selector")
2547
2474
  self.__dont_record_js_click = False
2548
- try:
2475
+ with suppress(Exception):
2549
2476
  self.execute_script(
2550
2477
  'arguments[0].style.opacity="arguments[1]";',
2551
2478
  element,
2552
2479
  opacity,
2553
2480
  )
2554
- except Exception:
2555
- pass
2556
2481
 
2557
2482
  def unselect_if_selected(self, selector, by="css selector"):
2558
2483
  """Same as uncheck_if_checked()"""
@@ -2611,14 +2536,12 @@ class BaseCase(unittest.TestCase):
2611
2536
  iframe_identifier = '[class="%s"]' % iframe_class
2612
2537
  else:
2613
2538
  continue
2614
- try:
2539
+ with suppress(Exception):
2615
2540
  self.switch_to_frame(iframe_identifier, timeout=1)
2616
2541
  if self.__needs_minimum_wait():
2617
2542
  time.sleep(0.02)
2618
2543
  if self.is_element_present(selector, by=by):
2619
2544
  return iframe_identifier
2620
- except Exception:
2621
- pass
2622
2545
  self.switch_to_default_content()
2623
2546
  if self.__needs_minimum_wait():
2624
2547
  time.sleep(0.02)
@@ -2692,10 +2615,8 @@ class BaseCase(unittest.TestCase):
2692
2615
  self.__demo_mode_highlight_if_active(original_selector, original_by)
2693
2616
  self.scroll_to(hover_selector, by=hover_by)
2694
2617
  pre_action_url = None
2695
- try:
2618
+ with suppress(Exception):
2696
2619
  pre_action_url = self.driver.current_url
2697
- except Exception:
2698
- pass
2699
2620
  pre_window_count = len(self.driver.window_handles)
2700
2621
  if self.recorder_mode and self.__current_url_is_recordable():
2701
2622
  if self.get_session_storage_item("pause_recorder") == "no":
@@ -2759,10 +2680,8 @@ class BaseCase(unittest.TestCase):
2759
2680
  self.__switch_to_newest_window_if_not_blank()
2760
2681
  elif self.browser == "safari":
2761
2682
  # Release the hover by hovering elsewhere
2762
- try:
2683
+ with suppress(Exception):
2763
2684
  page_actions.hover_on_element(self.driver, "body")
2764
- except Exception:
2765
- pass
2766
2685
  if self.demo_mode:
2767
2686
  if self.driver.current_url != pre_action_url:
2768
2687
  if not js_utils.is_jquery_activated(self.driver):
@@ -2822,10 +2741,8 @@ class BaseCase(unittest.TestCase):
2822
2741
  self.__demo_mode_highlight_if_active(original_selector, original_by)
2823
2742
  self.scroll_to(hover_selector, by=hover_by)
2824
2743
  pre_action_url = None
2825
- try:
2744
+ with suppress(Exception):
2826
2745
  pre_action_url = self.driver.current_url
2827
- except Exception:
2828
- pass
2829
2746
  pre_window_count = len(self.driver.window_handles)
2830
2747
  outdated_driver = False
2831
2748
  element = None
@@ -2886,7 +2803,7 @@ class BaseCase(unittest.TestCase):
2886
2803
  timeout=None,
2887
2804
  jquery=False,
2888
2805
  ):
2889
- """Drag and drop an element from one selector to another."""
2806
+ """Drag-and-drop an element from one selector to another."""
2890
2807
  self.__check_scope()
2891
2808
  if not timeout:
2892
2809
  timeout = settings.SMALL_TIMEOUT
@@ -2933,7 +2850,7 @@ class BaseCase(unittest.TestCase):
2933
2850
  def drag_and_drop_with_offset(
2934
2851
  self, selector, x, y, by="css selector", timeout=None
2935
2852
  ):
2936
- """Drag and drop an element to an {X,Y}-offset location."""
2853
+ """Drag-and-drop an element to an {X,Y}-offset location."""
2937
2854
  self.__check_scope()
2938
2855
  if not timeout:
2939
2856
  timeout = settings.SMALL_TIMEOUT
@@ -3013,10 +2930,8 @@ class BaseCase(unittest.TestCase):
3013
2930
  dropdown_selector, dropdown_by
3014
2931
  )
3015
2932
  pre_action_url = None
3016
- try:
2933
+ with suppress(Exception):
3017
2934
  pre_action_url = self.driver.current_url
3018
- except Exception:
3019
- pass
3020
2935
  pre_window_count = len(self.driver.window_handles)
3021
2936
  try:
3022
2937
  if option_by == "index":
@@ -3291,10 +3206,8 @@ class BaseCase(unittest.TestCase):
3291
3206
  self.open("data:text/html,<head></head><body><div></div></body>")
3292
3207
  inner_head = """document.getElementsByTagName("head")[0].innerHTML"""
3293
3208
  inner_body = """document.getElementsByTagName("body")[0].innerHTML"""
3294
- try:
3209
+ with suppress(Exception):
3295
3210
  self.wait_for_element_present("body", timeout=1)
3296
- except Exception:
3297
- pass
3298
3211
  if not found_body:
3299
3212
  self.execute_script('''%s = \"%s\"''' % (inner_body, html_string))
3300
3213
  elif found_body and not found_head:
@@ -4096,8 +4009,6 @@ class BaseCase(unittest.TestCase):
4096
4009
  "Valid options = {%s}" % (browser, valid_browsers)
4097
4010
  )
4098
4011
  # Launch a web browser
4099
- from seleniumbase.core import browser_launcher
4100
-
4101
4012
  new_driver = browser_launcher.get_driver(
4102
4013
  browser_name=browser_name,
4103
4014
  headless=headless,
@@ -4193,7 +4104,8 @@ class BaseCase(unittest.TestCase):
4193
4104
  self.driver.maximize_window()
4194
4105
  self.wait_for_ready_state_complete()
4195
4106
  else:
4196
- self.driver.set_window_size(width, height)
4107
+ with suppress(Exception):
4108
+ self.driver.set_window_size(width, height)
4197
4109
  except Exception:
4198
4110
  pass # Keep existing browser resolution
4199
4111
  elif self.browser == "safari":
@@ -4204,10 +4116,8 @@ class BaseCase(unittest.TestCase):
4204
4116
  except Exception:
4205
4117
  pass # Keep existing browser resolution
4206
4118
  else:
4207
- try:
4208
- self.driver.set_window_rect(10, 20, width, height)
4209
- except Exception:
4210
- pass
4119
+ with suppress(Exception):
4120
+ self.driver.set_window_rect(10, 46, width, height)
4211
4121
  if self.start_page and len(self.start_page) >= 4:
4212
4122
  if page_utils.is_valid_url(self.start_page):
4213
4123
  self.open(self.start_page)
@@ -4655,14 +4565,17 @@ class BaseCase(unittest.TestCase):
4655
4565
  from seleniumbase.js_code.recorder_js import recorder_js
4656
4566
 
4657
4567
  if not self.is_chromium():
4568
+ if "linux" not in sys.platform:
4569
+ c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
4570
+ c2 = colorama.Fore.BLUE + colorama.Back.LIGHTGREEN_EX
4571
+ cr = colorama.Style.RESET_ALL
4572
+ sc = c1 + "Selenium" + c2 + "Base" + cr
4658
4573
  raise Exception(
4659
- "The Recorder is only for Chromium browsers: (Chrome or Edge)"
4574
+ "The %s Recorder is for Chromium only!\n"
4575
+ " (Supported browsers: Chrome and Edge)" % sc
4660
4576
  )
4661
4577
  url = self.driver.current_url
4662
- if (
4663
- url.startswith("data:") or url.startswith("about:")
4664
- or url.startswith("chrome:") or url.startswith("edge:")
4665
- ):
4578
+ if url.startswith(("data:", "about:", "chrome:", "edge:")):
4666
4579
  message = (
4667
4580
  "The URL in Recorder-Mode cannot start with: "
4668
4581
  '"data:", "about:", "chrome:", or "edge:"!'
@@ -4671,7 +4584,7 @@ class BaseCase(unittest.TestCase):
4671
4584
  return
4672
4585
  if self.recorder_ext:
4673
4586
  return # The Recorder extension is already active
4674
- try:
4587
+ with suppress(Exception):
4675
4588
  recorder_on = self.get_session_storage_item("recorder_activated")
4676
4589
  if not recorder_on == "yes":
4677
4590
  self.execute_script(recorder_js)
@@ -4680,8 +4593,6 @@ class BaseCase(unittest.TestCase):
4680
4593
  print("\n" + message)
4681
4594
  p_msg = "Recorder Mode ACTIVE.<br>[ESC]: Pause. [~`]: Resume."
4682
4595
  self.post_message(p_msg, pause=False, style="error")
4683
- except Exception:
4684
- pass
4685
4596
 
4686
4597
  def __current_url_is_recordable(self):
4687
4598
  url = self.get_current_url()
@@ -4721,10 +4632,7 @@ class BaseCase(unittest.TestCase):
4721
4632
 
4722
4633
  def __get_recorded_actions_on_active_tab(self):
4723
4634
  url = self.driver.current_url
4724
- if (
4725
- url.startswith("data:") or url.startswith("about:")
4726
- or url.startswith("chrome:") or url.startswith("edge:")
4727
- ):
4635
+ if url.startswith(("data:", "about:", "chrome:", "edge:")):
4728
4636
  return []
4729
4637
  self.__origins_to_save.append(self.get_origin())
4730
4638
  actions = self.get_session_storage_item("recorded_actions")
@@ -4735,9 +4643,9 @@ class BaseCase(unittest.TestCase):
4735
4643
  return []
4736
4644
 
4737
4645
  def __process_recorded_actions(self):
4646
+ """Generates code after the SeleniumBase Recorder runs."""
4738
4647
  if self.driver is None:
4739
4648
  return
4740
- import colorama
4741
4649
  from seleniumbase.core import recorder_helper
4742
4650
 
4743
4651
  raw_actions = [] # All raw actions from sessionStorage
@@ -4939,10 +4847,7 @@ class BaseCase(unittest.TestCase):
4939
4847
  or srt_actions[n - 1][0] == "jq_cl"
4940
4848
  or srt_actions[n - 1][0] == "jq_ca"
4941
4849
  ):
4942
- if (
4943
- srt_actions[n - 1][1].startswith("input")
4944
- or srt_actions[n - 1][1].startswith("button")
4945
- ):
4850
+ if srt_actions[n - 1][1].startswith(("input", "button")):
4946
4851
  srt_actions[n][0] = "f_url"
4947
4852
  elif srt_actions[n - 1][0] == "input":
4948
4853
  if srt_actions[n - 1][2].endswith("\n"):
@@ -5290,7 +5195,6 @@ class BaseCase(unittest.TestCase):
5290
5195
  and (filename == "base_case.py" or methodname == "runTest")
5291
5196
  ):
5292
5197
  import traceback
5293
-
5294
5198
  stack_base = traceback.format_stack()[0].split(os.sep)[-1]
5295
5199
  test_base = stack_base.split(", in ")[0]
5296
5200
  if hasattr(self, "cm_filename") and self.cm_filename:
@@ -5360,11 +5264,9 @@ class BaseCase(unittest.TestCase):
5360
5264
  if recordings_folder.endswith("/"):
5361
5265
  recordings_folder = recordings_folder[:-1]
5362
5266
  if not os.path.exists(recordings_folder):
5363
- try:
5267
+ with suppress(Exception):
5364
5268
  os.makedirs(recordings_folder)
5365
5269
  sys.stdout.write("\nCreated recordings%s" % os.sep)
5366
- except Exception:
5367
- pass
5368
5270
 
5369
5271
  data = []
5370
5272
  data.append("")
@@ -5465,12 +5367,10 @@ class BaseCase(unittest.TestCase):
5465
5367
  if not new_file:
5466
5368
  rec_message = ">>> RECORDING ADDED to: "
5467
5369
  star_len = len(rec_message) + len(file_path)
5468
- try:
5370
+ with suppress(Exception):
5469
5371
  terminal_size = os.get_terminal_size().columns
5470
5372
  if terminal_size > 30 and star_len > terminal_size:
5471
5373
  star_len = terminal_size
5472
- except Exception:
5473
- pass
5474
5374
  spc = "\n\n"
5475
5375
  if hasattr(self, "rec_print") and self.rec_print:
5476
5376
  spc = ""
@@ -5543,22 +5443,16 @@ class BaseCase(unittest.TestCase):
5543
5443
  if recordings_folder.endswith("/"):
5544
5444
  recordings_folder = recordings_folder[:-1]
5545
5445
  if not os.path.exists(recordings_folder):
5546
- try:
5446
+ with suppress(Exception):
5547
5447
  os.makedirs(recordings_folder)
5548
- except Exception:
5549
- pass
5550
5448
  features_folder = os.path.join(recordings_folder, "features")
5551
5449
  if not os.path.exists(features_folder):
5552
- try:
5450
+ with suppress(Exception):
5553
5451
  os.makedirs(features_folder)
5554
- except Exception:
5555
- pass
5556
5452
  steps_folder = os.path.join(features_folder, "steps")
5557
5453
  if not os.path.exists(steps_folder):
5558
- try:
5454
+ with suppress(Exception):
5559
5455
  os.makedirs(steps_folder)
5560
- except Exception:
5561
- pass
5562
5456
 
5563
5457
  file_name = filename.split(".")[0]
5564
5458
  if hasattr(self, "is_behave") and self.is_behave:
@@ -5573,12 +5467,10 @@ class BaseCase(unittest.TestCase):
5573
5467
  if not new_file:
5574
5468
  rec_message = ">>> RECORDING ADDED to: "
5575
5469
  star_len = len(rec_message) + len(file_path)
5576
- try:
5470
+ with suppress(Exception):
5577
5471
  terminal_size = os.get_terminal_size().columns
5578
5472
  if terminal_size > 30 and star_len > terminal_size:
5579
5473
  star_len = terminal_size
5580
- except Exception:
5581
- pass
5582
5474
  spc = "\n"
5583
5475
  if hasattr(self, "rec_print") and self.rec_print:
5584
5476
  spc = ""
@@ -5684,16 +5576,14 @@ class BaseCase(unittest.TestCase):
5684
5576
  print("Created recordings/features/steps/imported.py")
5685
5577
 
5686
5578
  def bring_active_window_to_front(self):
5687
- """Brings the active browser window to the front.
5688
- This is useful when multiple drivers are being used."""
5579
+ """Brings the active browser window to the front (on top).
5580
+ Useful when multiple drivers are being used at the same time."""
5689
5581
  self.__check_scope()
5690
- try:
5582
+ with suppress(Exception):
5691
5583
  if not self.__is_in_frame():
5692
5584
  # Only bring the window to the front if not in a frame
5693
5585
  # because the driver resets itself to default content.
5694
5586
  self.switch_to_window(self.driver.current_window_handle)
5695
- except Exception:
5696
- pass
5697
5587
 
5698
5588
  def bring_to_front(self, selector, by="css selector"):
5699
5589
  """Updates the Z-index of a page element to bring it into view.
@@ -5723,7 +5613,7 @@ class BaseCase(unittest.TestCase):
5723
5613
  def highlight_click(
5724
5614
  self, selector, by="css selector", loops=3, scroll=True, timeout=None,
5725
5615
  ):
5726
- """Highlights the element and then clicks it."""
5616
+ """Highlights the element, and then clicks it."""
5727
5617
  self.__check_scope()
5728
5618
  if not timeout:
5729
5619
  timeout = settings.SMALL_TIMEOUT
@@ -5782,10 +5672,8 @@ class BaseCase(unittest.TestCase):
5782
5672
  if not loops:
5783
5673
  loops = settings.HIGHLIGHTS
5784
5674
  if scroll and self.browser != "safari":
5785
- try:
5675
+ with suppress(Exception):
5786
5676
  self.__slow_scroll_to_element(element)
5787
- except Exception:
5788
- pass
5789
5677
  if self.highlights:
5790
5678
  loops = self.highlights
5791
5679
  if self.browser == "ie":
@@ -5815,7 +5703,7 @@ class BaseCase(unittest.TestCase):
5815
5703
  self, selector, by="css selector", loops=None, scroll=True
5816
5704
  ):
5817
5705
  """This method uses fancy JavaScript to highlight an element.
5818
- (Commonly used during Demo Mode automatically)"""
5706
+ (Automatically using in S_e_l_e_n_i_u_m_B_a_s_e Demo Mode)"""
5819
5707
  self.__check_scope()
5820
5708
  selector, by = self.__recalculate_selector(selector, by, xp_ok=False)
5821
5709
  element = self.wait_for_element_visible(
@@ -5935,14 +5823,12 @@ class BaseCase(unittest.TestCase):
5935
5823
  count = 0
5936
5824
  elements = self.find_elements(selector, by=by)
5937
5825
  for element in elements:
5938
- try:
5826
+ with suppress(Exception):
5939
5827
  if element.is_displayed():
5940
5828
  self.__highlight_element(
5941
5829
  element, loops=loops, scroll=scroll
5942
5830
  )
5943
5831
  count += 1
5944
- except Exception:
5945
- pass
5946
5832
  if limit > 0 and count >= limit:
5947
5833
  break
5948
5834
 
@@ -6189,10 +6075,8 @@ class BaseCase(unittest.TestCase):
6189
6075
  time_stamp = 0
6190
6076
  action = ["", "", "", time_stamp]
6191
6077
  pre_action_url = None
6192
- try:
6078
+ with suppress(Exception):
6193
6079
  pre_action_url = self.driver.current_url
6194
- except Exception:
6195
- pass
6196
6080
  pre_window_count = len(self.driver.window_handles)
6197
6081
  if self.recorder_mode and not self.__dont_record_js_click:
6198
6082
  time_stamp = self.execute_script("return Date.now();")
@@ -6294,10 +6178,8 @@ class BaseCase(unittest.TestCase):
6294
6178
  # If a click closes the active window,
6295
6179
  # switch to the last one if it exists.
6296
6180
  self.switch_to_window(-1)
6297
- try:
6181
+ with suppress(Exception):
6298
6182
  self.wait_for_ready_state_complete()
6299
- except Exception:
6300
- pass
6301
6183
  self.__demo_mode_pause_if_active()
6302
6184
 
6303
6185
  def js_click_if_present(self, selector, by="css selector", timeout=0):
@@ -6309,10 +6191,8 @@ class BaseCase(unittest.TestCase):
6309
6191
  if self.is_element_present(selector, by=by):
6310
6192
  self.js_click(selector, by=by)
6311
6193
  elif timeout > 0:
6312
- try:
6194
+ with suppress(Exception):
6313
6195
  self.wait_for_element_present(selector, by=by, timeout=timeout)
6314
- except Exception:
6315
- pass
6316
6196
  if self.is_element_present(selector, by=by):
6317
6197
  self.js_click(selector, by=by)
6318
6198
 
@@ -6325,10 +6205,8 @@ class BaseCase(unittest.TestCase):
6325
6205
  if self.is_element_visible(selector, by=by):
6326
6206
  self.js_click(selector, by=by)
6327
6207
  elif timeout > 0:
6328
- try:
6208
+ with suppress(Exception):
6329
6209
  self.wait_for_element_visible(selector, by=by, timeout=timeout)
6330
- except Exception:
6331
- pass
6332
6210
  if self.is_element_visible(selector, by=by):
6333
6211
  self.js_click(selector, by=by)
6334
6212
 
@@ -6421,13 +6299,11 @@ class BaseCase(unittest.TestCase):
6421
6299
  """Hide the first element on the page that matches the selector."""
6422
6300
  self.__check_scope()
6423
6301
  element = None
6424
- try:
6302
+ with suppress(Exception):
6425
6303
  self.wait_for_element_visible("body", timeout=1.5)
6426
6304
  element = self.wait_for_element_present(
6427
6305
  selector, by=by, timeout=0.5
6428
6306
  )
6429
- except Exception:
6430
- pass
6431
6307
  selector, by = self.__recalculate_selector(selector, by)
6432
6308
  css_selector = self.convert_to_css_selector(selector, by=by)
6433
6309
  if ":contains(" in css_selector and element:
@@ -6453,10 +6329,8 @@ class BaseCase(unittest.TestCase):
6453
6329
  def hide_elements(self, selector, by="css selector"):
6454
6330
  """Hide all elements on the page that match the selector."""
6455
6331
  self.__check_scope()
6456
- try:
6332
+ with suppress(Exception):
6457
6333
  self.wait_for_element_visible("body", timeout=1.5)
6458
- except Exception:
6459
- pass
6460
6334
  selector, by = self.__recalculate_selector(selector, by)
6461
6335
  css_selector = self.convert_to_css_selector(selector, by=by)
6462
6336
  if ":contains(" in css_selector:
@@ -6479,11 +6353,9 @@ class BaseCase(unittest.TestCase):
6479
6353
  """Show the first element on the page that matches the selector."""
6480
6354
  self.__check_scope()
6481
6355
  element = None
6482
- try:
6356
+ with suppress(Exception):
6483
6357
  self.wait_for_element_visible("body", timeout=1.5)
6484
6358
  element = self.wait_for_element_present(selector, by=by, timeout=1)
6485
- except Exception:
6486
- pass
6487
6359
  selector, by = self.__recalculate_selector(selector, by)
6488
6360
  css_selector = self.convert_to_css_selector(selector, by=by)
6489
6361
  if ":contains(" in css_selector and element:
@@ -6509,10 +6381,8 @@ class BaseCase(unittest.TestCase):
6509
6381
  def show_elements(self, selector, by="css selector"):
6510
6382
  """Show all elements on the page that match the selector."""
6511
6383
  self.__check_scope()
6512
- try:
6384
+ with suppress(Exception):
6513
6385
  self.wait_for_element_visible("body", timeout=1.5)
6514
- except Exception:
6515
- pass
6516
6386
  selector, by = self.__recalculate_selector(selector, by)
6517
6387
  css_selector = self.convert_to_css_selector(selector, by=by)
6518
6388
  if ":contains(" in css_selector:
@@ -6535,13 +6405,11 @@ class BaseCase(unittest.TestCase):
6535
6405
  """Remove the first element on the page that matches the selector."""
6536
6406
  self.__check_scope()
6537
6407
  element = None
6538
- try:
6408
+ with suppress(Exception):
6539
6409
  self.wait_for_element_visible("body", timeout=1.5)
6540
6410
  element = self.wait_for_element_present(
6541
6411
  selector, by=by, timeout=0.5
6542
6412
  )
6543
- except Exception:
6544
- pass
6545
6413
  selector, by = self.__recalculate_selector(selector, by)
6546
6414
  css_selector = self.convert_to_css_selector(selector, by=by)
6547
6415
  if ":contains(" in css_selector and element:
@@ -6567,10 +6435,8 @@ class BaseCase(unittest.TestCase):
6567
6435
  def remove_elements(self, selector, by="css selector"):
6568
6436
  """Remove all elements on the page that match the selector."""
6569
6437
  self.__check_scope()
6570
- try:
6438
+ with suppress(Exception):
6571
6439
  self.wait_for_element_visible("body", timeout=1.5)
6572
- except Exception:
6573
- pass
6574
6440
  selector, by = self.__recalculate_selector(selector, by)
6575
6441
  css_selector = self.convert_to_css_selector(selector, by=by)
6576
6442
  if ":contains(" in css_selector:
@@ -6635,10 +6501,8 @@ class BaseCase(unittest.TestCase):
6635
6501
  $elements[index].setAttribute('class', new_class);}"""
6636
6502
  % css_selector
6637
6503
  )
6638
- try:
6504
+ with suppress(Exception):
6639
6505
  self.execute_script(script)
6640
- except Exception:
6641
- pass
6642
6506
  if self.recorder_mode and self.__current_url_is_recordable():
6643
6507
  if self.get_session_storage_item("pause_recorder") == "no":
6644
6508
  time_stamp = self.execute_script("return Date.now();")
@@ -6656,10 +6520,8 @@ class BaseCase(unittest.TestCase):
6656
6520
  self.is_chromium()
6657
6521
  and self.driver.current_url.startswith("http")
6658
6522
  ):
6659
- try:
6523
+ with suppress(Exception):
6660
6524
  self.driver.execute_script("window.onbeforeunload=null;")
6661
- except Exception:
6662
- pass
6663
6525
 
6664
6526
  def get_domain_url(self, url):
6665
6527
  self.__check_scope()
@@ -6675,12 +6537,10 @@ class BaseCase(unittest.TestCase):
6675
6537
  from bs4 import BeautifulSoup
6676
6538
 
6677
6539
  if not source:
6678
- try:
6540
+ with suppress(Exception):
6679
6541
  self.wait_for_element_visible(
6680
6542
  "body", timeout=settings.MINI_TIMEOUT
6681
6543
  )
6682
- except Exception:
6683
- pass
6684
6544
  source = self.get_page_source()
6685
6545
  return BeautifulSoup(source, "html.parser")
6686
6546
 
@@ -6693,11 +6553,9 @@ class BaseCase(unittest.TestCase):
6693
6553
  time.sleep(0.08)
6694
6554
  if self.undetectable:
6695
6555
  time.sleep(0.02)
6696
- try:
6556
+ with suppress(Exception):
6697
6557
  self.wait_for_element_present("body", timeout=1.5)
6698
6558
  self.wait_for_element_visible("body", timeout=1.5)
6699
- except Exception:
6700
- pass
6701
6559
  if self.__needs_minimum_wait():
6702
6560
  time.sleep(0.25)
6703
6561
  if self.undetectable:
@@ -6911,12 +6769,7 @@ class BaseCase(unittest.TestCase):
6911
6769
  try:
6912
6770
  from pdfminer.high_level import extract_text
6913
6771
  except Exception:
6914
- if not sys.version_info >= (3, 8):
6915
- shared_utils.pip_install(
6916
- "pdfminer.six", version="20221105"
6917
- )
6918
- else:
6919
- shared_utils.pip_install("pdfminer.six")
6772
+ shared_utils.pip_install("pdfminer.six")
6920
6773
  from pdfminer.high_level import extract_text
6921
6774
  if not password:
6922
6775
  password = ""
@@ -7036,10 +6889,8 @@ class BaseCase(unittest.TestCase):
7036
6889
  if len(folder) < 1:
7037
6890
  raise Exception("Minimum folder name length = 1.")
7038
6891
  if not os.path.exists(folder):
7039
- try:
6892
+ with suppress(Exception):
7040
6893
  os.makedirs(folder)
7041
- except Exception:
7042
- pass
7043
6894
 
7044
6895
  def choose_file(
7045
6896
  self, selector, file_path, by="css selector", timeout=None
@@ -7079,10 +6930,8 @@ class BaseCase(unittest.TestCase):
7079
6930
  self.__scroll_to_element(element, selector, by)
7080
6931
  pre_action_url = None
7081
6932
  if self.demo_mode:
7082
- try:
6933
+ with suppress(Exception):
7083
6934
  pre_action_url = self.driver.current_url
7084
- except Exception:
7085
- pass
7086
6935
  if self.recorder_mode and self.__current_url_is_recordable():
7087
6936
  if self.get_session_storage_item("pause_recorder") == "no":
7088
6937
  time_stamp = self.execute_script("return Date.now();")
@@ -7370,10 +7219,8 @@ class BaseCase(unittest.TestCase):
7370
7219
  Those paths are usually the same. (browser-dependent)."""
7371
7220
  if self.is_downloaded_file_present(file, browser=browser):
7372
7221
  file_path = self.get_path_of_downloaded_file(file, browser=browser)
7373
- try:
7222
+ with suppress(Exception):
7374
7223
  os.remove(file_path)
7375
- except Exception:
7376
- pass
7377
7224
 
7378
7225
  def delete_downloaded_file(self, file, browser=False):
7379
7226
  """Same as self.delete_downloaded_file_if_present()
@@ -7390,10 +7237,8 @@ class BaseCase(unittest.TestCase):
7390
7237
  Those paths are usually the same. (browser-dependent)."""
7391
7238
  if self.is_downloaded_file_present(file, browser=browser):
7392
7239
  file_path = self.get_path_of_downloaded_file(file, browser=browser)
7393
- try:
7240
+ with suppress(Exception):
7394
7241
  os.remove(file_path)
7395
- except Exception:
7396
- pass
7397
7242
 
7398
7243
  def assert_downloaded_file(self, file, timeout=None, browser=False):
7399
7244
  """Asserts that the file exists in SeleniumBase's [Downloads Folder].
@@ -7450,13 +7295,11 @@ class BaseCase(unittest.TestCase):
7450
7295
  self.__extra_actions.append(action)
7451
7296
  if self.demo_mode:
7452
7297
  messenger_post = "<b>ASSERT DOWNLOADED FILE</b>: [%s]" % file
7453
- try:
7298
+ with suppress(Exception):
7454
7299
  js_utils.activate_jquery(self.driver)
7455
7300
  js_utils.post_messenger_success_message(
7456
7301
  self.driver, messenger_post, self.message_duration
7457
7302
  )
7458
- except Exception:
7459
- pass
7460
7303
 
7461
7304
  def assert_downloaded_file_regex(self, regex, timeout=None, browser=False):
7462
7305
  """Assert the filename regex exists in SeleniumBase's Downloads Folder.
@@ -7505,13 +7348,11 @@ class BaseCase(unittest.TestCase):
7505
7348
  messenger_post = (
7506
7349
  "<b>ASSERT DOWNLOADED FILE REGEX</b>: [%s]" % regex
7507
7350
  )
7508
- try:
7351
+ with suppress(Exception):
7509
7352
  js_utils.activate_jquery(self.driver)
7510
7353
  js_utils.post_messenger_success_message(
7511
7354
  self.driver, messenger_post, self.message_duration
7512
7355
  )
7513
- except Exception:
7514
- pass
7515
7356
 
7516
7357
  def assert_data_in_downloaded_file(
7517
7358
  self, data, file, timeout=None, browser=False
@@ -7530,37 +7371,37 @@ class BaseCase(unittest.TestCase):
7530
7371
 
7531
7372
  def assert_true(self, expr, msg=None):
7532
7373
  """Asserts that the expression is True.
7533
- Will raise an exception if the statement if False."""
7374
+ Raises an exception if the statement if False."""
7534
7375
  self.assertTrue(expr, msg=msg)
7535
7376
 
7536
7377
  def assert_false(self, expr, msg=None):
7537
7378
  """Asserts that the expression is False.
7538
- Will raise an exception if the statement if True."""
7379
+ Raises an exception if the statement if True."""
7539
7380
  self.assertFalse(expr, msg=msg)
7540
7381
 
7541
7382
  def assert_equal(self, first, second, msg=None):
7542
7383
  """Asserts that the two values are equal.
7543
- Will raise an exception if the values are not equal."""
7384
+ Raises an exception if the values are not equal."""
7544
7385
  self.assertEqual(first, second, msg=msg)
7545
7386
 
7546
7387
  def assert_not_equal(self, first, second, msg=None):
7547
7388
  """Asserts that the two values are not equal.
7548
- Will raise an exception if the values are equal."""
7389
+ Raises an exception if the values are equal."""
7549
7390
  self.assertNotEqual(first, second, msg=msg)
7550
7391
 
7551
7392
  def assert_in(self, first, second, msg=None):
7552
7393
  """Asserts that the first string is in the second string.
7553
- Will raise an exception if the first string is not in the second."""
7394
+ Raises an exception if the first string is not in the second."""
7554
7395
  self.assertIn(first, second, msg=msg)
7555
7396
 
7556
7397
  def assert_not_in(self, first, second, msg=None):
7557
7398
  """Asserts that the first string is not in the second string.
7558
- Will raise an exception if the first string is in the second string."""
7399
+ Raises an exception if the first string is in the second string."""
7559
7400
  self.assertNotIn(first, second, msg=msg)
7560
7401
 
7561
7402
  def assert_raises(self, *args, **kwargs):
7562
7403
  """Asserts that the following block of code raises an exception.
7563
- Will raise an exception if the block of code has no exception.
7404
+ Raises an exception if the block of code has no exception.
7564
7405
  Usage Example =>
7565
7406
  # Verify that the expected exception is raised.
7566
7407
  with self.assert_raises(Exception):
@@ -8180,17 +8021,15 @@ class BaseCase(unittest.TestCase):
8180
8021
  else:
8181
8022
  if the_type == "range" and ":contains\\(" not in css_selector:
8182
8023
  # Some input sliders need a mouse event to trigger listeners.
8183
- try:
8024
+ with suppress(Exception):
8184
8025
  mouse_move_script = (
8185
8026
  """m_elm = document.querySelector('%s');"""
8186
8027
  """m_evt = new Event('mousemove');"""
8187
8028
  """m_elm.dispatchEvent(m_evt);""" % css_selector
8188
8029
  )
8189
8030
  self.execute_script(mouse_move_script)
8190
- except Exception:
8191
- pass
8192
8031
  elif the_type == "range" and ":contains\\(" in css_selector:
8193
- try:
8032
+ with suppress(Exception):
8194
8033
  element = self.wait_for_element_present(
8195
8034
  original_selector, by=by, timeout=1
8196
8035
  )
@@ -8200,8 +8039,6 @@ class BaseCase(unittest.TestCase):
8200
8039
  """m_elm.dispatchEvent(m_evt);"""
8201
8040
  )
8202
8041
  self.execute_script(mouse_move_script, element)
8203
- except Exception:
8204
- pass
8205
8042
  self.__demo_mode_pause_if_active()
8206
8043
  if not self.demo_mode and not self.slow_mode:
8207
8044
  if self.__needs_minimum_wait():
@@ -8221,13 +8058,11 @@ class BaseCase(unittest.TestCase):
8221
8058
  text = self.__get_type_checked_text(text)
8222
8059
  self.set_value(selector, text, by=by, timeout=timeout)
8223
8060
  if not text.endswith("\n"):
8224
- try:
8061
+ with suppress(Exception):
8225
8062
  element = page_actions.wait_for_element_present(
8226
8063
  self.driver, selector, by, timeout=0.2
8227
8064
  )
8228
8065
  element.send_keys(" " + Keys.BACK_SPACE)
8229
- except Exception:
8230
- pass
8231
8066
 
8232
8067
  def js_type(self, selector, text, by="css selector", timeout=None):
8233
8068
  """Same as self.js_update_text()
@@ -8347,13 +8182,11 @@ class BaseCase(unittest.TestCase):
8347
8182
  )
8348
8183
  element.send_keys(Keys.RETURN)
8349
8184
  else:
8350
- try:
8185
+ with suppress(Exception):
8351
8186
  element = self.wait_for_element_present(
8352
8187
  original_selector, by=original_by, timeout=0.2
8353
8188
  )
8354
8189
  element.send_keys(" " + Keys.BACK_SPACE)
8355
- except Exception:
8356
- pass
8357
8190
  self.__demo_mode_pause_if_active()
8358
8191
 
8359
8192
  def jquery_type(self, selector, text, by="css selector", timeout=None):
@@ -8530,10 +8363,8 @@ class BaseCase(unittest.TestCase):
8530
8363
  def get_recorded_console_logs(self):
8531
8364
  """Get console logs recorded after "start_recording_console_logs()"."""
8532
8365
  logs = []
8533
- try:
8366
+ with suppress(Exception):
8534
8367
  logs = self.execute_script("return console.logs;")
8535
- except Exception:
8536
- pass
8537
8368
  return logs
8538
8369
 
8539
8370
  ############
@@ -8916,7 +8747,7 @@ class BaseCase(unittest.TestCase):
8916
8747
  self, selector, by="css selector", timeout=None
8917
8748
  ):
8918
8749
  """Same as self.assert_element_absent()
8919
- Will raise an exception if the element stays present.
8750
+ Raises an exception if the element stays present.
8920
8751
  A hidden element counts as a present element, which fails this assert.
8921
8752
  If you want to assert that elements are hidden instead of nonexistent,
8922
8753
  use assert_element_not_visible() instead.
@@ -8978,10 +8809,8 @@ class BaseCase(unittest.TestCase):
8978
8809
  """This method raises an exception if the active window is closed.
8979
8810
  (This provides a much cleaner exception message in this situation.)"""
8980
8811
  active_window = None
8981
- try:
8812
+ with suppress(Exception):
8982
8813
  active_window = self.driver.current_window_handle # Fails if None
8983
- except Exception:
8984
- pass
8985
8814
  if not active_window:
8986
8815
  raise NoSuchWindowException("Active window was already closed!")
8987
8816
 
@@ -8995,10 +8824,8 @@ class BaseCase(unittest.TestCase):
8995
8824
  """
8996
8825
  if hasattr(sb_config, "_multithreaded") and sb_config._multithreaded:
8997
8826
  if not isinstance(msg, str):
8998
- try:
8827
+ with suppress(Exception):
8999
8828
  msg = str(msg)
9000
- except Exception:
9001
- pass
9002
8829
  sys.stderr.write(msg + "\n")
9003
8830
  else:
9004
8831
  print(msg)
@@ -9412,7 +9239,7 @@ class BaseCase(unittest.TestCase):
9412
9239
 
9413
9240
  def assert_element(self, selector, by="css selector", timeout=None):
9414
9241
  """Similar to wait_for_element_visible(), but returns nothing.
9415
- As above, will raise an exception if nothing can be found.
9242
+ As above, raises an exception if nothing can be found.
9416
9243
  Returns True if successful. Default timeout = SMALL_TIMEOUT."""
9417
9244
  self.__check_scope()
9418
9245
  if not timeout:
@@ -9452,7 +9279,7 @@ class BaseCase(unittest.TestCase):
9452
9279
  self, selector, by="css selector", timeout=None
9453
9280
  ):
9454
9281
  """Same as self.assert_element()
9455
- As above, will raise an exception if nothing can be found."""
9282
+ As above, raises an exception if nothing can be found."""
9456
9283
  self.__check_scope()
9457
9284
  if not timeout:
9458
9285
  timeout = settings.SMALL_TIMEOUT
@@ -9678,6 +9505,7 @@ class BaseCase(unittest.TestCase):
9678
9505
  """Similar to wait_for_text_visible()
9679
9506
  Raises an exception if the element or the text is not found.
9680
9507
  The text only needs to be a subset within the complete text.
9508
+ The text can be a string or a list/tuple of text substrings.
9681
9509
  Returns True if successful. Default timeout = SMALL_TIMEOUT."""
9682
9510
  self.__check_scope()
9683
9511
  if not timeout:
@@ -9686,26 +9514,45 @@ class BaseCase(unittest.TestCase):
9686
9514
  timeout = self.__get_new_timeout(timeout)
9687
9515
  original_selector = selector
9688
9516
  selector, by = self.__recalculate_selector(selector, by)
9689
- if self.__is_shadow_selector(selector):
9517
+ if isinstance(text, (list, tuple)):
9518
+ text_list = text
9519
+ for _text in text_list:
9520
+ self.wait_for_text_visible(
9521
+ _text, selector, by=by, timeout=timeout
9522
+ )
9523
+ if self.demo_mode:
9524
+ a_t = "ASSERT TEXT"
9525
+ i_n = "in"
9526
+ if self._language != "English":
9527
+ from seleniumbase.fixtures.words import SD
9528
+
9529
+ a_t = SD.translate_assert_text(self._language)
9530
+ i_n = SD.translate_in(self._language)
9531
+ messenger_post = "<b>%s</b>: {%s} %s %s: %s" % (
9532
+ a_t, _text, i_n, by.upper(), selector
9533
+ )
9534
+ self.__highlight_with_assert_success(
9535
+ messenger_post, selector, by
9536
+ )
9537
+ elif self.__is_shadow_selector(selector):
9690
9538
  self.__assert_shadow_text_visible(text, selector, timeout)
9691
9539
  return True
9692
- self.wait_for_text_visible(text, selector, by=by, timeout=timeout)
9693
- if self.demo_mode:
9694
- a_t = "ASSERT TEXT"
9695
- i_n = "in"
9696
- if self._language != "English":
9697
- from seleniumbase.fixtures.words import SD
9540
+ else:
9541
+ self.wait_for_text_visible(text, selector, by=by, timeout=timeout)
9542
+ if self.demo_mode:
9543
+ a_t = "ASSERT TEXT"
9544
+ i_n = "in"
9545
+ if self._language != "English":
9546
+ from seleniumbase.fixtures.words import SD
9698
9547
 
9699
- a_t = SD.translate_assert_text(self._language)
9700
- i_n = SD.translate_in(self._language)
9701
- messenger_post = "<b>%s</b>: {%s} %s %s: %s" % (
9702
- a_t,
9703
- text,
9704
- i_n,
9705
- by.upper(),
9706
- selector,
9707
- )
9708
- self.__highlight_with_assert_success(messenger_post, selector, by)
9548
+ a_t = SD.translate_assert_text(self._language)
9549
+ i_n = SD.translate_in(self._language)
9550
+ messenger_post = "<b>%s</b>: {%s} %s %s: %s" % (
9551
+ a_t, text, i_n, by.upper(), selector
9552
+ )
9553
+ self.__highlight_with_assert_success(
9554
+ messenger_post, selector, by
9555
+ )
9709
9556
  if self.recorder_mode and self.__current_url_is_recordable():
9710
9557
  if self.get_session_storage_item("pause_recorder") == "no":
9711
9558
  if by == By.XPATH:
@@ -9747,11 +9594,7 @@ class BaseCase(unittest.TestCase):
9747
9594
  a_t = SD.translate_assert_exact_text(self._language)
9748
9595
  i_n = SD.translate_in(self._language)
9749
9596
  messenger_post = "<b>%s</b>: {%s} %s %s: %s" % (
9750
- a_t,
9751
- text,
9752
- i_n,
9753
- by.upper(),
9754
- selector,
9597
+ a_t, text, i_n, by.upper(), selector
9755
9598
  )
9756
9599
  self.__highlight_with_assert_success(messenger_post, selector, by)
9757
9600
  if self.recorder_mode and self.__current_url_is_recordable():
@@ -9791,10 +9634,7 @@ class BaseCase(unittest.TestCase):
9791
9634
  a_t = SD.translate_assert_non_empty_text(self._language)
9792
9635
  i_n = SD.translate_in(self._language)
9793
9636
  messenger_post = "<b>%s</b> %s %s: %s" % (
9794
- a_t,
9795
- i_n,
9796
- by.upper(),
9797
- selector,
9637
+ a_t, i_n, by.upper(), selector
9798
9638
  )
9799
9639
  self.__highlight_with_assert_success(messenger_post, selector, by)
9800
9640
  if self.recorder_mode and self.__current_url_is_recordable():
@@ -9889,7 +9729,7 @@ class BaseCase(unittest.TestCase):
9889
9729
 
9890
9730
  def assert_link_text(self, link_text, timeout=None):
9891
9731
  """Similar to wait_for_link_text_visible(), but returns nothing.
9892
- As above, will raise an exception if nothing can be found.
9732
+ As above, raises an exception if nothing can be found.
9893
9733
  Returns True if successful. Default timeout = SMALL_TIMEOUT."""
9894
9734
  self.__check_scope()
9895
9735
  if not timeout:
@@ -9938,7 +9778,7 @@ class BaseCase(unittest.TestCase):
9938
9778
 
9939
9779
  def assert_partial_link_text(self, partial_link_text, timeout=None):
9940
9780
  """Similar to wait_for_partial_link_text(), but returns nothing.
9941
- As above, will raise an exception if nothing can be found.
9781
+ As above, raises an exception if nothing can be found.
9942
9782
  Returns True if successful. Default timeout = SMALL_TIMEOUT."""
9943
9783
  self.__check_scope()
9944
9784
  if not timeout:
@@ -9984,7 +9824,7 @@ class BaseCase(unittest.TestCase):
9984
9824
 
9985
9825
  def assert_element_absent(self, selector, by="css selector", timeout=None):
9986
9826
  """Similar to wait_for_element_absent()
9987
- As above, will raise an exception if the element stays present.
9827
+ As above, raises an exception if the element stays present.
9988
9828
  A hidden element counts as a present element, which fails this assert.
9989
9829
  If you want to assert that elements are hidden instead of nonexistent,
9990
9830
  use assert_element_not_visible() instead.
@@ -10025,7 +9865,7 @@ class BaseCase(unittest.TestCase):
10025
9865
  self, selector, by="css selector", timeout=None
10026
9866
  ):
10027
9867
  """Similar to wait_for_element_not_visible()
10028
- As above, will raise an exception if the element stays visible.
9868
+ As above, raises an exception if the element stays visible.
10029
9869
  Returns True if successful. Default timeout = SMALL_TIMEOUT."""
10030
9870
  self.__check_scope()
10031
9871
  if not timeout:
@@ -10341,7 +10181,7 @@ class BaseCase(unittest.TestCase):
10341
10181
  countdown_on = True
10342
10182
  countdown = 3
10343
10183
  minified_exception += line + "\n"
10344
- elif line.startswith("+") or line.startswith("-"):
10184
+ elif line.startswith(("+", "-")):
10345
10185
  minified_exception += line + "\n"
10346
10186
  elif line.startswith("?"):
10347
10187
  minified_exception += line + "\n"
@@ -10390,8 +10230,6 @@ class BaseCase(unittest.TestCase):
10390
10230
  shutil.copy(latest_png_path, latest_copy_path)
10391
10231
  if len(self.__visual_baseline_copies) != 1:
10392
10232
  return # Skip the rest when deferred visual asserts are used
10393
- from seleniumbase.core import visual_helper
10394
-
10395
10233
  the_html = visual_helper.get_sbs_html()
10396
10234
  file_path = os.path.join(test_logpath, constants.SideBySide.HTML_FILE)
10397
10235
  out_file = codecs.open(file_path, "w+", encoding="utf-8")
@@ -10478,12 +10316,10 @@ class BaseCase(unittest.TestCase):
10478
10316
  self.check_window(name="github_page", level=2)
10479
10317
  self.check_window(name="wikipedia_page", level=3) """
10480
10318
  self.wait_for_ready_state_complete()
10481
- try:
10319
+ with suppress(Exception):
10482
10320
  self.wait_for_element_visible(
10483
10321
  "body", timeout=settings.MINI_TIMEOUT
10484
10322
  )
10485
- except Exception:
10486
- pass
10487
10323
  if self.__needs_minimum_wait():
10488
10324
  time.sleep(0.08)
10489
10325
  if level == "0":
@@ -10509,7 +10345,6 @@ class BaseCase(unittest.TestCase):
10509
10345
  if not name or len(name) < 1:
10510
10346
  name = "default"
10511
10347
  name = str(name)
10512
- from seleniumbase.core import visual_helper
10513
10348
 
10514
10349
  visual_helper.visual_baseline_folder_setup()
10515
10350
  baseline_dir = constants.VisualBaseline.STORAGE_FOLDER
@@ -10792,14 +10627,12 @@ class BaseCase(unittest.TestCase):
10792
10627
  if self.timeout_multiplier and timeout == settings.MINI_TIMEOUT:
10793
10628
  timeout = self.__get_new_timeout(timeout)
10794
10629
  self.__deferred_assert_count += 1
10795
- try:
10630
+ with suppress(Exception):
10796
10631
  url = self.get_current_url()
10797
10632
  if url == self.__last_url_of_deferred_assert:
10798
10633
  timeout = 0.6 # Was already on page (full wait not needed)
10799
10634
  else:
10800
10635
  self.__last_url_of_deferred_assert = url
10801
- except Exception:
10802
- pass
10803
10636
  if self.recorder_mode and self.__current_url_is_recordable():
10804
10637
  if self.get_session_storage_item("pause_recorder") == "no":
10805
10638
  time_stamp = self.execute_script("return Date.now();")
@@ -10829,14 +10662,12 @@ class BaseCase(unittest.TestCase):
10829
10662
  if self.timeout_multiplier and timeout == settings.MINI_TIMEOUT:
10830
10663
  timeout = self.__get_new_timeout(timeout)
10831
10664
  self.__deferred_assert_count += 1
10832
- try:
10665
+ with suppress(Exception):
10833
10666
  url = self.get_current_url()
10834
10667
  if url == self.__last_url_of_deferred_assert:
10835
10668
  timeout = 0.6 # Was already on page (full wait not needed)
10836
10669
  else:
10837
10670
  self.__last_url_of_deferred_assert = url
10838
- except Exception:
10839
- pass
10840
10671
  if self.recorder_mode and self.__current_url_is_recordable():
10841
10672
  if self.get_session_storage_item("pause_recorder") == "no":
10842
10673
  time_stamp = self.execute_script("return Date.now();")
@@ -10866,14 +10697,12 @@ class BaseCase(unittest.TestCase):
10866
10697
  if self.timeout_multiplier and timeout == settings.MINI_TIMEOUT:
10867
10698
  timeout = self.__get_new_timeout(timeout)
10868
10699
  self.__deferred_assert_count += 1
10869
- try:
10700
+ with suppress(Exception):
10870
10701
  url = self.get_current_url()
10871
10702
  if url == self.__last_url_of_deferred_assert:
10872
10703
  timeout = 0.6 # Was already on page (full wait not needed)
10873
10704
  else:
10874
10705
  self.__last_url_of_deferred_assert = url
10875
- except Exception:
10876
- pass
10877
10706
  if self.recorder_mode and self.__current_url_is_recordable():
10878
10707
  if self.get_session_storage_item("pause_recorder") == "no":
10879
10708
  time_stamp = self.execute_script("return Date.now();")
@@ -10904,14 +10733,12 @@ class BaseCase(unittest.TestCase):
10904
10733
  if self.timeout_multiplier and timeout == settings.MINI_TIMEOUT:
10905
10734
  timeout = self.__get_new_timeout(timeout)
10906
10735
  self.__deferred_assert_count += 1
10907
- try:
10736
+ with suppress(Exception):
10908
10737
  url = self.get_current_url()
10909
10738
  if url == self.__last_url_of_deferred_assert:
10910
10739
  timeout = 0.6 # Was already on page (full wait not needed)
10911
10740
  else:
10912
10741
  self.__last_url_of_deferred_assert = url
10913
- except Exception:
10914
- pass
10915
10742
  if self.recorder_mode and self.__current_url_is_recordable():
10916
10743
  if self.get_session_storage_item("pause_recorder") == "no":
10917
10744
  time_stamp = self.execute_script("return Date.now();")
@@ -10948,14 +10775,12 @@ class BaseCase(unittest.TestCase):
10948
10775
  if self.timeout_multiplier and timeout == settings.MINI_TIMEOUT:
10949
10776
  timeout = self.__get_new_timeout(timeout)
10950
10777
  self.__deferred_assert_count += 1
10951
- try:
10778
+ with suppress(Exception):
10952
10779
  url = self.get_current_url()
10953
10780
  if url == self.__last_url_of_deferred_assert:
10954
10781
  timeout = 0.6 # Was already on page (full wait not needed)
10955
10782
  else:
10956
10783
  self.__last_url_of_deferred_assert = url
10957
- except Exception:
10958
- pass
10959
10784
  if self.recorder_mode and self.__current_url_is_recordable():
10960
10785
  if self.get_session_storage_item("pause_recorder") == "no":
10961
10786
  time_stamp = self.execute_script("return Date.now();")
@@ -11391,10 +11216,8 @@ class BaseCase(unittest.TestCase):
11391
11216
  if saved_presentations_folder.endswith("/"):
11392
11217
  saved_presentations_folder = saved_presentations_folder[:-1]
11393
11218
  if not os.path.exists(saved_presentations_folder):
11394
- try:
11219
+ with suppress(Exception):
11395
11220
  os.makedirs(saved_presentations_folder)
11396
- except Exception:
11397
- pass
11398
11221
  file_path = os.path.join(saved_presentations_folder, filename)
11399
11222
  out_file = codecs.open(file_path, "w+", encoding="utf-8")
11400
11223
  out_file.writelines(the_html)
@@ -11448,7 +11271,7 @@ class BaseCase(unittest.TestCase):
11448
11271
  self._presentation_slides[name].pop()
11449
11272
  self.open_html_file(file_path)
11450
11273
  presentation_folder = constants.Presentations.SAVED_FOLDER
11451
- try:
11274
+ with suppress(Exception):
11452
11275
  while (
11453
11276
  len(self.driver.window_handles) > 0
11454
11277
  and presentation_folder in self.get_current_url()
@@ -11459,8 +11282,6 @@ class BaseCase(unittest.TestCase):
11459
11282
  ):
11460
11283
  break
11461
11284
  time.sleep(0.05)
11462
- except Exception:
11463
- pass
11464
11285
 
11465
11286
  ############
11466
11287
 
@@ -12090,10 +11911,8 @@ class BaseCase(unittest.TestCase):
12090
11911
  if saved_charts_folder.endswith("/"):
12091
11912
  saved_charts_folder = saved_charts_folder[:-1]
12092
11913
  if not os.path.exists(saved_charts_folder):
12093
- try:
11914
+ with suppress(Exception):
12094
11915
  os.makedirs(saved_charts_folder)
12095
- except Exception:
12096
- pass
12097
11916
  file_path = os.path.join(saved_charts_folder, filename)
12098
11917
  out_file = codecs.open(file_path, "w+", encoding="utf-8")
12099
11918
  out_file.writelines(the_html)
@@ -12133,17 +11952,15 @@ class BaseCase(unittest.TestCase):
12133
11952
  self.open_html_file(file_path)
12134
11953
  chart_folder = constants.Charts.SAVED_FOLDER
12135
11954
  if interval == 0:
12136
- try:
11955
+ with suppress(Exception):
12137
11956
  print("\n*** Close the browser window to continue ***")
12138
11957
  # Will also continue if manually navigating to a new page
12139
11958
  while len(self.driver.window_handles) > 0 and (
12140
11959
  chart_folder in self.get_current_url()
12141
11960
  ):
12142
11961
  time.sleep(0.05)
12143
- except Exception:
12144
- pass
12145
11962
  else:
12146
- try:
11963
+ with suppress(Exception):
12147
11964
  start_ms = time.time() * 1000.0
12148
11965
  stop_ms = start_ms + (interval * 1000.0)
12149
11966
  for x in range(int(interval * 10)):
@@ -12155,8 +11972,6 @@ class BaseCase(unittest.TestCase):
12155
11972
  if chart_folder not in self.get_current_url():
12156
11973
  break
12157
11974
  time.sleep(0.1)
12158
- except Exception:
12159
- pass
12160
11975
 
12161
11976
  def extract_chart(self, chart_name=None):
12162
11977
  """Extracts the HTML from a SeleniumBase-generated chart.
@@ -12968,10 +12783,8 @@ class BaseCase(unittest.TestCase):
12968
12783
  )
12969
12784
  time.sleep(0.02)
12970
12785
  jf = "document.querySelector('.jconfirm-box').focus();"
12971
- try:
12786
+ with suppress(Exception):
12972
12787
  self.execute_script(jf)
12973
- except Exception:
12974
- pass
12975
12788
  waiting_for_response = True
12976
12789
  while waiting_for_response:
12977
12790
  time.sleep(0.05)
@@ -13043,10 +12856,8 @@ class BaseCase(unittest.TestCase):
13043
12856
  )
13044
12857
  time.sleep(0.02)
13045
12858
  jf = "document.querySelector('.jconfirm-box input.jqc_input').focus();"
13046
- try:
12859
+ with suppress(Exception):
13047
12860
  self.execute_script(jf)
13048
- except Exception:
13049
- pass
13050
12861
  waiting_for_response = True
13051
12862
  while waiting_for_response:
13052
12863
  time.sleep(0.05)
@@ -13107,10 +12918,8 @@ class BaseCase(unittest.TestCase):
13107
12918
  )
13108
12919
  time.sleep(0.02)
13109
12920
  jf = "document.querySelector('.jconfirm-box input.jqc_input').focus();"
13110
- try:
12921
+ with suppress(Exception):
13111
12922
  self.execute_script(jf)
13112
- except Exception:
13113
- pass
13114
12923
  waiting_for_response = True
13115
12924
  while waiting_for_response:
13116
12925
  time.sleep(0.05)
@@ -13185,12 +12994,10 @@ class BaseCase(unittest.TestCase):
13185
12994
  if not page_actions.is_element_clickable(
13186
12995
  self.driver, selector, by
13187
12996
  ):
13188
- try:
12997
+ with suppress(Exception):
13189
12998
  self.wait_for_element_clickable(
13190
12999
  selector, by, timeout=1.8
13191
13000
  )
13192
- except Exception:
13193
- pass
13194
13001
  # If the regular mouse-simulated click fails, do a basic JS click
13195
13002
  script = (
13196
13003
  """document.querySelector('%s').click();"""
@@ -13266,8 +13073,6 @@ class BaseCase(unittest.TestCase):
13266
13073
  timeout=None,
13267
13074
  center=None,
13268
13075
  ):
13269
- from selenium.webdriver.common.action_chains import ActionChains
13270
-
13271
13076
  self.wait_for_ready_state_complete()
13272
13077
  if self.__needs_minimum_wait():
13273
13078
  time.sleep(0.14)
@@ -13464,7 +13269,7 @@ class BaseCase(unittest.TestCase):
13464
13269
  for dropdown in matching_dropdowns:
13465
13270
  # The same class names might be used for multiple dropdowns
13466
13271
  if dropdown.is_displayed():
13467
- try:
13272
+ with suppress(Exception):
13468
13273
  try:
13469
13274
  page_actions.hover_element(
13470
13275
  self.driver,
@@ -13485,9 +13290,6 @@ class BaseCase(unittest.TestCase):
13485
13290
  timeout=0.12,
13486
13291
  )
13487
13292
  return True
13488
- except Exception:
13489
- pass
13490
-
13491
13293
  return False
13492
13294
 
13493
13295
  def __get_href_from_partial_link_text(self, link_text, hard_fail=True):
@@ -13528,7 +13330,7 @@ class BaseCase(unittest.TestCase):
13528
13330
  for dropdown in matching_dropdowns:
13529
13331
  # The same class names might be used for multiple dropdowns
13530
13332
  if dropdown.is_displayed():
13531
- try:
13333
+ with suppress(Exception):
13532
13334
  try:
13533
13335
  page_actions.hover_element(
13534
13336
  self.driver, dropdown
@@ -13550,8 +13352,6 @@ class BaseCase(unittest.TestCase):
13550
13352
  timeout=0.12,
13551
13353
  )
13552
13354
  return True
13553
- except Exception:
13554
- pass
13555
13355
  return False
13556
13356
 
13557
13357
  def __recalculate_selector(self, selector, by, xp_ok=True):
@@ -13778,7 +13578,7 @@ class BaseCase(unittest.TestCase):
13778
13578
  from sbvirtualdisplay import Display
13779
13579
  width = settings.HEADLESS_START_WIDTH
13780
13580
  height = settings.HEADLESS_START_HEIGHT
13781
- try:
13581
+ with suppress(Exception):
13782
13582
  self._xvfb_display = Display(
13783
13583
  visible=0, size=(width, height)
13784
13584
  )
@@ -13786,11 +13586,9 @@ class BaseCase(unittest.TestCase):
13786
13586
  sb_config._virtual_display = self._xvfb_display
13787
13587
  self.headless_active = True
13788
13588
  sb_config.headless_active = True
13789
- except Exception:
13790
- pass
13791
13589
 
13792
13590
  def __activate_virtual_display_as_needed(self):
13793
- """Should be needed only on Linux.
13591
+ """This is only needed on Linux.
13794
13592
  The "--xvfb" arg is still useful, as it prevents headless mode,
13795
13593
  which is the default mode on Linux unless using another arg."""
13796
13594
  if "linux" in sys.platform and (not self.headed or self.xvfb):
@@ -13802,9 +13600,13 @@ class BaseCase(unittest.TestCase):
13802
13600
  if self.undetectable and not (self.headless or self.headless2):
13803
13601
  import Xlib.display
13804
13602
  try:
13603
+ if not self._xvfb_width:
13604
+ self._xvfb_width = 1366
13605
+ if not self._xvfb_height:
13606
+ self._xvfb_height = 768
13805
13607
  self._xvfb_display = Display(
13806
13608
  visible=True,
13807
- size=(1366, 768),
13609
+ size=(self._xvfb_width, self._xvfb_height),
13808
13610
  backend="xvfb",
13809
13611
  use_xauth=True,
13810
13612
  )
@@ -13825,7 +13627,7 @@ class BaseCase(unittest.TestCase):
13825
13627
  pyautogui_is_installed = False
13826
13628
  try:
13827
13629
  import pyautogui
13828
- try:
13630
+ with suppress(Exception):
13829
13631
  use_pyautogui_ver = constants.PyAutoGUI.VER
13830
13632
  if pyautogui.__version__ != use_pyautogui_ver:
13831
13633
  del pyautogui # To get newer ver
@@ -13833,8 +13635,6 @@ class BaseCase(unittest.TestCase):
13833
13635
  "pyautogui", version=use_pyautogui_ver
13834
13636
  )
13835
13637
  import pyautogui
13836
- except Exception:
13837
- pass
13838
13638
  pyautogui_is_installed = True
13839
13639
  except Exception:
13840
13640
  message = (
@@ -14086,12 +13886,10 @@ class BaseCase(unittest.TestCase):
14086
13886
  selector, timeout=timeout, must_be_visible=True
14087
13887
  )
14088
13888
  if clear_first:
14089
- try:
13889
+ with suppress(Exception):
14090
13890
  element.clear()
14091
13891
  backspaces = Keys.BACK_SPACE * 42 # Autofill Defense
14092
13892
  element.send_keys(backspaces)
14093
- except Exception:
14094
- pass
14095
13893
  text = self.__get_type_checked_text(text)
14096
13894
  if not text.endswith("\n"):
14097
13895
  element.send_keys(text)
@@ -14107,12 +13905,10 @@ class BaseCase(unittest.TestCase):
14107
13905
  element = self.__get_shadow_element(
14108
13906
  selector, timeout=timeout, must_be_visible=True
14109
13907
  )
14110
- try:
13908
+ with suppress(Exception):
14111
13909
  element.clear()
14112
13910
  backspaces = Keys.BACK_SPACE * 42 # Autofill Defense
14113
13911
  element.send_keys(backspaces)
14114
- except Exception:
14115
- pass
14116
13912
 
14117
13913
  def __get_shadow_text(self, selector, timeout):
14118
13914
  element = self.__get_shadow_element(
@@ -14232,19 +14028,13 @@ class BaseCase(unittest.TestCase):
14232
14028
  a_t = SD.translate_assert_text(self._language)
14233
14029
  i_n = SD.translate_in(self._language)
14234
14030
  messenger_post = "<b>%s</b>: {%s} %s %s: %s" % (
14235
- a_t,
14236
- text,
14237
- i_n,
14238
- by.upper(),
14239
- selector,
14031
+ a_t, text, i_n, by.upper(), selector
14240
14032
  )
14241
- try:
14033
+ with suppress(Exception):
14242
14034
  js_utils.activate_jquery(self.driver)
14243
14035
  js_utils.post_messenger_success_message(
14244
14036
  self.driver, messenger_post, self.message_duration
14245
14037
  )
14246
- except Exception:
14247
- pass
14248
14038
 
14249
14039
  def __assert_exact_shadow_text_visible(self, text, selector, timeout):
14250
14040
  self.__wait_for_exact_shadow_text_visible(text, selector, timeout)
@@ -14258,19 +14048,13 @@ class BaseCase(unittest.TestCase):
14258
14048
  a_t = SD.translate_assert_exact_text(self._language)
14259
14049
  i_n = SD.translate_in(self._language)
14260
14050
  messenger_post = "<b>%s</b>: {%s} %s %s: %s" % (
14261
- a_t,
14262
- text,
14263
- i_n,
14264
- by.upper(),
14265
- selector,
14051
+ a_t, text, i_n, by.upper(), selector
14266
14052
  )
14267
- try:
14053
+ with suppress(Exception):
14268
14054
  js_utils.activate_jquery(self.driver)
14269
14055
  js_utils.post_messenger_success_message(
14270
14056
  self.driver, messenger_post, self.message_duration
14271
14057
  )
14272
- except Exception:
14273
- pass
14274
14058
 
14275
14059
  def __assert_non_empty_shadow_text_visible(self, selector, timeout, strip):
14276
14060
  self.__wait_for_non_empty_shadow_text_visible(selector, timeout, strip)
@@ -14284,18 +14068,13 @@ class BaseCase(unittest.TestCase):
14284
14068
  a_t = SD.translate_assert_non_empty_text(self._language)
14285
14069
  i_n = SD.translate_in(self._language)
14286
14070
  messenger_post = "<b>%s</b> %s %s: %s" % (
14287
- a_t,
14288
- i_n,
14289
- by.upper(),
14290
- selector,
14071
+ a_t, i_n, by.upper(), selector
14291
14072
  )
14292
- try:
14073
+ with suppress(Exception):
14293
14074
  js_utils.activate_jquery(self.driver)
14294
14075
  js_utils.post_messenger_success_message(
14295
14076
  self.driver, messenger_post, self.message_duration
14296
14077
  )
14297
- except Exception:
14298
- pass
14299
14078
 
14300
14079
  def __is_shadow_element_present(self, selector):
14301
14080
  try:
@@ -14447,13 +14226,11 @@ class BaseCase(unittest.TestCase):
14447
14226
 
14448
14227
  a_t = SD.translate_assert(self._language)
14449
14228
  messenger_post = "<b>%s %s</b>: %s" % (a_t, by.upper(), selector)
14450
- try:
14229
+ with suppress(Exception):
14451
14230
  js_utils.activate_jquery(self.driver)
14452
14231
  js_utils.post_messenger_success_message(
14453
14232
  self.driver, messenger_post, self.message_duration
14454
14233
  )
14455
- except Exception:
14456
- pass
14457
14234
 
14458
14235
  def __assert_shadow_element_visible(self, selector):
14459
14236
  element = self.__get_shadow_element(selector)
@@ -14468,13 +14245,11 @@ class BaseCase(unittest.TestCase):
14468
14245
 
14469
14246
  a_t = SD.translate_assert(self._language)
14470
14247
  messenger_post = "<b>%s %s</b>: %s" % (a_t, by.upper(), selector)
14471
- try:
14248
+ with suppress(Exception):
14472
14249
  js_utils.activate_jquery(self.driver)
14473
14250
  js_utils.post_messenger_success_message(
14474
14251
  self.driver, messenger_post, self.message_duration
14475
14252
  )
14476
- except Exception:
14477
- pass
14478
14253
 
14479
14254
  ############
14480
14255
 
@@ -14553,6 +14328,7 @@ class BaseCase(unittest.TestCase):
14553
14328
  sb_config.headless_active = False
14554
14329
  self.headed = sb_config.headed
14555
14330
  self.xvfb = sb_config.xvfb
14331
+ self.xvfb_metrics = sb_config.xvfb_metrics
14556
14332
  self.locale_code = sb_config.locale_code
14557
14333
  self.interval = sb_config.interval
14558
14334
  self.start_page = sb_config.start_page
@@ -14644,31 +14420,8 @@ class BaseCase(unittest.TestCase):
14644
14420
  self.use_wire = sb_config.use_wire
14645
14421
  self.external_pdf = sb_config.external_pdf
14646
14422
  self._final_debug = sb_config.final_debug
14423
+ self.window_position = sb_config.window_position
14647
14424
  self.window_size = sb_config.window_size
14648
- window_size = self.window_size
14649
- if window_size:
14650
- if window_size.count(",") != 1:
14651
- message = (
14652
- '\n\n window_size expects a "width,height" string!'
14653
- '\n (Your input was: "%s")\n' % window_size
14654
- )
14655
- raise Exception(message)
14656
- window_size = window_size.replace(" ", "")
14657
- width = None
14658
- height = None
14659
- try:
14660
- width = int(window_size.split(",")[0])
14661
- height = int(window_size.split(",")[1])
14662
- except Exception:
14663
- message = (
14664
- '\n\n Expecting integer values for "width,height"!'
14665
- '\n (window_size input was: "%s")\n' % window_size
14666
- )
14667
- raise Exception(message)
14668
- settings.CHROME_START_WIDTH = width
14669
- settings.CHROME_START_HEIGHT = height
14670
- settings.HEADLESS_START_WIDTH = width
14671
- settings.HEADLESS_START_HEIGHT = height
14672
14425
  self.maximize_option = sb_config.maximize_option
14673
14426
  self.save_screenshot_after_test = sb_config.save_screenshot
14674
14427
  self.no_screenshot_after_test = sb_config.no_screenshot
@@ -14832,9 +14585,87 @@ class BaseCase(unittest.TestCase):
14832
14585
  self.mobile_emulator = True
14833
14586
  except Exception:
14834
14587
  raise Exception(exception_string)
14588
+
14589
+ window_position = self.window_position
14590
+ if window_position:
14591
+ if window_position.count(",") != 1:
14592
+ message = (
14593
+ '\n\n window_position expects an "x,y" string!'
14594
+ '\n (Your input was: "%s")\n' % window_position
14595
+ )
14596
+ raise Exception(message)
14597
+ window_position = window_position.replace(" ", "")
14598
+ win_x = None
14599
+ win_y = None
14600
+ try:
14601
+ win_x = int(window_position.split(",")[0])
14602
+ win_y = int(window_position.split(",")[1])
14603
+ except Exception:
14604
+ message = (
14605
+ '\n\n Expecting integer values for "x,y"!'
14606
+ '\n (window_position input was: "%s")\n'
14607
+ % window_position
14608
+ )
14609
+ raise Exception(message)
14610
+ settings.WINDOW_START_X = win_x
14611
+ settings.WINDOW_START_Y = win_y
14612
+
14613
+ window_size = self.window_size
14614
+ if window_size:
14615
+ if window_size.count(",") != 1:
14616
+ message = (
14617
+ '\n\n window_size expects a "width,height" string!'
14618
+ '\n (Your input was: "%s")\n' % window_size
14619
+ )
14620
+ raise Exception(message)
14621
+ window_size = window_size.replace(" ", "")
14622
+ width = None
14623
+ height = None
14624
+ try:
14625
+ width = int(window_size.split(",")[0])
14626
+ height = int(window_size.split(",")[1])
14627
+ except Exception:
14628
+ message = (
14629
+ '\n\n Expecting integer values for "width,height"!'
14630
+ '\n (window_size input was: "%s")\n' % window_size
14631
+ )
14632
+ raise Exception(message)
14633
+ settings.CHROME_START_WIDTH = width
14634
+ settings.CHROME_START_HEIGHT = height
14635
+ settings.HEADLESS_START_WIDTH = width
14636
+ settings.HEADLESS_START_HEIGHT = height
14637
+
14638
+ if self.xvfb_metrics:
14639
+ metrics_string = self.xvfb_metrics
14640
+ metrics_string = metrics_string.replace(" ", "")
14641
+ metrics_list = metrics_string.split(",")[0:2]
14642
+ exception_string = (
14643
+ "Invalid input for xvfb_metrics!\n"
14644
+ "Expecting a comma-separated string\n"
14645
+ "with integer values for Width/Height.\n"
14646
+ 'Eg. --xvfb-metrics="1920,1080".\n'
14647
+ "(Minimum: 1024,768) (Default: 1366,768)"
14648
+ )
14649
+ if len(metrics_list) != 2:
14650
+ raise Exception(exception_string)
14651
+ try:
14652
+ self._xvfb_width = int(metrics_list[0])
14653
+ self._xvfb_height = int(metrics_list[1])
14654
+ # The minimum width,height is: 1024,768
14655
+ if self._xvfb_width < 1024:
14656
+ self._xvfb_width = 1024
14657
+ sb_config._xvfb_width = self._xvfb_width
14658
+ if self._xvfb_height < 768:
14659
+ self._xvfb_height = 768
14660
+ sb_config._xvfb_height = self._xvfb_height
14661
+ self.xvfb = True
14662
+ except Exception:
14663
+ raise Exception(exception_string)
14664
+
14835
14665
  if self.mobile_emulator and not self.user_agent:
14836
14666
  # Use a Pixel user agent by default if not specified
14837
14667
  self.user_agent = constants.Mobile.AGENT
14668
+
14838
14669
  if self.browser in ["firefox", "ie", "safari"]:
14839
14670
  # The Recorder Mode browser extension is only for Chrome/Edge.
14840
14671
  if self.recorder_mode:
@@ -14868,7 +14699,7 @@ class BaseCase(unittest.TestCase):
14868
14699
  if not hasattr(sb_config, "shared_driver"):
14869
14700
  sb_config.shared_driver = None
14870
14701
  if sb_config.shared_driver:
14871
- try:
14702
+ with suppress(Exception):
14872
14703
  self._default_driver = sb_config.shared_driver
14873
14704
  self.driver = sb_config.shared_driver
14874
14705
  self._drivers_list = [sb_config.shared_driver]
@@ -14882,12 +14713,8 @@ class BaseCase(unittest.TestCase):
14882
14713
  self.switch_to_window(0)
14883
14714
  if self._crumbs:
14884
14715
  self.wait_for_ready_state_complete()
14885
- try:
14716
+ with suppress(Exception):
14886
14717
  self.driver.delete_all_cookies()
14887
- except Exception:
14888
- pass
14889
- except Exception:
14890
- pass
14891
14718
  if self._reuse_session and sb_config.shared_driver and has_url:
14892
14719
  good_start_page = False
14893
14720
  if self.recorder_ext:
@@ -14974,10 +14801,8 @@ class BaseCase(unittest.TestCase):
14974
14801
  if self.driver.timeouts.implicit_wait > 0:
14975
14802
  self.driver.implicitly_wait(0)
14976
14803
  except Exception:
14977
- try:
14804
+ with suppress(Exception):
14978
14805
  self.driver.implicitly_wait(0)
14979
- except Exception:
14980
- pass
14981
14806
  self._default_driver = self.driver
14982
14807
  if self._reuse_session:
14983
14808
  sb_config.shared_driver = self.driver
@@ -14996,13 +14821,11 @@ class BaseCase(unittest.TestCase):
14996
14821
  self.set_time_limit(self.time_limit)
14997
14822
 
14998
14823
  # Configure the page load timeout
14999
- try:
14824
+ with suppress(Exception):
15000
14825
  if hasattr(settings, "PAGE_LOAD_TIMEOUT"):
15001
14826
  self.driver.set_page_load_timeout(settings.PAGE_LOAD_TIMEOUT)
15002
14827
  else:
15003
14828
  self.driver.set_page_load_timeout(120) # Selenium uses 300
15004
- except Exception:
15005
- pass
15006
14829
 
15007
14830
  # Set the start time for the test (in ms).
15008
14831
  # Although the pytest clock starts before setUp() begins,
@@ -15031,7 +14854,7 @@ class BaseCase(unittest.TestCase):
15031
14854
  not self.__last_page_screenshot
15032
14855
  and not self.__last_page_screenshot_png
15033
14856
  ):
15034
- try:
14857
+ with suppress(Exception):
15035
14858
  try:
15036
14859
  element = page_actions.wait_for_element_visible(
15037
14860
  self.driver,
@@ -15061,14 +14884,10 @@ class BaseCase(unittest.TestCase):
15061
14884
  element.screenshot_as_base64
15062
14885
  )
15063
14886
  except Exception:
15064
- try:
14887
+ with suppress(Exception):
15065
14888
  self.__last_page_screenshot = (
15066
14889
  self.driver.get_screenshot_as_base64()
15067
14890
  )
15068
- except Exception:
15069
- pass
15070
- except Exception:
15071
- pass
15072
14891
  if not self.__last_page_screenshot:
15073
14892
  self.__last_page_screenshot = SCREENSHOT_UNDEFINED
15074
14893
  self.__last_page_screenshot_png = SCREENSHOT_UNDEFINED
@@ -15078,12 +14897,10 @@ class BaseCase(unittest.TestCase):
15078
14897
  element.screenshot_as_png
15079
14898
  )
15080
14899
  except Exception:
15081
- try:
14900
+ with suppress(Exception):
15082
14901
  self.__last_page_screenshot_png = (
15083
14902
  self.driver.get_screenshot_as_png()
15084
14903
  )
15085
- except Exception:
15086
- pass
15087
14904
  else:
15088
14905
  import base64
15089
14906
 
@@ -15098,12 +14915,10 @@ class BaseCase(unittest.TestCase):
15098
14915
  element.screenshot_as_png
15099
14916
  )
15100
14917
  except Exception:
15101
- try:
14918
+ with suppress(Exception):
15102
14919
  self.__last_page_screenshot_png = (
15103
14920
  self.driver.get_screenshot_as_png()
15104
14921
  )
15105
- except Exception:
15106
- pass
15107
14922
  sb_config._last_page_screenshot_png = self.__last_page_screenshot_png
15108
14923
 
15109
14924
  def __set_last_page_url(self):
@@ -15155,7 +14970,6 @@ class BaseCase(unittest.TestCase):
15155
14970
  data_payload.state = state
15156
14971
  if err:
15157
14972
  import traceback
15158
-
15159
14973
  tb_string = traceback.format_exc()
15160
14974
  if "Message: " in tb_string:
15161
14975
  data_payload.message = (
@@ -15190,7 +15004,7 @@ class BaseCase(unittest.TestCase):
15190
15004
 
15191
15005
  def __add_pytest_html_extra(self):
15192
15006
  if not self.__added_pytest_html_extra:
15193
- try:
15007
+ with suppress(Exception):
15194
15008
  if self.with_selenium:
15195
15009
  if not self.__last_page_screenshot:
15196
15010
  self.__set_last_page_screenshot()
@@ -15217,8 +15031,6 @@ class BaseCase(unittest.TestCase):
15217
15031
  ):
15218
15032
  self._html_report_extra.append(extra_url)
15219
15033
  self._html_report_extra.append(extra_image)
15220
- except Exception:
15221
- pass
15222
15034
 
15223
15035
  def __delay_driver_quit(self):
15224
15036
  delay_driver_quit = False
@@ -15312,7 +15124,6 @@ class BaseCase(unittest.TestCase):
15312
15124
  context_id = None
15313
15125
  if filename == "base_case.py" or methodname == "runTest":
15314
15126
  import traceback
15315
-
15316
15127
  stack_base = traceback.format_stack()[0].split(", in ")[0]
15317
15128
  test_base = stack_base.split(", in ")[0].split(os.sep)[-1]
15318
15129
  if hasattr(self, "cm_filename") and self.cm_filename:
@@ -16034,7 +15845,14 @@ class BaseCase(unittest.TestCase):
16034
15845
  self.driver.window_handles
16035
15846
  except Exception:
16036
15847
  self.driver.connect()
16037
- self.__process_recorded_actions()
15848
+ try:
15849
+ self.__process_recorded_actions()
15850
+ except Exception as e:
15851
+ print("\n (Recorder) Code-generation exception:")
15852
+ if hasattr(e, "msg"):
15853
+ print("\n" + str(e.msg))
15854
+ else:
15855
+ print(e)
16038
15856
  self.__called_teardown = True
16039
15857
  self.__called_setup = False
16040
15858
  try:
@@ -16071,10 +15889,8 @@ class BaseCase(unittest.TestCase):
16071
15889
  try:
16072
15890
  self.driver.window_handles
16073
15891
  except Exception:
16074
- try:
15892
+ with suppress(Exception):
16075
15893
  self.driver.connect()
16076
- except Exception:
16077
- pass
16078
15894
  self.__slow_mode_pause_if_active()
16079
15895
  has_exception = self.__has_exception()
16080
15896
  sb_config._has_exception = has_exception
@@ -16264,7 +16080,6 @@ class BaseCase(unittest.TestCase):
16264
16080
  else:
16265
16081
  # (Pynose / Behave / Pure Python)
16266
16082
  if hasattr(self, "is_behave") and self.is_behave:
16267
- import colorama
16268
16083
  if sb_config.behave_scenario.status.name == "failed":
16269
16084
  has_exception = True
16270
16085
  sb_config._has_exception = True