11package com .serenitydojo .playwright .toolshop .contact ;
22
3+ import com .microsoft .playwright .Locator ;
34import com .microsoft .playwright .Page ;
45import com .microsoft .playwright .junit .UsePlaywright ;
56import com .microsoft .playwright .options .AriaRole ;
67import com .serenitydojo .playwright .toolshop .catalog .pageobjects .NavBar ;
78import com .serenitydojo .playwright .toolshop .fixtures .ChromeHeadlessOptions ;
8- import com .serenitydojo .playwright .toolshop .fixtures .ScreenshotManager ;
99import com .serenitydojo .playwright .toolshop .fixtures .TakesFinalScreenshot ;
1010import io .qameta .allure .Feature ;
1111import io .qameta .allure .Story ;
@@ -40,7 +40,7 @@ void openContactPage(Page page) {
4040 @ Story ("Contact form" )
4141 @ DisplayName ("Customers can use the contact form to contact us" )
4242 @ Test
43- void completeForm () throws URISyntaxException {
43+ void completeForm (Page page ) throws URISyntaxException {
4444 contactForm .setFirstName ("Sarah-Jane" );
4545 contactForm .setLastName ("Smith" );
4646 contactForm .
setEmail (
"[email protected] " );
@@ -52,8 +52,8 @@ void completeForm() throws URISyntaxException {
5252
5353 contactForm .submitForm ();
5454
55- Assertions . assertThat (contactForm .getAlertMessage ())
56- . contains ("Thanks for your message! We will contact you shortly." );
55+ assertThat (contactForm .alertMessage ()). isVisible ();
56+ assertThat ( contactForm . alertMessage ()). hasText ("Thanks for your message! We will contact you shortly." );
5757 }
5858
5959 @ Story ("Contact form" )
@@ -74,9 +74,8 @@ void mandatoryFields(String fieldName, Page page) {
7474 contactForm .submitForm ();
7575
7676 // Check the error message for that field
77- var errorMessage = page .getByRole (AriaRole .ALERT ).getByText (fieldName + " is required" );
78-
79- assertThat (errorMessage ).isVisible ();
77+ assertThat (contactForm .alertMessage ()).isVisible ();
78+ assertThat (contactForm .alertMessage ()).hasText (fieldName + " is required" );
8079 }
8180
8281 @ Story ("Contact form" )
@@ -92,7 +91,8 @@ void messageTooShort(Page page) {
9291
9392 contactForm .submitForm ();
9493
95- assertThat (page .getByRole (AriaRole .ALERT )).hasText ("Message must be minimal 50 characters" );
94+ assertThat (contactForm .alertMessage ()).isVisible ();
95+ assertThat (contactForm .alertMessage ()).hasText ("Message must be minimal 50 characters" );
9696 }
9797
9898 @ Story ("Contact form" )
@@ -108,6 +108,7 @@ void invalidEmailField(String invalidEmail, Page page) {
108108
109109 contactForm .submitForm ();
110110
111- assertThat (page .getByRole (AriaRole .ALERT )).hasText ("Email format is invalid" );
111+ assertThat (contactForm .alertMessage ()).isVisible ();
112+ assertThat (contactForm .alertMessage ()).hasText ("Email format is invalid" );
112113 }
113114}
0 commit comments