@@ -3482,6 +3482,36 @@ def wait_for_and_switch_to_alert(self, timeout=None):
3482
3482
3483
3483
############
3484
3484
3485
+ def __assert_eq (self , * args , ** kwargs ):
3486
+ """ Minified assert_equal() using only the list diff. """
3487
+ minified_exception = None
3488
+ try :
3489
+ self .assertEqual (* args , ** kwargs )
3490
+ except Exception as e :
3491
+ str_e = str (e )
3492
+ minified_exception = "\n AssertionError:\n "
3493
+ lines = str_e .split ('\n ' )
3494
+ countdown = 3
3495
+ countdown_on = False
3496
+ for line in lines :
3497
+ if countdown_on :
3498
+ minified_exception += line + '\n '
3499
+ countdown = countdown - 1
3500
+ if countdown == 0 :
3501
+ countdown_on = False
3502
+ elif line .startswith ('F' ):
3503
+ countdown_on = True
3504
+ countdown = 3
3505
+ minified_exception += line + '\n '
3506
+ elif line .startswith ('+' ) or line .startswith ('-' ):
3507
+ minified_exception += line + '\n '
3508
+ elif line .startswith ('?' ):
3509
+ minified_exception += line + '\n '
3510
+ elif line .strip ().startswith ('*' ):
3511
+ minified_exception += line + '\n '
3512
+ if minified_exception :
3513
+ raise Exception (minified_exception )
3514
+
3485
3515
def check_window (self , name = "default" , level = 0 , baseline = False ):
3486
3516
""" *** Automated Visual Testing with SeleniumBase ***
3487
3517
@@ -3644,40 +3674,41 @@ def check_window(self, name="default", level=0, baseline=False):
3644
3674
f .close ()
3645
3675
3646
3676
domain_fail = (
3647
- "Page Domain Mismatch Failure: "
3677
+ "\n Page Domain Mismatch Failure: "
3648
3678
"Current Page Domain doesn't match the Page Domain of the "
3649
3679
"Baseline! Can't compare two completely different sites! "
3650
3680
"Run with --visual_baseline to reset the baseline!" )
3651
3681
level_1_failure = (
3652
- "\n \n *** Exception: <Level 1> Visual Diff Failure:\n "
3682
+ "\n * \n *** Exception: <Level 1> Visual Diff Failure:\n "
3653
3683
"* HTML tags don't match the baseline!" )
3654
3684
level_2_failure = (
3655
- "\n \n *** Exception: <Level 2> Visual Diff Failure:\n "
3656
- "* HTML tag attributes don't match the baseline!" )
3685
+ "\n * \n *** Exception: <Level 2> Visual Diff Failure:\n "
3686
+ "* HTML tag attribute names don't match the baseline!" )
3657
3687
level_3_failure = (
3658
- "\n \n *** Exception: <Level 3> Visual Diff Failure:\n "
3688
+ "\n * \n *** Exception: <Level 3> Visual Diff Failure:\n "
3659
3689
"* HTML tag attribute values don't match the baseline!" )
3660
3690
3661
3691
page_domain = self .get_domain_url (page_url )
3662
3692
page_data_domain = self .get_domain_url (page_url_data )
3663
3693
unittest .TestCase .maxDiff = 1000
3664
- if level == 1 or level == 2 or level == 3 :
3665
- self .assertEqual (page_domain , page_data_domain , domain_fail )
3666
- self .assertEqual (level_1 , level_1_data , level_1_failure )
3694
+ if level != 0 :
3695
+ self .assertEqual (page_data_domain , page_domain , domain_fail )
3667
3696
unittest .TestCase .maxDiff = None
3668
- if level == 2 or level == 3 :
3669
- self .assertEqual (level_2 , level_2_data , level_2_failure )
3670
3697
if level == 3 :
3671
- self .assertEqual (level_3 , level_3_data , level_3_failure )
3698
+ self .__assert_eq (level_3_data , level_3 , level_3_failure )
3699
+ if level == 2 :
3700
+ self .__assert_eq (level_2_data , level_2 , level_2_failure )
3701
+ unittest .TestCase .maxDiff = 1000
3702
+ if level == 1 :
3703
+ self .__assert_eq (level_1_data , level_1 , level_1_failure )
3704
+ unittest .TestCase .maxDiff = None
3672
3705
if level == 0 :
3673
3706
try :
3674
3707
unittest .TestCase .maxDiff = 1000
3675
3708
self .assertEqual (
3676
3709
page_domain , page_data_domain , domain_fail )
3677
- self .assertEqual (level_1 , level_1_data , level_1_failure )
3678
3710
unittest .TestCase .maxDiff = None
3679
- self .assertEqual (level_2 , level_2_data , level_2_failure )
3680
- self .assertEqual (level_3 , level_3_data , level_3_failure )
3711
+ self .__assert_eq (level_3_data , level_3 , level_3_failure )
3681
3712
except Exception as e :
3682
3713
print (e ) # Level-0 Dry Run (Only print the differences)
3683
3714
0 commit comments