@@ -510,14 +510,14 @@ async def test_assertions_locator_to_be_checked(page: Page, server: Server) -> N
510510 await page .set_content ("<input type=checkbox>" )
511511 my_checkbox = page .locator ("input" )
512512 await expect (my_checkbox ).not_to_be_checked ()
513- with pytest .raises (AssertionError ):
513+ with pytest .raises (AssertionError , match = "Locator expected to be checked" ):
514514 await expect (my_checkbox ).to_be_checked (timeout = 100 )
515515 await expect (my_checkbox ).to_be_checked (timeout = 100 , checked = False )
516516 with pytest .raises (AssertionError ):
517517 await expect (my_checkbox ).to_be_checked (timeout = 100 , checked = True )
518518 await my_checkbox .check ()
519519 await expect (my_checkbox ).to_be_checked (timeout = 100 , checked = True )
520- with pytest .raises (AssertionError ):
520+ with pytest .raises (AssertionError , match = "Locator expected to be unchecked" ):
521521 await expect (my_checkbox ).to_be_checked (timeout = 100 , checked = False )
522522 await expect (my_checkbox ).to_be_checked ()
523523
@@ -534,19 +534,91 @@ async def test_assertions_locator_to_be_disabled_enabled(
534534 await expect (my_checkbox ).to_be_disabled (timeout = 100 )
535535 await my_checkbox .evaluate ("e => e.disabled = true" )
536536 await expect (my_checkbox ).to_be_disabled ()
537- with pytest .raises (AssertionError ):
537+ with pytest .raises (AssertionError , match = "Locator expected to be enabled" ):
538538 await expect (my_checkbox ).to_be_enabled (timeout = 100 )
539539
540540
541+ async def test_assertions_locator_to_be_enabled_with_true (page : Page ) -> None :
542+ await page .set_content ("<button>Text</button>" )
543+ await expect (page .locator ("button" )).to_be_enabled (enabled = True )
544+
545+
546+ async def test_assertions_locator_to_be_enabled_with_false_throws_good_exception (
547+ page : Page ,
548+ ) -> None :
549+ await page .set_content ("<button>Text</button>" )
550+ with pytest .raises (AssertionError , match = "Locator expected to be disabled" ):
551+ await expect (page .locator ("button" )).to_be_enabled (enabled = False )
552+
553+
554+ async def test_assertions_locator_to_be_enabled_with_false (page : Page ) -> None :
555+ await page .set_content ("<button disabled>Text</button>" )
556+ await expect (page .locator ("button" )).to_be_enabled (enabled = False )
557+
558+
559+ async def test_assertions_locator_to_be_enabled_with_not_and_false (page : Page ) -> None :
560+ await page .set_content ("<button>Text</button>" )
561+ await expect (page .locator ("button" )).not_to_be_enabled (enabled = False )
562+
563+
564+ async def test_assertions_locator_to_be_enabled_eventually (page : Page ) -> None :
565+ await page .set_content ("<button disabled>Text</button>" )
566+ await page .eval_on_selector (
567+ "button" ,
568+ """
569+ button => setTimeout(() => {
570+ button.removeAttribute('disabled');
571+ }, 700);
572+ """ ,
573+ )
574+ await expect (page .locator ("button" )).to_be_enabled ()
575+
576+
577+ async def test_assertions_locator_to_be_enabled_eventually_with_not (page : Page ) -> None :
578+ await page .set_content ("<button>Text</button>" )
579+ await page .eval_on_selector (
580+ "button" ,
581+ """
582+ button => setTimeout(() => {
583+ button.setAttribute('disabled', '');
584+ }, 700);
585+ """ ,
586+ )
587+ await expect (page .locator ("button" )).not_to_be_enabled ()
588+
589+
541590async def test_assertions_locator_to_be_editable (page : Page , server : Server ) -> None :
542591 await page .goto (server .EMPTY_PAGE )
543592 await page .set_content ("<input></input><button disabled>Text</button>" )
544593 await expect (page .locator ("button" )).not_to_be_editable ()
545594 await expect (page .locator ("input" )).to_be_editable ()
546- with pytest .raises (AssertionError ):
595+ with pytest .raises (AssertionError , match = "Locator expected to be editable" ):
547596 await expect (page .locator ("button" )).to_be_editable (timeout = 100 )
548597
549598
599+ async def test_assertions_locator_to_be_editable_with_true (page : Page ) -> None :
600+ await page .set_content ("<input></input>" )
601+ await expect (page .locator ("input" )).to_be_editable (editable = True )
602+
603+
604+ async def test_assertions_locator_to_be_editable_with_false (page : Page ) -> None :
605+ await page .set_content ("<input readonly></input>" )
606+ await expect (page .locator ("input" )).to_be_editable (editable = False )
607+
608+
609+ async def test_assertions_locator_to_be_editable_with_false_and_throw_good_exception (
610+ page : Page ,
611+ ) -> None :
612+ await page .set_content ("<input></input>" )
613+ with pytest .raises (AssertionError , match = "Locator expected to be readonly" ):
614+ await expect (page .locator ("input" )).to_be_editable (editable = False )
615+
616+
617+ async def test_assertions_locator_to_be_editable_with_not_and_false (page : Page ) -> None :
618+ await page .set_content ("<input></input>" )
619+ await expect (page .locator ("input" )).not_to_be_editable (editable = False )
620+
621+
550622async def test_assertions_locator_to_be_empty (page : Page , server : Server ) -> None :
551623 await page .goto (server .EMPTY_PAGE )
552624 await page .set_content (
@@ -579,10 +651,59 @@ async def test_assertions_locator_to_be_hidden_visible(
579651 await expect (my_checkbox ).to_be_hidden (timeout = 100 )
580652 await my_checkbox .evaluate ("e => e.style.display = 'none'" )
581653 await expect (my_checkbox ).to_be_hidden ()
582- with pytest .raises (AssertionError ):
654+ with pytest .raises (AssertionError , match = "Locator expected to be visible" ):
583655 await expect (my_checkbox ).to_be_visible (timeout = 100 )
584656
585657
658+ async def test_assertions_locator_to_be_visible_with_true (page : Page ) -> None :
659+ await page .set_content ("<button>hello</button>" )
660+ await expect (page .locator ("button" )).to_be_visible (visible = True )
661+
662+
663+ async def test_assertions_locator_to_be_visible_with_false (page : Page ) -> None :
664+ await page .set_content ("<button hidden>hello</button>" )
665+ await expect (page .locator ("button" )).to_be_visible (visible = False )
666+
667+
668+ async def test_assertions_locator_to_be_visible_with_false_throws_good_exception (
669+ page : Page ,
670+ ) -> None :
671+ await page .set_content ("<button>hello</button>" )
672+ with pytest .raises (AssertionError , match = "Locator expected to be hidden" ):
673+ await expect (page .locator ("button" )).to_be_visible (visible = False )
674+
675+
676+ async def test_assertions_locator_to_be_visible_with_not_and_false (page : Page ) -> None :
677+ await page .set_content ("<button>hello</button>" )
678+ await expect (page .locator ("button" )).not_to_be_visible (visible = False )
679+
680+
681+ async def test_assertions_locator_to_be_visible_eventually (page : Page ) -> None :
682+ await page .set_content ("<div></div>" )
683+ await page .eval_on_selector (
684+ "div" ,
685+ """
686+ div => setTimeout(() => {
687+ div.innerHTML = '<span>Hello</span>';
688+ }, 700);
689+ """ ,
690+ )
691+ await expect (page .locator ("span" )).to_be_visible ()
692+
693+
694+ async def test_assertions_locator_to_be_visible_eventually_with_not (page : Page ) -> None :
695+ await page .set_content ("<div><span>Hello</span></div>" )
696+ await page .eval_on_selector (
697+ "span" ,
698+ """
699+ span => setTimeout(() => {
700+ span.textContent = '';
701+ }, 700);
702+ """ ,
703+ )
704+ await expect (page .locator ("span" )).not_to_be_visible ()
705+
706+
586707async def test_assertions_should_serialize_regexp_correctly (
587708 page : Page , server : Server
588709) -> None :
@@ -746,6 +867,15 @@ async def test_should_be_attached_with_attached_false(page: Page) -> None:
746867 await expect (locator ).to_be_attached (attached = False )
747868
748869
870+ async def test_should_be_attached_with_attached_false_and_throw_good_error (
871+ page : Page ,
872+ ) -> None :
873+ await page .set_content ("<button>hello</button>" )
874+ locator = page .locator ("button" )
875+ with pytest .raises (AssertionError , match = "Locator expected to be detached" ):
876+ await expect (locator ).to_be_attached (attached = False , timeout = 1 )
877+
878+
749879async def test_should_be_attached_with_not_and_attached_false (page : Page ) -> None :
750880 await page .set_content ("<button>hello</button>" )
751881 locator = page .locator ("button" )
@@ -773,7 +903,9 @@ async def test_should_be_attached_eventually_with_not(page: Page) -> None:
773903async def test_should_be_attached_fail (page : Page ) -> None :
774904 await page .set_content ("<button>Hello</button>" )
775905 locator = page .locator ("input" )
776- with pytest .raises (AssertionError ) as exc_info :
906+ with pytest .raises (
907+ AssertionError , match = "Locator expected to be attached"
908+ ) as exc_info :
777909 await expect (locator ).to_be_attached (timeout = 1000 )
778910 assert "locator resolved to" not in exc_info .value .args [0 ]
779911
0 commit comments