seleniumbase 4.30.8__py3-none-any.whl → 4.31.1__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.
- sbase/__init__.py +1 -0
- seleniumbase/__init__.py +2 -3
- seleniumbase/__version__.py +1 -1
- seleniumbase/behave/behave_sb.py +59 -11
- seleniumbase/config/settings.py +4 -0
- seleniumbase/console_scripts/logo_helper.py +47 -0
- seleniumbase/console_scripts/run.py +7 -4
- seleniumbase/console_scripts/sb_behave_gui.py +5 -5
- seleniumbase/console_scripts/sb_caseplans.py +6 -6
- seleniumbase/console_scripts/sb_commander.py +5 -5
- seleniumbase/console_scripts/sb_install.py +10 -2
- seleniumbase/console_scripts/sb_recorder.py +4 -4
- seleniumbase/core/browser_launcher.py +179 -108
- seleniumbase/core/mysql.py +1 -4
- seleniumbase/core/recorder_helper.py +24 -5
- seleniumbase/core/sb_driver.py +13 -3
- seleniumbase/core/settings_parser.py +4 -0
- seleniumbase/fixtures/base_case.py +324 -493
- seleniumbase/fixtures/js_utils.py +19 -52
- seleniumbase/fixtures/page_actions.py +3 -6
- seleniumbase/fixtures/page_utils.py +18 -53
- seleniumbase/plugins/base_plugin.py +2 -3
- seleniumbase/plugins/driver_manager.py +182 -5
- seleniumbase/plugins/pytest_plugin.py +51 -23
- seleniumbase/plugins/sb_manager.py +185 -5
- seleniumbase/plugins/selenium_plugin.py +71 -8
- seleniumbase/undetected/__init__.py +13 -38
- seleniumbase/undetected/dprocess.py +4 -6
- seleniumbase/undetected/options.py +3 -6
- seleniumbase/undetected/patcher.py +2 -3
- {seleniumbase-4.30.8.dist-info → seleniumbase-4.31.1.dist-info}/METADATA +111 -125
- {seleniumbase-4.30.8.dist-info → seleniumbase-4.31.1.dist-info}/RECORD +36 -47
- {seleniumbase-4.30.8.dist-info → seleniumbase-4.31.1.dist-info}/WHEEL +1 -1
- sbase/ReadMe.txt +0 -2
- seleniumbase/ReadMe.md +0 -25
- seleniumbase/common/ReadMe.md +0 -71
- seleniumbase/console_scripts/ReadMe.md +0 -734
- seleniumbase/drivers/ReadMe.md +0 -27
- seleniumbase/extensions/ReadMe.md +0 -12
- seleniumbase/masterqa/ReadMe.md +0 -61
- seleniumbase/resources/ReadMe.md +0 -31
- seleniumbase/resources/favicon.ico +0 -0
- seleniumbase/utilities/selenium_grid/ReadMe.md +0 -84
- seleniumbase/utilities/selenium_ide/ReadMe.md +0 -111
- {seleniumbase-4.30.8.dist-info → seleniumbase-4.31.1.dist-info}/LICENSE +0 -0
- {seleniumbase-4.30.8.dist-info → seleniumbase-4.31.1.dist-info}/entry_points.txt +0 -0
- {seleniumbase-4.30.8.dist-info → seleniumbase-4.31.1.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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
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
|
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
|
-
|
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
|
-
|
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:
|
@@ -3858,6 +3771,7 @@ class BaseCase(unittest.TestCase):
|
|
3858
3771
|
log_cdp_events=None,
|
3859
3772
|
no_sandbox=None,
|
3860
3773
|
disable_gpu=None,
|
3774
|
+
headless1=None,
|
3861
3775
|
headless2=None,
|
3862
3776
|
incognito=None,
|
3863
3777
|
guest_mode=None,
|
@@ -3917,6 +3831,7 @@ class BaseCase(unittest.TestCase):
|
|
3917
3831
|
log_cdp_events - capture {"performance": "ALL", "browser": "ALL"})
|
3918
3832
|
no_sandbox - the option to enable the "No-Sandbox" feature (Chrome)
|
3919
3833
|
disable_gpu - the option to enable Chrome's "Disable GPU" feature
|
3834
|
+
headless1 - the option to use the older headless mode (Chromium)
|
3920
3835
|
headless2 - the option to use the newer headless mode (Chromium)
|
3921
3836
|
incognito - the option to enable Chrome's Incognito mode (Chrome)
|
3922
3837
|
guest_mode - the option to enable Chrome's Guest mode (Chrome)
|
@@ -4025,6 +3940,8 @@ class BaseCase(unittest.TestCase):
|
|
4025
3940
|
no_sandbox = self.no_sandbox
|
4026
3941
|
if disable_gpu is None:
|
4027
3942
|
disable_gpu = self.disable_gpu
|
3943
|
+
if headless1 is None:
|
3944
|
+
headless1 = self.headless1
|
4028
3945
|
if headless2 is None:
|
4029
3946
|
headless2 = self.headless2
|
4030
3947
|
if incognito is None:
|
@@ -4096,8 +4013,6 @@ class BaseCase(unittest.TestCase):
|
|
4096
4013
|
"Valid options = {%s}" % (browser, valid_browsers)
|
4097
4014
|
)
|
4098
4015
|
# Launch a web browser
|
4099
|
-
from seleniumbase.core import browser_launcher
|
4100
|
-
|
4101
4016
|
new_driver = browser_launcher.get_driver(
|
4102
4017
|
browser_name=browser_name,
|
4103
4018
|
headless=headless,
|
@@ -4125,6 +4040,7 @@ class BaseCase(unittest.TestCase):
|
|
4125
4040
|
log_cdp_events=log_cdp_events,
|
4126
4041
|
no_sandbox=no_sandbox,
|
4127
4042
|
disable_gpu=disable_gpu,
|
4043
|
+
headless1=headless1,
|
4128
4044
|
headless2=headless2,
|
4129
4045
|
incognito=incognito,
|
4130
4046
|
guest_mode=guest_mode,
|
@@ -4193,7 +4109,8 @@ class BaseCase(unittest.TestCase):
|
|
4193
4109
|
self.driver.maximize_window()
|
4194
4110
|
self.wait_for_ready_state_complete()
|
4195
4111
|
else:
|
4196
|
-
|
4112
|
+
with suppress(Exception):
|
4113
|
+
self.driver.set_window_size(width, height)
|
4197
4114
|
except Exception:
|
4198
4115
|
pass # Keep existing browser resolution
|
4199
4116
|
elif self.browser == "safari":
|
@@ -4204,10 +4121,8 @@ class BaseCase(unittest.TestCase):
|
|
4204
4121
|
except Exception:
|
4205
4122
|
pass # Keep existing browser resolution
|
4206
4123
|
else:
|
4207
|
-
|
4208
|
-
self.driver.set_window_rect(10,
|
4209
|
-
except Exception:
|
4210
|
-
pass
|
4124
|
+
with suppress(Exception):
|
4125
|
+
self.driver.set_window_rect(10, 46, width, height)
|
4211
4126
|
if self.start_page and len(self.start_page) >= 4:
|
4212
4127
|
if page_utils.is_valid_url(self.start_page):
|
4213
4128
|
self.open(self.start_page)
|
@@ -4655,14 +4570,17 @@ class BaseCase(unittest.TestCase):
|
|
4655
4570
|
from seleniumbase.js_code.recorder_js import recorder_js
|
4656
4571
|
|
4657
4572
|
if not self.is_chromium():
|
4573
|
+
if "linux" not in sys.platform:
|
4574
|
+
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTCYAN_EX
|
4575
|
+
c2 = colorama.Fore.BLUE + colorama.Back.LIGHTGREEN_EX
|
4576
|
+
cr = colorama.Style.RESET_ALL
|
4577
|
+
sc = c1 + "Selenium" + c2 + "Base" + cr
|
4658
4578
|
raise Exception(
|
4659
|
-
"The Recorder is
|
4579
|
+
"The %s Recorder is for Chromium only!\n"
|
4580
|
+
" (Supported browsers: Chrome and Edge)" % sc
|
4660
4581
|
)
|
4661
4582
|
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
|
-
):
|
4583
|
+
if url.startswith(("data:", "about:", "chrome:", "edge:")):
|
4666
4584
|
message = (
|
4667
4585
|
"The URL in Recorder-Mode cannot start with: "
|
4668
4586
|
'"data:", "about:", "chrome:", or "edge:"!'
|
@@ -4671,7 +4589,7 @@ class BaseCase(unittest.TestCase):
|
|
4671
4589
|
return
|
4672
4590
|
if self.recorder_ext:
|
4673
4591
|
return # The Recorder extension is already active
|
4674
|
-
|
4592
|
+
with suppress(Exception):
|
4675
4593
|
recorder_on = self.get_session_storage_item("recorder_activated")
|
4676
4594
|
if not recorder_on == "yes":
|
4677
4595
|
self.execute_script(recorder_js)
|
@@ -4680,8 +4598,6 @@ class BaseCase(unittest.TestCase):
|
|
4680
4598
|
print("\n" + message)
|
4681
4599
|
p_msg = "Recorder Mode ACTIVE.<br>[ESC]: Pause. [~`]: Resume."
|
4682
4600
|
self.post_message(p_msg, pause=False, style="error")
|
4683
|
-
except Exception:
|
4684
|
-
pass
|
4685
4601
|
|
4686
4602
|
def __current_url_is_recordable(self):
|
4687
4603
|
url = self.get_current_url()
|
@@ -4721,10 +4637,7 @@ class BaseCase(unittest.TestCase):
|
|
4721
4637
|
|
4722
4638
|
def __get_recorded_actions_on_active_tab(self):
|
4723
4639
|
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
|
-
):
|
4640
|
+
if url.startswith(("data:", "about:", "chrome:", "edge:")):
|
4728
4641
|
return []
|
4729
4642
|
self.__origins_to_save.append(self.get_origin())
|
4730
4643
|
actions = self.get_session_storage_item("recorded_actions")
|
@@ -4735,9 +4648,9 @@ class BaseCase(unittest.TestCase):
|
|
4735
4648
|
return []
|
4736
4649
|
|
4737
4650
|
def __process_recorded_actions(self):
|
4651
|
+
"""Generates code after the SeleniumBase Recorder runs."""
|
4738
4652
|
if self.driver is None:
|
4739
4653
|
return
|
4740
|
-
import colorama
|
4741
4654
|
from seleniumbase.core import recorder_helper
|
4742
4655
|
|
4743
4656
|
raw_actions = [] # All raw actions from sessionStorage
|
@@ -4939,10 +4852,7 @@ class BaseCase(unittest.TestCase):
|
|
4939
4852
|
or srt_actions[n - 1][0] == "jq_cl"
|
4940
4853
|
or srt_actions[n - 1][0] == "jq_ca"
|
4941
4854
|
):
|
4942
|
-
if (
|
4943
|
-
srt_actions[n - 1][1].startswith("input")
|
4944
|
-
or srt_actions[n - 1][1].startswith("button")
|
4945
|
-
):
|
4855
|
+
if srt_actions[n - 1][1].startswith(("input", "button")):
|
4946
4856
|
srt_actions[n][0] = "f_url"
|
4947
4857
|
elif srt_actions[n - 1][0] == "input":
|
4948
4858
|
if srt_actions[n - 1][2].endswith("\n"):
|
@@ -5290,7 +5200,6 @@ class BaseCase(unittest.TestCase):
|
|
5290
5200
|
and (filename == "base_case.py" or methodname == "runTest")
|
5291
5201
|
):
|
5292
5202
|
import traceback
|
5293
|
-
|
5294
5203
|
stack_base = traceback.format_stack()[0].split(os.sep)[-1]
|
5295
5204
|
test_base = stack_base.split(", in ")[0]
|
5296
5205
|
if hasattr(self, "cm_filename") and self.cm_filename:
|
@@ -5360,11 +5269,9 @@ class BaseCase(unittest.TestCase):
|
|
5360
5269
|
if recordings_folder.endswith("/"):
|
5361
5270
|
recordings_folder = recordings_folder[:-1]
|
5362
5271
|
if not os.path.exists(recordings_folder):
|
5363
|
-
|
5272
|
+
with suppress(Exception):
|
5364
5273
|
os.makedirs(recordings_folder)
|
5365
5274
|
sys.stdout.write("\nCreated recordings%s" % os.sep)
|
5366
|
-
except Exception:
|
5367
|
-
pass
|
5368
5275
|
|
5369
5276
|
data = []
|
5370
5277
|
data.append("")
|
@@ -5465,12 +5372,10 @@ class BaseCase(unittest.TestCase):
|
|
5465
5372
|
if not new_file:
|
5466
5373
|
rec_message = ">>> RECORDING ADDED to: "
|
5467
5374
|
star_len = len(rec_message) + len(file_path)
|
5468
|
-
|
5375
|
+
with suppress(Exception):
|
5469
5376
|
terminal_size = os.get_terminal_size().columns
|
5470
5377
|
if terminal_size > 30 and star_len > terminal_size:
|
5471
5378
|
star_len = terminal_size
|
5472
|
-
except Exception:
|
5473
|
-
pass
|
5474
5379
|
spc = "\n\n"
|
5475
5380
|
if hasattr(self, "rec_print") and self.rec_print:
|
5476
5381
|
spc = ""
|
@@ -5543,22 +5448,16 @@ class BaseCase(unittest.TestCase):
|
|
5543
5448
|
if recordings_folder.endswith("/"):
|
5544
5449
|
recordings_folder = recordings_folder[:-1]
|
5545
5450
|
if not os.path.exists(recordings_folder):
|
5546
|
-
|
5451
|
+
with suppress(Exception):
|
5547
5452
|
os.makedirs(recordings_folder)
|
5548
|
-
except Exception:
|
5549
|
-
pass
|
5550
5453
|
features_folder = os.path.join(recordings_folder, "features")
|
5551
5454
|
if not os.path.exists(features_folder):
|
5552
|
-
|
5455
|
+
with suppress(Exception):
|
5553
5456
|
os.makedirs(features_folder)
|
5554
|
-
except Exception:
|
5555
|
-
pass
|
5556
5457
|
steps_folder = os.path.join(features_folder, "steps")
|
5557
5458
|
if not os.path.exists(steps_folder):
|
5558
|
-
|
5459
|
+
with suppress(Exception):
|
5559
5460
|
os.makedirs(steps_folder)
|
5560
|
-
except Exception:
|
5561
|
-
pass
|
5562
5461
|
|
5563
5462
|
file_name = filename.split(".")[0]
|
5564
5463
|
if hasattr(self, "is_behave") and self.is_behave:
|
@@ -5573,12 +5472,10 @@ class BaseCase(unittest.TestCase):
|
|
5573
5472
|
if not new_file:
|
5574
5473
|
rec_message = ">>> RECORDING ADDED to: "
|
5575
5474
|
star_len = len(rec_message) + len(file_path)
|
5576
|
-
|
5475
|
+
with suppress(Exception):
|
5577
5476
|
terminal_size = os.get_terminal_size().columns
|
5578
5477
|
if terminal_size > 30 and star_len > terminal_size:
|
5579
5478
|
star_len = terminal_size
|
5580
|
-
except Exception:
|
5581
|
-
pass
|
5582
5479
|
spc = "\n"
|
5583
5480
|
if hasattr(self, "rec_print") and self.rec_print:
|
5584
5481
|
spc = ""
|
@@ -5684,16 +5581,14 @@ class BaseCase(unittest.TestCase):
|
|
5684
5581
|
print("Created recordings/features/steps/imported.py")
|
5685
5582
|
|
5686
5583
|
def bring_active_window_to_front(self):
|
5687
|
-
"""Brings the active browser window to the front.
|
5688
|
-
|
5584
|
+
"""Brings the active browser window to the front (on top).
|
5585
|
+
Useful when multiple drivers are being used at the same time."""
|
5689
5586
|
self.__check_scope()
|
5690
|
-
|
5587
|
+
with suppress(Exception):
|
5691
5588
|
if not self.__is_in_frame():
|
5692
5589
|
# Only bring the window to the front if not in a frame
|
5693
5590
|
# because the driver resets itself to default content.
|
5694
5591
|
self.switch_to_window(self.driver.current_window_handle)
|
5695
|
-
except Exception:
|
5696
|
-
pass
|
5697
5592
|
|
5698
5593
|
def bring_to_front(self, selector, by="css selector"):
|
5699
5594
|
"""Updates the Z-index of a page element to bring it into view.
|
@@ -5723,7 +5618,7 @@ class BaseCase(unittest.TestCase):
|
|
5723
5618
|
def highlight_click(
|
5724
5619
|
self, selector, by="css selector", loops=3, scroll=True, timeout=None,
|
5725
5620
|
):
|
5726
|
-
"""Highlights the element and then clicks it."""
|
5621
|
+
"""Highlights the element, and then clicks it."""
|
5727
5622
|
self.__check_scope()
|
5728
5623
|
if not timeout:
|
5729
5624
|
timeout = settings.SMALL_TIMEOUT
|
@@ -5782,10 +5677,8 @@ class BaseCase(unittest.TestCase):
|
|
5782
5677
|
if not loops:
|
5783
5678
|
loops = settings.HIGHLIGHTS
|
5784
5679
|
if scroll and self.browser != "safari":
|
5785
|
-
|
5680
|
+
with suppress(Exception):
|
5786
5681
|
self.__slow_scroll_to_element(element)
|
5787
|
-
except Exception:
|
5788
|
-
pass
|
5789
5682
|
if self.highlights:
|
5790
5683
|
loops = self.highlights
|
5791
5684
|
if self.browser == "ie":
|
@@ -5815,7 +5708,7 @@ class BaseCase(unittest.TestCase):
|
|
5815
5708
|
self, selector, by="css selector", loops=None, scroll=True
|
5816
5709
|
):
|
5817
5710
|
"""This method uses fancy JavaScript to highlight an element.
|
5818
|
-
(
|
5711
|
+
(Automatically using in S_e_l_e_n_i_u_m_B_a_s_e Demo Mode)"""
|
5819
5712
|
self.__check_scope()
|
5820
5713
|
selector, by = self.__recalculate_selector(selector, by, xp_ok=False)
|
5821
5714
|
element = self.wait_for_element_visible(
|
@@ -5935,14 +5828,12 @@ class BaseCase(unittest.TestCase):
|
|
5935
5828
|
count = 0
|
5936
5829
|
elements = self.find_elements(selector, by=by)
|
5937
5830
|
for element in elements:
|
5938
|
-
|
5831
|
+
with suppress(Exception):
|
5939
5832
|
if element.is_displayed():
|
5940
5833
|
self.__highlight_element(
|
5941
5834
|
element, loops=loops, scroll=scroll
|
5942
5835
|
)
|
5943
5836
|
count += 1
|
5944
|
-
except Exception:
|
5945
|
-
pass
|
5946
5837
|
if limit > 0 and count >= limit:
|
5947
5838
|
break
|
5948
5839
|
|
@@ -6189,10 +6080,8 @@ class BaseCase(unittest.TestCase):
|
|
6189
6080
|
time_stamp = 0
|
6190
6081
|
action = ["", "", "", time_stamp]
|
6191
6082
|
pre_action_url = None
|
6192
|
-
|
6083
|
+
with suppress(Exception):
|
6193
6084
|
pre_action_url = self.driver.current_url
|
6194
|
-
except Exception:
|
6195
|
-
pass
|
6196
6085
|
pre_window_count = len(self.driver.window_handles)
|
6197
6086
|
if self.recorder_mode and not self.__dont_record_js_click:
|
6198
6087
|
time_stamp = self.execute_script("return Date.now();")
|
@@ -6294,10 +6183,8 @@ class BaseCase(unittest.TestCase):
|
|
6294
6183
|
# If a click closes the active window,
|
6295
6184
|
# switch to the last one if it exists.
|
6296
6185
|
self.switch_to_window(-1)
|
6297
|
-
|
6186
|
+
with suppress(Exception):
|
6298
6187
|
self.wait_for_ready_state_complete()
|
6299
|
-
except Exception:
|
6300
|
-
pass
|
6301
6188
|
self.__demo_mode_pause_if_active()
|
6302
6189
|
|
6303
6190
|
def js_click_if_present(self, selector, by="css selector", timeout=0):
|
@@ -6309,10 +6196,8 @@ class BaseCase(unittest.TestCase):
|
|
6309
6196
|
if self.is_element_present(selector, by=by):
|
6310
6197
|
self.js_click(selector, by=by)
|
6311
6198
|
elif timeout > 0:
|
6312
|
-
|
6199
|
+
with suppress(Exception):
|
6313
6200
|
self.wait_for_element_present(selector, by=by, timeout=timeout)
|
6314
|
-
except Exception:
|
6315
|
-
pass
|
6316
6201
|
if self.is_element_present(selector, by=by):
|
6317
6202
|
self.js_click(selector, by=by)
|
6318
6203
|
|
@@ -6325,10 +6210,8 @@ class BaseCase(unittest.TestCase):
|
|
6325
6210
|
if self.is_element_visible(selector, by=by):
|
6326
6211
|
self.js_click(selector, by=by)
|
6327
6212
|
elif timeout > 0:
|
6328
|
-
|
6213
|
+
with suppress(Exception):
|
6329
6214
|
self.wait_for_element_visible(selector, by=by, timeout=timeout)
|
6330
|
-
except Exception:
|
6331
|
-
pass
|
6332
6215
|
if self.is_element_visible(selector, by=by):
|
6333
6216
|
self.js_click(selector, by=by)
|
6334
6217
|
|
@@ -6421,13 +6304,11 @@ class BaseCase(unittest.TestCase):
|
|
6421
6304
|
"""Hide the first element on the page that matches the selector."""
|
6422
6305
|
self.__check_scope()
|
6423
6306
|
element = None
|
6424
|
-
|
6307
|
+
with suppress(Exception):
|
6425
6308
|
self.wait_for_element_visible("body", timeout=1.5)
|
6426
6309
|
element = self.wait_for_element_present(
|
6427
6310
|
selector, by=by, timeout=0.5
|
6428
6311
|
)
|
6429
|
-
except Exception:
|
6430
|
-
pass
|
6431
6312
|
selector, by = self.__recalculate_selector(selector, by)
|
6432
6313
|
css_selector = self.convert_to_css_selector(selector, by=by)
|
6433
6314
|
if ":contains(" in css_selector and element:
|
@@ -6453,10 +6334,8 @@ class BaseCase(unittest.TestCase):
|
|
6453
6334
|
def hide_elements(self, selector, by="css selector"):
|
6454
6335
|
"""Hide all elements on the page that match the selector."""
|
6455
6336
|
self.__check_scope()
|
6456
|
-
|
6337
|
+
with suppress(Exception):
|
6457
6338
|
self.wait_for_element_visible("body", timeout=1.5)
|
6458
|
-
except Exception:
|
6459
|
-
pass
|
6460
6339
|
selector, by = self.__recalculate_selector(selector, by)
|
6461
6340
|
css_selector = self.convert_to_css_selector(selector, by=by)
|
6462
6341
|
if ":contains(" in css_selector:
|
@@ -6479,11 +6358,9 @@ class BaseCase(unittest.TestCase):
|
|
6479
6358
|
"""Show the first element on the page that matches the selector."""
|
6480
6359
|
self.__check_scope()
|
6481
6360
|
element = None
|
6482
|
-
|
6361
|
+
with suppress(Exception):
|
6483
6362
|
self.wait_for_element_visible("body", timeout=1.5)
|
6484
6363
|
element = self.wait_for_element_present(selector, by=by, timeout=1)
|
6485
|
-
except Exception:
|
6486
|
-
pass
|
6487
6364
|
selector, by = self.__recalculate_selector(selector, by)
|
6488
6365
|
css_selector = self.convert_to_css_selector(selector, by=by)
|
6489
6366
|
if ":contains(" in css_selector and element:
|
@@ -6509,10 +6386,8 @@ class BaseCase(unittest.TestCase):
|
|
6509
6386
|
def show_elements(self, selector, by="css selector"):
|
6510
6387
|
"""Show all elements on the page that match the selector."""
|
6511
6388
|
self.__check_scope()
|
6512
|
-
|
6389
|
+
with suppress(Exception):
|
6513
6390
|
self.wait_for_element_visible("body", timeout=1.5)
|
6514
|
-
except Exception:
|
6515
|
-
pass
|
6516
6391
|
selector, by = self.__recalculate_selector(selector, by)
|
6517
6392
|
css_selector = self.convert_to_css_selector(selector, by=by)
|
6518
6393
|
if ":contains(" in css_selector:
|
@@ -6535,13 +6410,11 @@ class BaseCase(unittest.TestCase):
|
|
6535
6410
|
"""Remove the first element on the page that matches the selector."""
|
6536
6411
|
self.__check_scope()
|
6537
6412
|
element = None
|
6538
|
-
|
6413
|
+
with suppress(Exception):
|
6539
6414
|
self.wait_for_element_visible("body", timeout=1.5)
|
6540
6415
|
element = self.wait_for_element_present(
|
6541
6416
|
selector, by=by, timeout=0.5
|
6542
6417
|
)
|
6543
|
-
except Exception:
|
6544
|
-
pass
|
6545
6418
|
selector, by = self.__recalculate_selector(selector, by)
|
6546
6419
|
css_selector = self.convert_to_css_selector(selector, by=by)
|
6547
6420
|
if ":contains(" in css_selector and element:
|
@@ -6567,10 +6440,8 @@ class BaseCase(unittest.TestCase):
|
|
6567
6440
|
def remove_elements(self, selector, by="css selector"):
|
6568
6441
|
"""Remove all elements on the page that match the selector."""
|
6569
6442
|
self.__check_scope()
|
6570
|
-
|
6443
|
+
with suppress(Exception):
|
6571
6444
|
self.wait_for_element_visible("body", timeout=1.5)
|
6572
|
-
except Exception:
|
6573
|
-
pass
|
6574
6445
|
selector, by = self.__recalculate_selector(selector, by)
|
6575
6446
|
css_selector = self.convert_to_css_selector(selector, by=by)
|
6576
6447
|
if ":contains(" in css_selector:
|
@@ -6635,10 +6506,8 @@ class BaseCase(unittest.TestCase):
|
|
6635
6506
|
$elements[index].setAttribute('class', new_class);}"""
|
6636
6507
|
% css_selector
|
6637
6508
|
)
|
6638
|
-
|
6509
|
+
with suppress(Exception):
|
6639
6510
|
self.execute_script(script)
|
6640
|
-
except Exception:
|
6641
|
-
pass
|
6642
6511
|
if self.recorder_mode and self.__current_url_is_recordable():
|
6643
6512
|
if self.get_session_storage_item("pause_recorder") == "no":
|
6644
6513
|
time_stamp = self.execute_script("return Date.now();")
|
@@ -6656,10 +6525,8 @@ class BaseCase(unittest.TestCase):
|
|
6656
6525
|
self.is_chromium()
|
6657
6526
|
and self.driver.current_url.startswith("http")
|
6658
6527
|
):
|
6659
|
-
|
6528
|
+
with suppress(Exception):
|
6660
6529
|
self.driver.execute_script("window.onbeforeunload=null;")
|
6661
|
-
except Exception:
|
6662
|
-
pass
|
6663
6530
|
|
6664
6531
|
def get_domain_url(self, url):
|
6665
6532
|
self.__check_scope()
|
@@ -6675,12 +6542,10 @@ class BaseCase(unittest.TestCase):
|
|
6675
6542
|
from bs4 import BeautifulSoup
|
6676
6543
|
|
6677
6544
|
if not source:
|
6678
|
-
|
6545
|
+
with suppress(Exception):
|
6679
6546
|
self.wait_for_element_visible(
|
6680
6547
|
"body", timeout=settings.MINI_TIMEOUT
|
6681
6548
|
)
|
6682
|
-
except Exception:
|
6683
|
-
pass
|
6684
6549
|
source = self.get_page_source()
|
6685
6550
|
return BeautifulSoup(source, "html.parser")
|
6686
6551
|
|
@@ -6693,11 +6558,9 @@ class BaseCase(unittest.TestCase):
|
|
6693
6558
|
time.sleep(0.08)
|
6694
6559
|
if self.undetectable:
|
6695
6560
|
time.sleep(0.02)
|
6696
|
-
|
6561
|
+
with suppress(Exception):
|
6697
6562
|
self.wait_for_element_present("body", timeout=1.5)
|
6698
6563
|
self.wait_for_element_visible("body", timeout=1.5)
|
6699
|
-
except Exception:
|
6700
|
-
pass
|
6701
6564
|
if self.__needs_minimum_wait():
|
6702
6565
|
time.sleep(0.25)
|
6703
6566
|
if self.undetectable:
|
@@ -6911,12 +6774,7 @@ class BaseCase(unittest.TestCase):
|
|
6911
6774
|
try:
|
6912
6775
|
from pdfminer.high_level import extract_text
|
6913
6776
|
except Exception:
|
6914
|
-
|
6915
|
-
shared_utils.pip_install(
|
6916
|
-
"pdfminer.six", version="20221105"
|
6917
|
-
)
|
6918
|
-
else:
|
6919
|
-
shared_utils.pip_install("pdfminer.six")
|
6777
|
+
shared_utils.pip_install("pdfminer.six")
|
6920
6778
|
from pdfminer.high_level import extract_text
|
6921
6779
|
if not password:
|
6922
6780
|
password = ""
|
@@ -7036,10 +6894,8 @@ class BaseCase(unittest.TestCase):
|
|
7036
6894
|
if len(folder) < 1:
|
7037
6895
|
raise Exception("Minimum folder name length = 1.")
|
7038
6896
|
if not os.path.exists(folder):
|
7039
|
-
|
6897
|
+
with suppress(Exception):
|
7040
6898
|
os.makedirs(folder)
|
7041
|
-
except Exception:
|
7042
|
-
pass
|
7043
6899
|
|
7044
6900
|
def choose_file(
|
7045
6901
|
self, selector, file_path, by="css selector", timeout=None
|
@@ -7079,10 +6935,8 @@ class BaseCase(unittest.TestCase):
|
|
7079
6935
|
self.__scroll_to_element(element, selector, by)
|
7080
6936
|
pre_action_url = None
|
7081
6937
|
if self.demo_mode:
|
7082
|
-
|
6938
|
+
with suppress(Exception):
|
7083
6939
|
pre_action_url = self.driver.current_url
|
7084
|
-
except Exception:
|
7085
|
-
pass
|
7086
6940
|
if self.recorder_mode and self.__current_url_is_recordable():
|
7087
6941
|
if self.get_session_storage_item("pause_recorder") == "no":
|
7088
6942
|
time_stamp = self.execute_script("return Date.now();")
|
@@ -7370,10 +7224,8 @@ class BaseCase(unittest.TestCase):
|
|
7370
7224
|
Those paths are usually the same. (browser-dependent)."""
|
7371
7225
|
if self.is_downloaded_file_present(file, browser=browser):
|
7372
7226
|
file_path = self.get_path_of_downloaded_file(file, browser=browser)
|
7373
|
-
|
7227
|
+
with suppress(Exception):
|
7374
7228
|
os.remove(file_path)
|
7375
|
-
except Exception:
|
7376
|
-
pass
|
7377
7229
|
|
7378
7230
|
def delete_downloaded_file(self, file, browser=False):
|
7379
7231
|
"""Same as self.delete_downloaded_file_if_present()
|
@@ -7390,10 +7242,8 @@ class BaseCase(unittest.TestCase):
|
|
7390
7242
|
Those paths are usually the same. (browser-dependent)."""
|
7391
7243
|
if self.is_downloaded_file_present(file, browser=browser):
|
7392
7244
|
file_path = self.get_path_of_downloaded_file(file, browser=browser)
|
7393
|
-
|
7245
|
+
with suppress(Exception):
|
7394
7246
|
os.remove(file_path)
|
7395
|
-
except Exception:
|
7396
|
-
pass
|
7397
7247
|
|
7398
7248
|
def assert_downloaded_file(self, file, timeout=None, browser=False):
|
7399
7249
|
"""Asserts that the file exists in SeleniumBase's [Downloads Folder].
|
@@ -7450,13 +7300,11 @@ class BaseCase(unittest.TestCase):
|
|
7450
7300
|
self.__extra_actions.append(action)
|
7451
7301
|
if self.demo_mode:
|
7452
7302
|
messenger_post = "<b>ASSERT DOWNLOADED FILE</b>: [%s]" % file
|
7453
|
-
|
7303
|
+
with suppress(Exception):
|
7454
7304
|
js_utils.activate_jquery(self.driver)
|
7455
7305
|
js_utils.post_messenger_success_message(
|
7456
7306
|
self.driver, messenger_post, self.message_duration
|
7457
7307
|
)
|
7458
|
-
except Exception:
|
7459
|
-
pass
|
7460
7308
|
|
7461
7309
|
def assert_downloaded_file_regex(self, regex, timeout=None, browser=False):
|
7462
7310
|
"""Assert the filename regex exists in SeleniumBase's Downloads Folder.
|
@@ -7505,13 +7353,11 @@ class BaseCase(unittest.TestCase):
|
|
7505
7353
|
messenger_post = (
|
7506
7354
|
"<b>ASSERT DOWNLOADED FILE REGEX</b>: [%s]" % regex
|
7507
7355
|
)
|
7508
|
-
|
7356
|
+
with suppress(Exception):
|
7509
7357
|
js_utils.activate_jquery(self.driver)
|
7510
7358
|
js_utils.post_messenger_success_message(
|
7511
7359
|
self.driver, messenger_post, self.message_duration
|
7512
7360
|
)
|
7513
|
-
except Exception:
|
7514
|
-
pass
|
7515
7361
|
|
7516
7362
|
def assert_data_in_downloaded_file(
|
7517
7363
|
self, data, file, timeout=None, browser=False
|
@@ -7530,37 +7376,37 @@ class BaseCase(unittest.TestCase):
|
|
7530
7376
|
|
7531
7377
|
def assert_true(self, expr, msg=None):
|
7532
7378
|
"""Asserts that the expression is True.
|
7533
|
-
|
7379
|
+
Raises an exception if the statement if False."""
|
7534
7380
|
self.assertTrue(expr, msg=msg)
|
7535
7381
|
|
7536
7382
|
def assert_false(self, expr, msg=None):
|
7537
7383
|
"""Asserts that the expression is False.
|
7538
|
-
|
7384
|
+
Raises an exception if the statement if True."""
|
7539
7385
|
self.assertFalse(expr, msg=msg)
|
7540
7386
|
|
7541
7387
|
def assert_equal(self, first, second, msg=None):
|
7542
7388
|
"""Asserts that the two values are equal.
|
7543
|
-
|
7389
|
+
Raises an exception if the values are not equal."""
|
7544
7390
|
self.assertEqual(first, second, msg=msg)
|
7545
7391
|
|
7546
7392
|
def assert_not_equal(self, first, second, msg=None):
|
7547
7393
|
"""Asserts that the two values are not equal.
|
7548
|
-
|
7394
|
+
Raises an exception if the values are equal."""
|
7549
7395
|
self.assertNotEqual(first, second, msg=msg)
|
7550
7396
|
|
7551
7397
|
def assert_in(self, first, second, msg=None):
|
7552
7398
|
"""Asserts that the first string is in the second string.
|
7553
|
-
|
7399
|
+
Raises an exception if the first string is not in the second."""
|
7554
7400
|
self.assertIn(first, second, msg=msg)
|
7555
7401
|
|
7556
7402
|
def assert_not_in(self, first, second, msg=None):
|
7557
7403
|
"""Asserts that the first string is not in the second string.
|
7558
|
-
|
7404
|
+
Raises an exception if the first string is in the second string."""
|
7559
7405
|
self.assertNotIn(first, second, msg=msg)
|
7560
7406
|
|
7561
7407
|
def assert_raises(self, *args, **kwargs):
|
7562
7408
|
"""Asserts that the following block of code raises an exception.
|
7563
|
-
|
7409
|
+
Raises an exception if the block of code has no exception.
|
7564
7410
|
Usage Example =>
|
7565
7411
|
# Verify that the expected exception is raised.
|
7566
7412
|
with self.assert_raises(Exception):
|
@@ -7967,6 +7813,13 @@ class BaseCase(unittest.TestCase):
|
|
7967
7813
|
"""Return True if the url is a valid url."""
|
7968
7814
|
return page_utils.is_valid_url(url)
|
7969
7815
|
|
7816
|
+
def is_alert_present(self):
|
7817
|
+
try:
|
7818
|
+
self.driver.switch_to.alert
|
7819
|
+
return True
|
7820
|
+
except Exception:
|
7821
|
+
return False
|
7822
|
+
|
7970
7823
|
def is_online(self):
|
7971
7824
|
"""Return True if connected to the Internet."""
|
7972
7825
|
return self.execute_script("return navigator.onLine;")
|
@@ -8180,17 +8033,15 @@ class BaseCase(unittest.TestCase):
|
|
8180
8033
|
else:
|
8181
8034
|
if the_type == "range" and ":contains\\(" not in css_selector:
|
8182
8035
|
# Some input sliders need a mouse event to trigger listeners.
|
8183
|
-
|
8036
|
+
with suppress(Exception):
|
8184
8037
|
mouse_move_script = (
|
8185
8038
|
"""m_elm = document.querySelector('%s');"""
|
8186
8039
|
"""m_evt = new Event('mousemove');"""
|
8187
8040
|
"""m_elm.dispatchEvent(m_evt);""" % css_selector
|
8188
8041
|
)
|
8189
8042
|
self.execute_script(mouse_move_script)
|
8190
|
-
except Exception:
|
8191
|
-
pass
|
8192
8043
|
elif the_type == "range" and ":contains\\(" in css_selector:
|
8193
|
-
|
8044
|
+
with suppress(Exception):
|
8194
8045
|
element = self.wait_for_element_present(
|
8195
8046
|
original_selector, by=by, timeout=1
|
8196
8047
|
)
|
@@ -8200,8 +8051,6 @@ class BaseCase(unittest.TestCase):
|
|
8200
8051
|
"""m_elm.dispatchEvent(m_evt);"""
|
8201
8052
|
)
|
8202
8053
|
self.execute_script(mouse_move_script, element)
|
8203
|
-
except Exception:
|
8204
|
-
pass
|
8205
8054
|
self.__demo_mode_pause_if_active()
|
8206
8055
|
if not self.demo_mode and not self.slow_mode:
|
8207
8056
|
if self.__needs_minimum_wait():
|
@@ -8221,13 +8070,11 @@ class BaseCase(unittest.TestCase):
|
|
8221
8070
|
text = self.__get_type_checked_text(text)
|
8222
8071
|
self.set_value(selector, text, by=by, timeout=timeout)
|
8223
8072
|
if not text.endswith("\n"):
|
8224
|
-
|
8073
|
+
with suppress(Exception):
|
8225
8074
|
element = page_actions.wait_for_element_present(
|
8226
8075
|
self.driver, selector, by, timeout=0.2
|
8227
8076
|
)
|
8228
8077
|
element.send_keys(" " + Keys.BACK_SPACE)
|
8229
|
-
except Exception:
|
8230
|
-
pass
|
8231
8078
|
|
8232
8079
|
def js_type(self, selector, text, by="css selector", timeout=None):
|
8233
8080
|
"""Same as self.js_update_text()
|
@@ -8347,13 +8194,11 @@ class BaseCase(unittest.TestCase):
|
|
8347
8194
|
)
|
8348
8195
|
element.send_keys(Keys.RETURN)
|
8349
8196
|
else:
|
8350
|
-
|
8197
|
+
with suppress(Exception):
|
8351
8198
|
element = self.wait_for_element_present(
|
8352
8199
|
original_selector, by=original_by, timeout=0.2
|
8353
8200
|
)
|
8354
8201
|
element.send_keys(" " + Keys.BACK_SPACE)
|
8355
|
-
except Exception:
|
8356
|
-
pass
|
8357
8202
|
self.__demo_mode_pause_if_active()
|
8358
8203
|
|
8359
8204
|
def jquery_type(self, selector, text, by="css selector", timeout=None):
|
@@ -8530,10 +8375,8 @@ class BaseCase(unittest.TestCase):
|
|
8530
8375
|
def get_recorded_console_logs(self):
|
8531
8376
|
"""Get console logs recorded after "start_recording_console_logs()"."""
|
8532
8377
|
logs = []
|
8533
|
-
|
8378
|
+
with suppress(Exception):
|
8534
8379
|
logs = self.execute_script("return console.logs;")
|
8535
|
-
except Exception:
|
8536
|
-
pass
|
8537
8380
|
return logs
|
8538
8381
|
|
8539
8382
|
############
|
@@ -8916,7 +8759,7 @@ class BaseCase(unittest.TestCase):
|
|
8916
8759
|
self, selector, by="css selector", timeout=None
|
8917
8760
|
):
|
8918
8761
|
"""Same as self.assert_element_absent()
|
8919
|
-
|
8762
|
+
Raises an exception if the element stays present.
|
8920
8763
|
A hidden element counts as a present element, which fails this assert.
|
8921
8764
|
If you want to assert that elements are hidden instead of nonexistent,
|
8922
8765
|
use assert_element_not_visible() instead.
|
@@ -8978,10 +8821,8 @@ class BaseCase(unittest.TestCase):
|
|
8978
8821
|
"""This method raises an exception if the active window is closed.
|
8979
8822
|
(This provides a much cleaner exception message in this situation.)"""
|
8980
8823
|
active_window = None
|
8981
|
-
|
8824
|
+
with suppress(Exception):
|
8982
8825
|
active_window = self.driver.current_window_handle # Fails if None
|
8983
|
-
except Exception:
|
8984
|
-
pass
|
8985
8826
|
if not active_window:
|
8986
8827
|
raise NoSuchWindowException("Active window was already closed!")
|
8987
8828
|
|
@@ -8995,10 +8836,8 @@ class BaseCase(unittest.TestCase):
|
|
8995
8836
|
"""
|
8996
8837
|
if hasattr(sb_config, "_multithreaded") and sb_config._multithreaded:
|
8997
8838
|
if not isinstance(msg, str):
|
8998
|
-
|
8839
|
+
with suppress(Exception):
|
8999
8840
|
msg = str(msg)
|
9000
|
-
except Exception:
|
9001
|
-
pass
|
9002
8841
|
sys.stderr.write(msg + "\n")
|
9003
8842
|
else:
|
9004
8843
|
print(msg)
|
@@ -9412,7 +9251,7 @@ class BaseCase(unittest.TestCase):
|
|
9412
9251
|
|
9413
9252
|
def assert_element(self, selector, by="css selector", timeout=None):
|
9414
9253
|
"""Similar to wait_for_element_visible(), but returns nothing.
|
9415
|
-
As above,
|
9254
|
+
As above, raises an exception if nothing can be found.
|
9416
9255
|
Returns True if successful. Default timeout = SMALL_TIMEOUT."""
|
9417
9256
|
self.__check_scope()
|
9418
9257
|
if not timeout:
|
@@ -9452,7 +9291,7 @@ class BaseCase(unittest.TestCase):
|
|
9452
9291
|
self, selector, by="css selector", timeout=None
|
9453
9292
|
):
|
9454
9293
|
"""Same as self.assert_element()
|
9455
|
-
As above,
|
9294
|
+
As above, raises an exception if nothing can be found."""
|
9456
9295
|
self.__check_scope()
|
9457
9296
|
if not timeout:
|
9458
9297
|
timeout = settings.SMALL_TIMEOUT
|
@@ -9678,6 +9517,7 @@ class BaseCase(unittest.TestCase):
|
|
9678
9517
|
"""Similar to wait_for_text_visible()
|
9679
9518
|
Raises an exception if the element or the text is not found.
|
9680
9519
|
The text only needs to be a subset within the complete text.
|
9520
|
+
The text can be a string or a list/tuple of text substrings.
|
9681
9521
|
Returns True if successful. Default timeout = SMALL_TIMEOUT."""
|
9682
9522
|
self.__check_scope()
|
9683
9523
|
if not timeout:
|
@@ -9686,26 +9526,45 @@ class BaseCase(unittest.TestCase):
|
|
9686
9526
|
timeout = self.__get_new_timeout(timeout)
|
9687
9527
|
original_selector = selector
|
9688
9528
|
selector, by = self.__recalculate_selector(selector, by)
|
9689
|
-
if
|
9529
|
+
if isinstance(text, (list, tuple)):
|
9530
|
+
text_list = text
|
9531
|
+
for _text in text_list:
|
9532
|
+
self.wait_for_text_visible(
|
9533
|
+
_text, selector, by=by, timeout=timeout
|
9534
|
+
)
|
9535
|
+
if self.demo_mode:
|
9536
|
+
a_t = "ASSERT TEXT"
|
9537
|
+
i_n = "in"
|
9538
|
+
if self._language != "English":
|
9539
|
+
from seleniumbase.fixtures.words import SD
|
9540
|
+
|
9541
|
+
a_t = SD.translate_assert_text(self._language)
|
9542
|
+
i_n = SD.translate_in(self._language)
|
9543
|
+
messenger_post = "<b>%s</b>: {%s} %s %s: %s" % (
|
9544
|
+
a_t, _text, i_n, by.upper(), selector
|
9545
|
+
)
|
9546
|
+
self.__highlight_with_assert_success(
|
9547
|
+
messenger_post, selector, by
|
9548
|
+
)
|
9549
|
+
elif self.__is_shadow_selector(selector):
|
9690
9550
|
self.__assert_shadow_text_visible(text, selector, timeout)
|
9691
9551
|
return True
|
9692
|
-
|
9693
|
-
|
9694
|
-
|
9695
|
-
|
9696
|
-
|
9697
|
-
|
9552
|
+
else:
|
9553
|
+
self.wait_for_text_visible(text, selector, by=by, timeout=timeout)
|
9554
|
+
if self.demo_mode:
|
9555
|
+
a_t = "ASSERT TEXT"
|
9556
|
+
i_n = "in"
|
9557
|
+
if self._language != "English":
|
9558
|
+
from seleniumbase.fixtures.words import SD
|
9698
9559
|
|
9699
|
-
|
9700
|
-
|
9701
|
-
|
9702
|
-
|
9703
|
-
|
9704
|
-
|
9705
|
-
|
9706
|
-
|
9707
|
-
)
|
9708
|
-
self.__highlight_with_assert_success(messenger_post, selector, by)
|
9560
|
+
a_t = SD.translate_assert_text(self._language)
|
9561
|
+
i_n = SD.translate_in(self._language)
|
9562
|
+
messenger_post = "<b>%s</b>: {%s} %s %s: %s" % (
|
9563
|
+
a_t, text, i_n, by.upper(), selector
|
9564
|
+
)
|
9565
|
+
self.__highlight_with_assert_success(
|
9566
|
+
messenger_post, selector, by
|
9567
|
+
)
|
9709
9568
|
if self.recorder_mode and self.__current_url_is_recordable():
|
9710
9569
|
if self.get_session_storage_item("pause_recorder") == "no":
|
9711
9570
|
if by == By.XPATH:
|
@@ -9747,11 +9606,7 @@ class BaseCase(unittest.TestCase):
|
|
9747
9606
|
a_t = SD.translate_assert_exact_text(self._language)
|
9748
9607
|
i_n = SD.translate_in(self._language)
|
9749
9608
|
messenger_post = "<b>%s</b>: {%s} %s %s: %s" % (
|
9750
|
-
a_t,
|
9751
|
-
text,
|
9752
|
-
i_n,
|
9753
|
-
by.upper(),
|
9754
|
-
selector,
|
9609
|
+
a_t, text, i_n, by.upper(), selector
|
9755
9610
|
)
|
9756
9611
|
self.__highlight_with_assert_success(messenger_post, selector, by)
|
9757
9612
|
if self.recorder_mode and self.__current_url_is_recordable():
|
@@ -9791,10 +9646,7 @@ class BaseCase(unittest.TestCase):
|
|
9791
9646
|
a_t = SD.translate_assert_non_empty_text(self._language)
|
9792
9647
|
i_n = SD.translate_in(self._language)
|
9793
9648
|
messenger_post = "<b>%s</b> %s %s: %s" % (
|
9794
|
-
a_t,
|
9795
|
-
i_n,
|
9796
|
-
by.upper(),
|
9797
|
-
selector,
|
9649
|
+
a_t, i_n, by.upper(), selector
|
9798
9650
|
)
|
9799
9651
|
self.__highlight_with_assert_success(messenger_post, selector, by)
|
9800
9652
|
if self.recorder_mode and self.__current_url_is_recordable():
|
@@ -9889,7 +9741,7 @@ class BaseCase(unittest.TestCase):
|
|
9889
9741
|
|
9890
9742
|
def assert_link_text(self, link_text, timeout=None):
|
9891
9743
|
"""Similar to wait_for_link_text_visible(), but returns nothing.
|
9892
|
-
As above,
|
9744
|
+
As above, raises an exception if nothing can be found.
|
9893
9745
|
Returns True if successful. Default timeout = SMALL_TIMEOUT."""
|
9894
9746
|
self.__check_scope()
|
9895
9747
|
if not timeout:
|
@@ -9938,7 +9790,7 @@ class BaseCase(unittest.TestCase):
|
|
9938
9790
|
|
9939
9791
|
def assert_partial_link_text(self, partial_link_text, timeout=None):
|
9940
9792
|
"""Similar to wait_for_partial_link_text(), but returns nothing.
|
9941
|
-
As above,
|
9793
|
+
As above, raises an exception if nothing can be found.
|
9942
9794
|
Returns True if successful. Default timeout = SMALL_TIMEOUT."""
|
9943
9795
|
self.__check_scope()
|
9944
9796
|
if not timeout:
|
@@ -9984,7 +9836,7 @@ class BaseCase(unittest.TestCase):
|
|
9984
9836
|
|
9985
9837
|
def assert_element_absent(self, selector, by="css selector", timeout=None):
|
9986
9838
|
"""Similar to wait_for_element_absent()
|
9987
|
-
As above,
|
9839
|
+
As above, raises an exception if the element stays present.
|
9988
9840
|
A hidden element counts as a present element, which fails this assert.
|
9989
9841
|
If you want to assert that elements are hidden instead of nonexistent,
|
9990
9842
|
use assert_element_not_visible() instead.
|
@@ -10025,7 +9877,7 @@ class BaseCase(unittest.TestCase):
|
|
10025
9877
|
self, selector, by="css selector", timeout=None
|
10026
9878
|
):
|
10027
9879
|
"""Similar to wait_for_element_not_visible()
|
10028
|
-
As above,
|
9880
|
+
As above, raises an exception if the element stays visible.
|
10029
9881
|
Returns True if successful. Default timeout = SMALL_TIMEOUT."""
|
10030
9882
|
self.__check_scope()
|
10031
9883
|
if not timeout:
|
@@ -10341,7 +10193,7 @@ class BaseCase(unittest.TestCase):
|
|
10341
10193
|
countdown_on = True
|
10342
10194
|
countdown = 3
|
10343
10195
|
minified_exception += line + "\n"
|
10344
|
-
elif line.startswith("+"
|
10196
|
+
elif line.startswith(("+", "-")):
|
10345
10197
|
minified_exception += line + "\n"
|
10346
10198
|
elif line.startswith("?"):
|
10347
10199
|
minified_exception += line + "\n"
|
@@ -10390,8 +10242,6 @@ class BaseCase(unittest.TestCase):
|
|
10390
10242
|
shutil.copy(latest_png_path, latest_copy_path)
|
10391
10243
|
if len(self.__visual_baseline_copies) != 1:
|
10392
10244
|
return # Skip the rest when deferred visual asserts are used
|
10393
|
-
from seleniumbase.core import visual_helper
|
10394
|
-
|
10395
10245
|
the_html = visual_helper.get_sbs_html()
|
10396
10246
|
file_path = os.path.join(test_logpath, constants.SideBySide.HTML_FILE)
|
10397
10247
|
out_file = codecs.open(file_path, "w+", encoding="utf-8")
|
@@ -10478,12 +10328,10 @@ class BaseCase(unittest.TestCase):
|
|
10478
10328
|
self.check_window(name="github_page", level=2)
|
10479
10329
|
self.check_window(name="wikipedia_page", level=3) """
|
10480
10330
|
self.wait_for_ready_state_complete()
|
10481
|
-
|
10331
|
+
with suppress(Exception):
|
10482
10332
|
self.wait_for_element_visible(
|
10483
10333
|
"body", timeout=settings.MINI_TIMEOUT
|
10484
10334
|
)
|
10485
|
-
except Exception:
|
10486
|
-
pass
|
10487
10335
|
if self.__needs_minimum_wait():
|
10488
10336
|
time.sleep(0.08)
|
10489
10337
|
if level == "0":
|
@@ -10509,7 +10357,6 @@ class BaseCase(unittest.TestCase):
|
|
10509
10357
|
if not name or len(name) < 1:
|
10510
10358
|
name = "default"
|
10511
10359
|
name = str(name)
|
10512
|
-
from seleniumbase.core import visual_helper
|
10513
10360
|
|
10514
10361
|
visual_helper.visual_baseline_folder_setup()
|
10515
10362
|
baseline_dir = constants.VisualBaseline.STORAGE_FOLDER
|
@@ -10792,14 +10639,12 @@ class BaseCase(unittest.TestCase):
|
|
10792
10639
|
if self.timeout_multiplier and timeout == settings.MINI_TIMEOUT:
|
10793
10640
|
timeout = self.__get_new_timeout(timeout)
|
10794
10641
|
self.__deferred_assert_count += 1
|
10795
|
-
|
10642
|
+
with suppress(Exception):
|
10796
10643
|
url = self.get_current_url()
|
10797
10644
|
if url == self.__last_url_of_deferred_assert:
|
10798
10645
|
timeout = 0.6 # Was already on page (full wait not needed)
|
10799
10646
|
else:
|
10800
10647
|
self.__last_url_of_deferred_assert = url
|
10801
|
-
except Exception:
|
10802
|
-
pass
|
10803
10648
|
if self.recorder_mode and self.__current_url_is_recordable():
|
10804
10649
|
if self.get_session_storage_item("pause_recorder") == "no":
|
10805
10650
|
time_stamp = self.execute_script("return Date.now();")
|
@@ -10829,14 +10674,12 @@ class BaseCase(unittest.TestCase):
|
|
10829
10674
|
if self.timeout_multiplier and timeout == settings.MINI_TIMEOUT:
|
10830
10675
|
timeout = self.__get_new_timeout(timeout)
|
10831
10676
|
self.__deferred_assert_count += 1
|
10832
|
-
|
10677
|
+
with suppress(Exception):
|
10833
10678
|
url = self.get_current_url()
|
10834
10679
|
if url == self.__last_url_of_deferred_assert:
|
10835
10680
|
timeout = 0.6 # Was already on page (full wait not needed)
|
10836
10681
|
else:
|
10837
10682
|
self.__last_url_of_deferred_assert = url
|
10838
|
-
except Exception:
|
10839
|
-
pass
|
10840
10683
|
if self.recorder_mode and self.__current_url_is_recordable():
|
10841
10684
|
if self.get_session_storage_item("pause_recorder") == "no":
|
10842
10685
|
time_stamp = self.execute_script("return Date.now();")
|
@@ -10866,14 +10709,12 @@ class BaseCase(unittest.TestCase):
|
|
10866
10709
|
if self.timeout_multiplier and timeout == settings.MINI_TIMEOUT:
|
10867
10710
|
timeout = self.__get_new_timeout(timeout)
|
10868
10711
|
self.__deferred_assert_count += 1
|
10869
|
-
|
10712
|
+
with suppress(Exception):
|
10870
10713
|
url = self.get_current_url()
|
10871
10714
|
if url == self.__last_url_of_deferred_assert:
|
10872
10715
|
timeout = 0.6 # Was already on page (full wait not needed)
|
10873
10716
|
else:
|
10874
10717
|
self.__last_url_of_deferred_assert = url
|
10875
|
-
except Exception:
|
10876
|
-
pass
|
10877
10718
|
if self.recorder_mode and self.__current_url_is_recordable():
|
10878
10719
|
if self.get_session_storage_item("pause_recorder") == "no":
|
10879
10720
|
time_stamp = self.execute_script("return Date.now();")
|
@@ -10904,14 +10745,12 @@ class BaseCase(unittest.TestCase):
|
|
10904
10745
|
if self.timeout_multiplier and timeout == settings.MINI_TIMEOUT:
|
10905
10746
|
timeout = self.__get_new_timeout(timeout)
|
10906
10747
|
self.__deferred_assert_count += 1
|
10907
|
-
|
10748
|
+
with suppress(Exception):
|
10908
10749
|
url = self.get_current_url()
|
10909
10750
|
if url == self.__last_url_of_deferred_assert:
|
10910
10751
|
timeout = 0.6 # Was already on page (full wait not needed)
|
10911
10752
|
else:
|
10912
10753
|
self.__last_url_of_deferred_assert = url
|
10913
|
-
except Exception:
|
10914
|
-
pass
|
10915
10754
|
if self.recorder_mode and self.__current_url_is_recordable():
|
10916
10755
|
if self.get_session_storage_item("pause_recorder") == "no":
|
10917
10756
|
time_stamp = self.execute_script("return Date.now();")
|
@@ -10948,14 +10787,12 @@ class BaseCase(unittest.TestCase):
|
|
10948
10787
|
if self.timeout_multiplier and timeout == settings.MINI_TIMEOUT:
|
10949
10788
|
timeout = self.__get_new_timeout(timeout)
|
10950
10789
|
self.__deferred_assert_count += 1
|
10951
|
-
|
10790
|
+
with suppress(Exception):
|
10952
10791
|
url = self.get_current_url()
|
10953
10792
|
if url == self.__last_url_of_deferred_assert:
|
10954
10793
|
timeout = 0.6 # Was already on page (full wait not needed)
|
10955
10794
|
else:
|
10956
10795
|
self.__last_url_of_deferred_assert = url
|
10957
|
-
except Exception:
|
10958
|
-
pass
|
10959
10796
|
if self.recorder_mode and self.__current_url_is_recordable():
|
10960
10797
|
if self.get_session_storage_item("pause_recorder") == "no":
|
10961
10798
|
time_stamp = self.execute_script("return Date.now();")
|
@@ -11391,10 +11228,8 @@ class BaseCase(unittest.TestCase):
|
|
11391
11228
|
if saved_presentations_folder.endswith("/"):
|
11392
11229
|
saved_presentations_folder = saved_presentations_folder[:-1]
|
11393
11230
|
if not os.path.exists(saved_presentations_folder):
|
11394
|
-
|
11231
|
+
with suppress(Exception):
|
11395
11232
|
os.makedirs(saved_presentations_folder)
|
11396
|
-
except Exception:
|
11397
|
-
pass
|
11398
11233
|
file_path = os.path.join(saved_presentations_folder, filename)
|
11399
11234
|
out_file = codecs.open(file_path, "w+", encoding="utf-8")
|
11400
11235
|
out_file.writelines(the_html)
|
@@ -11448,7 +11283,7 @@ class BaseCase(unittest.TestCase):
|
|
11448
11283
|
self._presentation_slides[name].pop()
|
11449
11284
|
self.open_html_file(file_path)
|
11450
11285
|
presentation_folder = constants.Presentations.SAVED_FOLDER
|
11451
|
-
|
11286
|
+
with suppress(Exception):
|
11452
11287
|
while (
|
11453
11288
|
len(self.driver.window_handles) > 0
|
11454
11289
|
and presentation_folder in self.get_current_url()
|
@@ -11459,8 +11294,6 @@ class BaseCase(unittest.TestCase):
|
|
11459
11294
|
):
|
11460
11295
|
break
|
11461
11296
|
time.sleep(0.05)
|
11462
|
-
except Exception:
|
11463
|
-
pass
|
11464
11297
|
|
11465
11298
|
############
|
11466
11299
|
|
@@ -12090,10 +11923,8 @@ class BaseCase(unittest.TestCase):
|
|
12090
11923
|
if saved_charts_folder.endswith("/"):
|
12091
11924
|
saved_charts_folder = saved_charts_folder[:-1]
|
12092
11925
|
if not os.path.exists(saved_charts_folder):
|
12093
|
-
|
11926
|
+
with suppress(Exception):
|
12094
11927
|
os.makedirs(saved_charts_folder)
|
12095
|
-
except Exception:
|
12096
|
-
pass
|
12097
11928
|
file_path = os.path.join(saved_charts_folder, filename)
|
12098
11929
|
out_file = codecs.open(file_path, "w+", encoding="utf-8")
|
12099
11930
|
out_file.writelines(the_html)
|
@@ -12133,17 +11964,15 @@ class BaseCase(unittest.TestCase):
|
|
12133
11964
|
self.open_html_file(file_path)
|
12134
11965
|
chart_folder = constants.Charts.SAVED_FOLDER
|
12135
11966
|
if interval == 0:
|
12136
|
-
|
11967
|
+
with suppress(Exception):
|
12137
11968
|
print("\n*** Close the browser window to continue ***")
|
12138
11969
|
# Will also continue if manually navigating to a new page
|
12139
11970
|
while len(self.driver.window_handles) > 0 and (
|
12140
11971
|
chart_folder in self.get_current_url()
|
12141
11972
|
):
|
12142
11973
|
time.sleep(0.05)
|
12143
|
-
except Exception:
|
12144
|
-
pass
|
12145
11974
|
else:
|
12146
|
-
|
11975
|
+
with suppress(Exception):
|
12147
11976
|
start_ms = time.time() * 1000.0
|
12148
11977
|
stop_ms = start_ms + (interval * 1000.0)
|
12149
11978
|
for x in range(int(interval * 10)):
|
@@ -12155,8 +11984,6 @@ class BaseCase(unittest.TestCase):
|
|
12155
11984
|
if chart_folder not in self.get_current_url():
|
12156
11985
|
break
|
12157
11986
|
time.sleep(0.1)
|
12158
|
-
except Exception:
|
12159
|
-
pass
|
12160
11987
|
|
12161
11988
|
def extract_chart(self, chart_name=None):
|
12162
11989
|
"""Extracts the HTML from a SeleniumBase-generated chart.
|
@@ -12968,10 +12795,8 @@ class BaseCase(unittest.TestCase):
|
|
12968
12795
|
)
|
12969
12796
|
time.sleep(0.02)
|
12970
12797
|
jf = "document.querySelector('.jconfirm-box').focus();"
|
12971
|
-
|
12798
|
+
with suppress(Exception):
|
12972
12799
|
self.execute_script(jf)
|
12973
|
-
except Exception:
|
12974
|
-
pass
|
12975
12800
|
waiting_for_response = True
|
12976
12801
|
while waiting_for_response:
|
12977
12802
|
time.sleep(0.05)
|
@@ -13043,10 +12868,8 @@ class BaseCase(unittest.TestCase):
|
|
13043
12868
|
)
|
13044
12869
|
time.sleep(0.02)
|
13045
12870
|
jf = "document.querySelector('.jconfirm-box input.jqc_input').focus();"
|
13046
|
-
|
12871
|
+
with suppress(Exception):
|
13047
12872
|
self.execute_script(jf)
|
13048
|
-
except Exception:
|
13049
|
-
pass
|
13050
12873
|
waiting_for_response = True
|
13051
12874
|
while waiting_for_response:
|
13052
12875
|
time.sleep(0.05)
|
@@ -13107,10 +12930,8 @@ class BaseCase(unittest.TestCase):
|
|
13107
12930
|
)
|
13108
12931
|
time.sleep(0.02)
|
13109
12932
|
jf = "document.querySelector('.jconfirm-box input.jqc_input').focus();"
|
13110
|
-
|
12933
|
+
with suppress(Exception):
|
13111
12934
|
self.execute_script(jf)
|
13112
|
-
except Exception:
|
13113
|
-
pass
|
13114
12935
|
waiting_for_response = True
|
13115
12936
|
while waiting_for_response:
|
13116
12937
|
time.sleep(0.05)
|
@@ -13185,12 +13006,10 @@ class BaseCase(unittest.TestCase):
|
|
13185
13006
|
if not page_actions.is_element_clickable(
|
13186
13007
|
self.driver, selector, by
|
13187
13008
|
):
|
13188
|
-
|
13009
|
+
with suppress(Exception):
|
13189
13010
|
self.wait_for_element_clickable(
|
13190
13011
|
selector, by, timeout=1.8
|
13191
13012
|
)
|
13192
|
-
except Exception:
|
13193
|
-
pass
|
13194
13013
|
# If the regular mouse-simulated click fails, do a basic JS click
|
13195
13014
|
script = (
|
13196
13015
|
"""document.querySelector('%s').click();"""
|
@@ -13266,8 +13085,6 @@ class BaseCase(unittest.TestCase):
|
|
13266
13085
|
timeout=None,
|
13267
13086
|
center=None,
|
13268
13087
|
):
|
13269
|
-
from selenium.webdriver.common.action_chains import ActionChains
|
13270
|
-
|
13271
13088
|
self.wait_for_ready_state_complete()
|
13272
13089
|
if self.__needs_minimum_wait():
|
13273
13090
|
time.sleep(0.14)
|
@@ -13464,7 +13281,7 @@ class BaseCase(unittest.TestCase):
|
|
13464
13281
|
for dropdown in matching_dropdowns:
|
13465
13282
|
# The same class names might be used for multiple dropdowns
|
13466
13283
|
if dropdown.is_displayed():
|
13467
|
-
|
13284
|
+
with suppress(Exception):
|
13468
13285
|
try:
|
13469
13286
|
page_actions.hover_element(
|
13470
13287
|
self.driver,
|
@@ -13485,9 +13302,6 @@ class BaseCase(unittest.TestCase):
|
|
13485
13302
|
timeout=0.12,
|
13486
13303
|
)
|
13487
13304
|
return True
|
13488
|
-
except Exception:
|
13489
|
-
pass
|
13490
|
-
|
13491
13305
|
return False
|
13492
13306
|
|
13493
13307
|
def __get_href_from_partial_link_text(self, link_text, hard_fail=True):
|
@@ -13528,7 +13342,7 @@ class BaseCase(unittest.TestCase):
|
|
13528
13342
|
for dropdown in matching_dropdowns:
|
13529
13343
|
# The same class names might be used for multiple dropdowns
|
13530
13344
|
if dropdown.is_displayed():
|
13531
|
-
|
13345
|
+
with suppress(Exception):
|
13532
13346
|
try:
|
13533
13347
|
page_actions.hover_element(
|
13534
13348
|
self.driver, dropdown
|
@@ -13550,8 +13364,6 @@ class BaseCase(unittest.TestCase):
|
|
13550
13364
|
timeout=0.12,
|
13551
13365
|
)
|
13552
13366
|
return True
|
13553
|
-
except Exception:
|
13554
|
-
pass
|
13555
13367
|
return False
|
13556
13368
|
|
13557
13369
|
def __recalculate_selector(self, selector, by, xp_ok=True):
|
@@ -13778,7 +13590,7 @@ class BaseCase(unittest.TestCase):
|
|
13778
13590
|
from sbvirtualdisplay import Display
|
13779
13591
|
width = settings.HEADLESS_START_WIDTH
|
13780
13592
|
height = settings.HEADLESS_START_HEIGHT
|
13781
|
-
|
13593
|
+
with suppress(Exception):
|
13782
13594
|
self._xvfb_display = Display(
|
13783
13595
|
visible=0, size=(width, height)
|
13784
13596
|
)
|
@@ -13786,11 +13598,9 @@ class BaseCase(unittest.TestCase):
|
|
13786
13598
|
sb_config._virtual_display = self._xvfb_display
|
13787
13599
|
self.headless_active = True
|
13788
13600
|
sb_config.headless_active = True
|
13789
|
-
except Exception:
|
13790
|
-
pass
|
13791
13601
|
|
13792
13602
|
def __activate_virtual_display_as_needed(self):
|
13793
|
-
"""
|
13603
|
+
"""This is only needed on Linux.
|
13794
13604
|
The "--xvfb" arg is still useful, as it prevents headless mode,
|
13795
13605
|
which is the default mode on Linux unless using another arg."""
|
13796
13606
|
if "linux" in sys.platform and (not self.headed or self.xvfb):
|
@@ -13802,9 +13612,13 @@ class BaseCase(unittest.TestCase):
|
|
13802
13612
|
if self.undetectable and not (self.headless or self.headless2):
|
13803
13613
|
import Xlib.display
|
13804
13614
|
try:
|
13615
|
+
if not self._xvfb_width:
|
13616
|
+
self._xvfb_width = 1366
|
13617
|
+
if not self._xvfb_height:
|
13618
|
+
self._xvfb_height = 768
|
13805
13619
|
self._xvfb_display = Display(
|
13806
13620
|
visible=True,
|
13807
|
-
size=(
|
13621
|
+
size=(self._xvfb_width, self._xvfb_height),
|
13808
13622
|
backend="xvfb",
|
13809
13623
|
use_xauth=True,
|
13810
13624
|
)
|
@@ -13825,7 +13639,7 @@ class BaseCase(unittest.TestCase):
|
|
13825
13639
|
pyautogui_is_installed = False
|
13826
13640
|
try:
|
13827
13641
|
import pyautogui
|
13828
|
-
|
13642
|
+
with suppress(Exception):
|
13829
13643
|
use_pyautogui_ver = constants.PyAutoGUI.VER
|
13830
13644
|
if pyautogui.__version__ != use_pyautogui_ver:
|
13831
13645
|
del pyautogui # To get newer ver
|
@@ -13833,8 +13647,6 @@ class BaseCase(unittest.TestCase):
|
|
13833
13647
|
"pyautogui", version=use_pyautogui_ver
|
13834
13648
|
)
|
13835
13649
|
import pyautogui
|
13836
|
-
except Exception:
|
13837
|
-
pass
|
13838
13650
|
pyautogui_is_installed = True
|
13839
13651
|
except Exception:
|
13840
13652
|
message = (
|
@@ -14086,12 +13898,10 @@ class BaseCase(unittest.TestCase):
|
|
14086
13898
|
selector, timeout=timeout, must_be_visible=True
|
14087
13899
|
)
|
14088
13900
|
if clear_first:
|
14089
|
-
|
13901
|
+
with suppress(Exception):
|
14090
13902
|
element.clear()
|
14091
13903
|
backspaces = Keys.BACK_SPACE * 42 # Autofill Defense
|
14092
13904
|
element.send_keys(backspaces)
|
14093
|
-
except Exception:
|
14094
|
-
pass
|
14095
13905
|
text = self.__get_type_checked_text(text)
|
14096
13906
|
if not text.endswith("\n"):
|
14097
13907
|
element.send_keys(text)
|
@@ -14107,12 +13917,10 @@ class BaseCase(unittest.TestCase):
|
|
14107
13917
|
element = self.__get_shadow_element(
|
14108
13918
|
selector, timeout=timeout, must_be_visible=True
|
14109
13919
|
)
|
14110
|
-
|
13920
|
+
with suppress(Exception):
|
14111
13921
|
element.clear()
|
14112
13922
|
backspaces = Keys.BACK_SPACE * 42 # Autofill Defense
|
14113
13923
|
element.send_keys(backspaces)
|
14114
|
-
except Exception:
|
14115
|
-
pass
|
14116
13924
|
|
14117
13925
|
def __get_shadow_text(self, selector, timeout):
|
14118
13926
|
element = self.__get_shadow_element(
|
@@ -14232,19 +14040,13 @@ class BaseCase(unittest.TestCase):
|
|
14232
14040
|
a_t = SD.translate_assert_text(self._language)
|
14233
14041
|
i_n = SD.translate_in(self._language)
|
14234
14042
|
messenger_post = "<b>%s</b>: {%s} %s %s: %s" % (
|
14235
|
-
a_t,
|
14236
|
-
text,
|
14237
|
-
i_n,
|
14238
|
-
by.upper(),
|
14239
|
-
selector,
|
14043
|
+
a_t, text, i_n, by.upper(), selector
|
14240
14044
|
)
|
14241
|
-
|
14045
|
+
with suppress(Exception):
|
14242
14046
|
js_utils.activate_jquery(self.driver)
|
14243
14047
|
js_utils.post_messenger_success_message(
|
14244
14048
|
self.driver, messenger_post, self.message_duration
|
14245
14049
|
)
|
14246
|
-
except Exception:
|
14247
|
-
pass
|
14248
14050
|
|
14249
14051
|
def __assert_exact_shadow_text_visible(self, text, selector, timeout):
|
14250
14052
|
self.__wait_for_exact_shadow_text_visible(text, selector, timeout)
|
@@ -14258,19 +14060,13 @@ class BaseCase(unittest.TestCase):
|
|
14258
14060
|
a_t = SD.translate_assert_exact_text(self._language)
|
14259
14061
|
i_n = SD.translate_in(self._language)
|
14260
14062
|
messenger_post = "<b>%s</b>: {%s} %s %s: %s" % (
|
14261
|
-
a_t,
|
14262
|
-
text,
|
14263
|
-
i_n,
|
14264
|
-
by.upper(),
|
14265
|
-
selector,
|
14063
|
+
a_t, text, i_n, by.upper(), selector
|
14266
14064
|
)
|
14267
|
-
|
14065
|
+
with suppress(Exception):
|
14268
14066
|
js_utils.activate_jquery(self.driver)
|
14269
14067
|
js_utils.post_messenger_success_message(
|
14270
14068
|
self.driver, messenger_post, self.message_duration
|
14271
14069
|
)
|
14272
|
-
except Exception:
|
14273
|
-
pass
|
14274
14070
|
|
14275
14071
|
def __assert_non_empty_shadow_text_visible(self, selector, timeout, strip):
|
14276
14072
|
self.__wait_for_non_empty_shadow_text_visible(selector, timeout, strip)
|
@@ -14284,18 +14080,13 @@ class BaseCase(unittest.TestCase):
|
|
14284
14080
|
a_t = SD.translate_assert_non_empty_text(self._language)
|
14285
14081
|
i_n = SD.translate_in(self._language)
|
14286
14082
|
messenger_post = "<b>%s</b> %s %s: %s" % (
|
14287
|
-
a_t,
|
14288
|
-
i_n,
|
14289
|
-
by.upper(),
|
14290
|
-
selector,
|
14083
|
+
a_t, i_n, by.upper(), selector
|
14291
14084
|
)
|
14292
|
-
|
14085
|
+
with suppress(Exception):
|
14293
14086
|
js_utils.activate_jquery(self.driver)
|
14294
14087
|
js_utils.post_messenger_success_message(
|
14295
14088
|
self.driver, messenger_post, self.message_duration
|
14296
14089
|
)
|
14297
|
-
except Exception:
|
14298
|
-
pass
|
14299
14090
|
|
14300
14091
|
def __is_shadow_element_present(self, selector):
|
14301
14092
|
try:
|
@@ -14447,13 +14238,11 @@ class BaseCase(unittest.TestCase):
|
|
14447
14238
|
|
14448
14239
|
a_t = SD.translate_assert(self._language)
|
14449
14240
|
messenger_post = "<b>%s %s</b>: %s" % (a_t, by.upper(), selector)
|
14450
|
-
|
14241
|
+
with suppress(Exception):
|
14451
14242
|
js_utils.activate_jquery(self.driver)
|
14452
14243
|
js_utils.post_messenger_success_message(
|
14453
14244
|
self.driver, messenger_post, self.message_duration
|
14454
14245
|
)
|
14455
|
-
except Exception:
|
14456
|
-
pass
|
14457
14246
|
|
14458
14247
|
def __assert_shadow_element_visible(self, selector):
|
14459
14248
|
element = self.__get_shadow_element(selector)
|
@@ -14468,13 +14257,11 @@ class BaseCase(unittest.TestCase):
|
|
14468
14257
|
|
14469
14258
|
a_t = SD.translate_assert(self._language)
|
14470
14259
|
messenger_post = "<b>%s %s</b>: %s" % (a_t, by.upper(), selector)
|
14471
|
-
|
14260
|
+
with suppress(Exception):
|
14472
14261
|
js_utils.activate_jquery(self.driver)
|
14473
14262
|
js_utils.post_messenger_success_message(
|
14474
14263
|
self.driver, messenger_post, self.message_duration
|
14475
14264
|
)
|
14476
|
-
except Exception:
|
14477
|
-
pass
|
14478
14265
|
|
14479
14266
|
############
|
14480
14267
|
|
@@ -14549,10 +14336,15 @@ class BaseCase(unittest.TestCase):
|
|
14549
14336
|
self.env = self.environment # Add a shortened version
|
14550
14337
|
self.with_selenium = sb_config.with_selenium # Should be True
|
14551
14338
|
self.headless = sb_config.headless
|
14339
|
+
self.headless1 = sb_config.headless1
|
14340
|
+
if self.headless1:
|
14341
|
+
self.headless = True
|
14342
|
+
self.headless2 = sb_config.headless2
|
14552
14343
|
self.headless_active = False
|
14553
14344
|
sb_config.headless_active = False
|
14554
14345
|
self.headed = sb_config.headed
|
14555
14346
|
self.xvfb = sb_config.xvfb
|
14347
|
+
self.xvfb_metrics = sb_config.xvfb_metrics
|
14556
14348
|
self.locale_code = sb_config.locale_code
|
14557
14349
|
self.interval = sb_config.interval
|
14558
14350
|
self.start_page = sb_config.start_page
|
@@ -14616,7 +14408,6 @@ class BaseCase(unittest.TestCase):
|
|
14616
14408
|
self.log_cdp_events = sb_config.log_cdp_events
|
14617
14409
|
self.no_sandbox = sb_config.no_sandbox
|
14618
14410
|
self.disable_gpu = sb_config.disable_gpu
|
14619
|
-
self.headless2 = sb_config.headless2
|
14620
14411
|
self.incognito = sb_config.incognito
|
14621
14412
|
self.guest_mode = sb_config.guest_mode
|
14622
14413
|
self.dark_mode = sb_config.dark_mode
|
@@ -14644,31 +14435,8 @@ class BaseCase(unittest.TestCase):
|
|
14644
14435
|
self.use_wire = sb_config.use_wire
|
14645
14436
|
self.external_pdf = sb_config.external_pdf
|
14646
14437
|
self._final_debug = sb_config.final_debug
|
14438
|
+
self.window_position = sb_config.window_position
|
14647
14439
|
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
14440
|
self.maximize_option = sb_config.maximize_option
|
14673
14441
|
self.save_screenshot_after_test = sb_config.save_screenshot
|
14674
14442
|
self.no_screenshot_after_test = sb_config.no_screenshot
|
@@ -14832,9 +14600,87 @@ class BaseCase(unittest.TestCase):
|
|
14832
14600
|
self.mobile_emulator = True
|
14833
14601
|
except Exception:
|
14834
14602
|
raise Exception(exception_string)
|
14603
|
+
|
14604
|
+
window_position = self.window_position
|
14605
|
+
if window_position:
|
14606
|
+
if window_position.count(",") != 1:
|
14607
|
+
message = (
|
14608
|
+
'\n\n window_position expects an "x,y" string!'
|
14609
|
+
'\n (Your input was: "%s")\n' % window_position
|
14610
|
+
)
|
14611
|
+
raise Exception(message)
|
14612
|
+
window_position = window_position.replace(" ", "")
|
14613
|
+
win_x = None
|
14614
|
+
win_y = None
|
14615
|
+
try:
|
14616
|
+
win_x = int(window_position.split(",")[0])
|
14617
|
+
win_y = int(window_position.split(",")[1])
|
14618
|
+
except Exception:
|
14619
|
+
message = (
|
14620
|
+
'\n\n Expecting integer values for "x,y"!'
|
14621
|
+
'\n (window_position input was: "%s")\n'
|
14622
|
+
% window_position
|
14623
|
+
)
|
14624
|
+
raise Exception(message)
|
14625
|
+
settings.WINDOW_START_X = win_x
|
14626
|
+
settings.WINDOW_START_Y = win_y
|
14627
|
+
|
14628
|
+
window_size = self.window_size
|
14629
|
+
if window_size:
|
14630
|
+
if window_size.count(",") != 1:
|
14631
|
+
message = (
|
14632
|
+
'\n\n window_size expects a "width,height" string!'
|
14633
|
+
'\n (Your input was: "%s")\n' % window_size
|
14634
|
+
)
|
14635
|
+
raise Exception(message)
|
14636
|
+
window_size = window_size.replace(" ", "")
|
14637
|
+
width = None
|
14638
|
+
height = None
|
14639
|
+
try:
|
14640
|
+
width = int(window_size.split(",")[0])
|
14641
|
+
height = int(window_size.split(",")[1])
|
14642
|
+
except Exception:
|
14643
|
+
message = (
|
14644
|
+
'\n\n Expecting integer values for "width,height"!'
|
14645
|
+
'\n (window_size input was: "%s")\n' % window_size
|
14646
|
+
)
|
14647
|
+
raise Exception(message)
|
14648
|
+
settings.CHROME_START_WIDTH = width
|
14649
|
+
settings.CHROME_START_HEIGHT = height
|
14650
|
+
settings.HEADLESS_START_WIDTH = width
|
14651
|
+
settings.HEADLESS_START_HEIGHT = height
|
14652
|
+
|
14653
|
+
if self.xvfb_metrics:
|
14654
|
+
metrics_string = self.xvfb_metrics
|
14655
|
+
metrics_string = metrics_string.replace(" ", "")
|
14656
|
+
metrics_list = metrics_string.split(",")[0:2]
|
14657
|
+
exception_string = (
|
14658
|
+
"Invalid input for xvfb_metrics!\n"
|
14659
|
+
"Expecting a comma-separated string\n"
|
14660
|
+
"with integer values for Width/Height.\n"
|
14661
|
+
'Eg. --xvfb-metrics="1920,1080".\n'
|
14662
|
+
"(Minimum: 1024,768) (Default: 1366,768)"
|
14663
|
+
)
|
14664
|
+
if len(metrics_list) != 2:
|
14665
|
+
raise Exception(exception_string)
|
14666
|
+
try:
|
14667
|
+
self._xvfb_width = int(metrics_list[0])
|
14668
|
+
self._xvfb_height = int(metrics_list[1])
|
14669
|
+
# The minimum width,height is: 1024,768
|
14670
|
+
if self._xvfb_width < 1024:
|
14671
|
+
self._xvfb_width = 1024
|
14672
|
+
sb_config._xvfb_width = self._xvfb_width
|
14673
|
+
if self._xvfb_height < 768:
|
14674
|
+
self._xvfb_height = 768
|
14675
|
+
sb_config._xvfb_height = self._xvfb_height
|
14676
|
+
self.xvfb = True
|
14677
|
+
except Exception:
|
14678
|
+
raise Exception(exception_string)
|
14679
|
+
|
14835
14680
|
if self.mobile_emulator and not self.user_agent:
|
14836
14681
|
# Use a Pixel user agent by default if not specified
|
14837
14682
|
self.user_agent = constants.Mobile.AGENT
|
14683
|
+
|
14838
14684
|
if self.browser in ["firefox", "ie", "safari"]:
|
14839
14685
|
# The Recorder Mode browser extension is only for Chrome/Edge.
|
14840
14686
|
if self.recorder_mode:
|
@@ -14868,7 +14714,7 @@ class BaseCase(unittest.TestCase):
|
|
14868
14714
|
if not hasattr(sb_config, "shared_driver"):
|
14869
14715
|
sb_config.shared_driver = None
|
14870
14716
|
if sb_config.shared_driver:
|
14871
|
-
|
14717
|
+
with suppress(Exception):
|
14872
14718
|
self._default_driver = sb_config.shared_driver
|
14873
14719
|
self.driver = sb_config.shared_driver
|
14874
14720
|
self._drivers_list = [sb_config.shared_driver]
|
@@ -14882,12 +14728,8 @@ class BaseCase(unittest.TestCase):
|
|
14882
14728
|
self.switch_to_window(0)
|
14883
14729
|
if self._crumbs:
|
14884
14730
|
self.wait_for_ready_state_complete()
|
14885
|
-
|
14731
|
+
with suppress(Exception):
|
14886
14732
|
self.driver.delete_all_cookies()
|
14887
|
-
except Exception:
|
14888
|
-
pass
|
14889
|
-
except Exception:
|
14890
|
-
pass
|
14891
14733
|
if self._reuse_session and sb_config.shared_driver and has_url:
|
14892
14734
|
good_start_page = False
|
14893
14735
|
if self.recorder_ext:
|
@@ -14941,6 +14783,7 @@ class BaseCase(unittest.TestCase):
|
|
14941
14783
|
log_cdp_events=self.log_cdp_events,
|
14942
14784
|
no_sandbox=self.no_sandbox,
|
14943
14785
|
disable_gpu=self.disable_gpu,
|
14786
|
+
headless1=self.headless1,
|
14944
14787
|
headless2=self.headless2,
|
14945
14788
|
incognito=self.incognito,
|
14946
14789
|
guest_mode=self.guest_mode,
|
@@ -14974,10 +14817,8 @@ class BaseCase(unittest.TestCase):
|
|
14974
14817
|
if self.driver.timeouts.implicit_wait > 0:
|
14975
14818
|
self.driver.implicitly_wait(0)
|
14976
14819
|
except Exception:
|
14977
|
-
|
14820
|
+
with suppress(Exception):
|
14978
14821
|
self.driver.implicitly_wait(0)
|
14979
|
-
except Exception:
|
14980
|
-
pass
|
14981
14822
|
self._default_driver = self.driver
|
14982
14823
|
if self._reuse_session:
|
14983
14824
|
sb_config.shared_driver = self.driver
|
@@ -14996,13 +14837,11 @@ class BaseCase(unittest.TestCase):
|
|
14996
14837
|
self.set_time_limit(self.time_limit)
|
14997
14838
|
|
14998
14839
|
# Configure the page load timeout
|
14999
|
-
|
14840
|
+
with suppress(Exception):
|
15000
14841
|
if hasattr(settings, "PAGE_LOAD_TIMEOUT"):
|
15001
14842
|
self.driver.set_page_load_timeout(settings.PAGE_LOAD_TIMEOUT)
|
15002
14843
|
else:
|
15003
14844
|
self.driver.set_page_load_timeout(120) # Selenium uses 300
|
15004
|
-
except Exception:
|
15005
|
-
pass
|
15006
14845
|
|
15007
14846
|
# Set the start time for the test (in ms).
|
15008
14847
|
# Although the pytest clock starts before setUp() begins,
|
@@ -15031,7 +14870,7 @@ class BaseCase(unittest.TestCase):
|
|
15031
14870
|
not self.__last_page_screenshot
|
15032
14871
|
and not self.__last_page_screenshot_png
|
15033
14872
|
):
|
15034
|
-
|
14873
|
+
with suppress(Exception):
|
15035
14874
|
try:
|
15036
14875
|
element = page_actions.wait_for_element_visible(
|
15037
14876
|
self.driver,
|
@@ -15061,14 +14900,10 @@ class BaseCase(unittest.TestCase):
|
|
15061
14900
|
element.screenshot_as_base64
|
15062
14901
|
)
|
15063
14902
|
except Exception:
|
15064
|
-
|
14903
|
+
with suppress(Exception):
|
15065
14904
|
self.__last_page_screenshot = (
|
15066
14905
|
self.driver.get_screenshot_as_base64()
|
15067
14906
|
)
|
15068
|
-
except Exception:
|
15069
|
-
pass
|
15070
|
-
except Exception:
|
15071
|
-
pass
|
15072
14907
|
if not self.__last_page_screenshot:
|
15073
14908
|
self.__last_page_screenshot = SCREENSHOT_UNDEFINED
|
15074
14909
|
self.__last_page_screenshot_png = SCREENSHOT_UNDEFINED
|
@@ -15078,12 +14913,10 @@ class BaseCase(unittest.TestCase):
|
|
15078
14913
|
element.screenshot_as_png
|
15079
14914
|
)
|
15080
14915
|
except Exception:
|
15081
|
-
|
14916
|
+
with suppress(Exception):
|
15082
14917
|
self.__last_page_screenshot_png = (
|
15083
14918
|
self.driver.get_screenshot_as_png()
|
15084
14919
|
)
|
15085
|
-
except Exception:
|
15086
|
-
pass
|
15087
14920
|
else:
|
15088
14921
|
import base64
|
15089
14922
|
|
@@ -15098,12 +14931,10 @@ class BaseCase(unittest.TestCase):
|
|
15098
14931
|
element.screenshot_as_png
|
15099
14932
|
)
|
15100
14933
|
except Exception:
|
15101
|
-
|
14934
|
+
with suppress(Exception):
|
15102
14935
|
self.__last_page_screenshot_png = (
|
15103
14936
|
self.driver.get_screenshot_as_png()
|
15104
14937
|
)
|
15105
|
-
except Exception:
|
15106
|
-
pass
|
15107
14938
|
sb_config._last_page_screenshot_png = self.__last_page_screenshot_png
|
15108
14939
|
|
15109
14940
|
def __set_last_page_url(self):
|
@@ -15155,7 +14986,6 @@ class BaseCase(unittest.TestCase):
|
|
15155
14986
|
data_payload.state = state
|
15156
14987
|
if err:
|
15157
14988
|
import traceback
|
15158
|
-
|
15159
14989
|
tb_string = traceback.format_exc()
|
15160
14990
|
if "Message: " in tb_string:
|
15161
14991
|
data_payload.message = (
|
@@ -15190,7 +15020,7 @@ class BaseCase(unittest.TestCase):
|
|
15190
15020
|
|
15191
15021
|
def __add_pytest_html_extra(self):
|
15192
15022
|
if not self.__added_pytest_html_extra:
|
15193
|
-
|
15023
|
+
with suppress(Exception):
|
15194
15024
|
if self.with_selenium:
|
15195
15025
|
if not self.__last_page_screenshot:
|
15196
15026
|
self.__set_last_page_screenshot()
|
@@ -15217,8 +15047,6 @@ class BaseCase(unittest.TestCase):
|
|
15217
15047
|
):
|
15218
15048
|
self._html_report_extra.append(extra_url)
|
15219
15049
|
self._html_report_extra.append(extra_image)
|
15220
|
-
except Exception:
|
15221
|
-
pass
|
15222
15050
|
|
15223
15051
|
def __delay_driver_quit(self):
|
15224
15052
|
delay_driver_quit = False
|
@@ -15312,7 +15140,6 @@ class BaseCase(unittest.TestCase):
|
|
15312
15140
|
context_id = None
|
15313
15141
|
if filename == "base_case.py" or methodname == "runTest":
|
15314
15142
|
import traceback
|
15315
|
-
|
15316
15143
|
stack_base = traceback.format_stack()[0].split(", in ")[0]
|
15317
15144
|
test_base = stack_base.split(", in ")[0].split(os.sep)[-1]
|
15318
15145
|
if hasattr(self, "cm_filename") and self.cm_filename:
|
@@ -16034,7 +15861,14 @@ class BaseCase(unittest.TestCase):
|
|
16034
15861
|
self.driver.window_handles
|
16035
15862
|
except Exception:
|
16036
15863
|
self.driver.connect()
|
16037
|
-
|
15864
|
+
try:
|
15865
|
+
self.__process_recorded_actions()
|
15866
|
+
except Exception as e:
|
15867
|
+
print("\n (Recorder) Code-generation exception:")
|
15868
|
+
if hasattr(e, "msg"):
|
15869
|
+
print("\n" + str(e.msg))
|
15870
|
+
else:
|
15871
|
+
print(e)
|
16038
15872
|
self.__called_teardown = True
|
16039
15873
|
self.__called_setup = False
|
16040
15874
|
try:
|
@@ -16071,10 +15905,8 @@ class BaseCase(unittest.TestCase):
|
|
16071
15905
|
try:
|
16072
15906
|
self.driver.window_handles
|
16073
15907
|
except Exception:
|
16074
|
-
|
15908
|
+
with suppress(Exception):
|
16075
15909
|
self.driver.connect()
|
16076
|
-
except Exception:
|
16077
|
-
pass
|
16078
15910
|
self.__slow_mode_pause_if_active()
|
16079
15911
|
has_exception = self.__has_exception()
|
16080
15912
|
sb_config._has_exception = has_exception
|
@@ -16264,7 +16096,6 @@ class BaseCase(unittest.TestCase):
|
|
16264
16096
|
else:
|
16265
16097
|
# (Pynose / Behave / Pure Python)
|
16266
16098
|
if hasattr(self, "is_behave") and self.is_behave:
|
16267
|
-
import colorama
|
16268
16099
|
if sb_config.behave_scenario.status.name == "failed":
|
16269
16100
|
has_exception = True
|
16270
16101
|
sb_config._has_exception = True
|