33import com .microsoft .playwright .Browser ;
44import com .microsoft .playwright .BrowserType ;
55import com .microsoft .playwright .Page ;
6- import com .microsoft .playwright .junit .UsePlaywright ;
7- import com .microsoft .playwright .junit .Options ;
8- import com .microsoft .playwright .junit .OptionsFactory ;
6+ import com .microsoft .playwright .Playwright ;
7+ import org .junit .jupiter .api .AfterEach ;
98import org .junit .jupiter .api .Assertions ;
9+ import org .junit .jupiter .api .BeforeEach ;
1010import org .junit .jupiter .api .Test ;
1111
1212import java .util .Arrays ;
1313
14- @ UsePlaywright (ASimplePlaywrightTest .CustomOptions .class )
1514public class ASimplePlaywrightTest {
1615
17- public static class CustomOptions implements OptionsFactory {
18- @ Override
19- public Options getOptions () {
20- return new Options ()
21- // .setHeadless(false)
22- .setLaunchOptions (
23- new BrowserType .LaunchOptions ()
24- .setArgs (Arrays .asList ("--no-sandbox" ,
25- "--disable-gpu" ,
26- "--disable-extensions" ))
27- );
28- }
16+ Playwright playwright ;
17+ Browser browser ;
18+ Page page ;
19+
20+ @ BeforeEach
21+ public void setUp () {
22+ playwright = Playwright .create ();
23+ browser = playwright .chromium ().launch (
24+ new BrowserType .LaunchOptions ()
25+ // .setHeadless(false)
26+ .setArgs (Arrays .asList ("--no-sandbox" ,"--disable-extensions" ,"--disable-gpu" ))
27+ );
28+ page = browser .newPage ();
29+ }
30+
31+ @ AfterEach
32+ public void tearDown () {
33+ browser .close ();
34+ playwright .close ();
2935 }
3036
3137 @ Test
32- void shouldShowThePageTitle (Page page ) {
38+ void shouldShowThePageTitle () {
3339 page .navigate ("https://practicesoftwaretesting.com" );
3440 String title = page .title ();
3541 Assertions .assertTrue (title .contains ("Practice Software Testing" ));
3642 }
3743
3844 @ Test
39- void shouldShowSearchTermsInTheTitle1 ( Page page ) {
45+ void shouldShowSearchTermsInTheTitle ( ) {
4046 page .navigate ("https://practicesoftwaretesting.com" );
4147 page .locator ("[placeholder=Search]" ).fill ("Pliers" );
4248 page .locator ("button:has-text('Search')" ).click ();
@@ -45,4 +51,5 @@ void shouldShowSearchTermsInTheTitle1(Page page) {
4551
4652 Assertions .assertTrue (matchingProductCount > 0 );
4753 }
54+
4855}
0 commit comments