11package com .serenitydojo .playwright .toolshop .contact ;
22
3- import com .microsoft .playwright .BrowserContext ;
43import com .microsoft .playwright .Page ;
5- import com .microsoft .playwright .Tracing ;
64import com .microsoft .playwright .junit .UsePlaywright ;
75import com .microsoft .playwright .options .AriaRole ;
8- import com .serenitydojo .playwright .HeadlessChromeOptions ;
9- import com .serenitydojo .playwright .toolshop .fixtures .RecordsAllureScreenshots ;
106import com .serenitydojo .playwright .toolshop .catalog .pageobjects .NavBar ;
7+ import com .serenitydojo .playwright .toolshop .fixtures .ChromeHeadlessOptions ;
8+ import com .serenitydojo .playwright .toolshop .fixtures .TakesFinalScreenshot ;
119import io .qameta .allure .Feature ;
12- import io .qameta .allure .Step ;
1310import io .qameta .allure .Story ;
1411import org .assertj .core .api .Assertions ;
15- import org .junit .jupiter .api .*;
12+ import org .junit .jupiter .api .BeforeEach ;
13+ import org .junit .jupiter .api .DisplayName ;
14+ import org .junit .jupiter .api .Test ;
1615import org .junit .jupiter .params .ParameterizedTest ;
1716import org .junit .jupiter .params .provider .ValueSource ;
1817
2322import static com .microsoft .playwright .assertions .PlaywrightAssertions .assertThat ;
2423
2524@ DisplayName ("Contact form" )
26- @ Feature ("Contact form " )
27- @ UsePlaywright (HeadlessChromeOptions .class )
28- public class ContactFormTest implements RecordsAllureScreenshots {
25+ @ Feature ("Contacts " )
26+ @ UsePlaywright (ChromeHeadlessOptions .class )
27+ public class ContactFormTest implements TakesFinalScreenshot {
2928
3029 ContactForm contactForm ;
3130 NavBar navigate ;
@@ -37,31 +36,10 @@ void openContactPage(Page page) {
3736 navigate .toTheContactPage ();
3837 }
3938
40-
41- @ BeforeEach
42- void setupTrace (BrowserContext context ) {
43- context .tracing ().start (
44- new Tracing .StartOptions ()
45- .setScreenshots (true )
46- .setSnapshots (true )
47- .setSources (true )
48- );
49- }
50-
51- @ AfterEach
52- void recordTrace (TestInfo testInfo , BrowserContext context ) {
53- String traceName = testInfo .getDisplayName ().replace (" " , "-" ).toLowerCase ();
54- context .tracing ().stop (
55- new Tracing .StopOptions ()
56- .setPath (Paths .get ("target/trace-" + traceName + ".zip" ))
57- );
58- }
59-
60-
61- @ Story ("Submitting a request" )
39+ @ Story ("Contact form" )
6240 @ DisplayName ("Customers can use the contact form to contact us" )
6341 @ Test
64- void completeForm (Page page ) throws URISyntaxException {
42+ void completeForm () throws URISyntaxException {
6543 contactForm .setFirstName ("Sarah-Jane" );
6644 contactForm .setLastName ("Smith" );
6745 contactForm .
setEmail (
"[email protected] " );
@@ -71,19 +49,13 @@ void completeForm(Page page) throws URISyntaxException {
7149 Path fileToUpload = Paths .get (ClassLoader .getSystemResource ("data/sample-data.txt" ).toURI ());
7250 contactForm .setAttachment (fileToUpload );
7351
74- recordScreenshot (page , "Submit form" );
7552 contactForm .submitForm ();
7653
7754 Assertions .assertThat (contactForm .getAlertMessage ())
7855 .contains ("Thanks for your message! We will contact you shortly." );
7956 }
8057
81- @ Step
82- void submitTheForm (Page page ) {
83-
84- }
85-
86- @ Story ("Submitting a request" )
58+ @ Story ("Contact form" )
8759 @ DisplayName ("First name, last name, email and message are mandatory" )
8860 @ ParameterizedTest (name = "{arguments} is a mandatory field" )
8961 @ ValueSource (strings = {"First name" , "Last name" , "Email" , "Message" })
@@ -98,7 +70,6 @@ void mandatoryFields(String fieldName, Page page) {
9870 // Clear one of the fields
9971 contactForm .clearField (fieldName );
10072
101- recordScreenshot (page , "Submit form" );
10273 contactForm .submitForm ();
10374
10475 // Check the error message for that field
@@ -107,7 +78,7 @@ void mandatoryFields(String fieldName, Page page) {
10778 assertThat (errorMessage ).isVisible ();
10879 }
10980
110- @ Story ("Submitting a request " )
81+ @ Story ("Contact form " )
11182 @ DisplayName ("The message must be at least 50 characters long" )
11283 @ Test
11384 void messageTooShort (Page page ) {
@@ -118,13 +89,12 @@ void messageTooShort(Page page) {
11889 contactForm .setMessage ("A short long message." );
11990 contactForm .selectSubject ("Warranty" );
12091
121- recordScreenshot (page , "Submit form" );
12292 contactForm .submitForm ();
12393
12494 assertThat (page .getByRole (AriaRole .ALERT )).hasText ("Message must be minimal 50 characters" );
12595 }
12696
127- @ Story ("Submitting a request " )
97+ @ Story ("Contact form " )
12898 @ DisplayName ("The email address must be correctly formatted" )
12999 @ ParameterizedTest (name = "'{arguments}' should be rejected" )
130100 @ ValueSource (strings = {"not-an-email" , "not-an.email.com" , "notanemail" })
@@ -135,7 +105,6 @@ void invalidEmailField(String invalidEmail, Page page) {
135105 contactForm .setMessage ("A very long message to the warranty service about a warranty on a product!" );
136106 contactForm .selectSubject ("Warranty" );
137107
138- recordScreenshot (page , "Submit form" );
139108 contactForm .submitForm ();
140109
141110 assertThat (page .getByRole (AriaRole .ALERT )).hasText ("Email format is invalid" );
0 commit comments