File tree Expand file tree Collapse file tree
src/test/java/io/github/mfaisalkhatri Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ I have tried to answer the below questions by providing working code example in
25251 . How to get the Website URL?
26261 . How to type values in the textbox?
27271 . How to set different window sizes?
28+ 1 . How to double on a button?
28291 . How to use Page Object Model using Playwright Java?
2930
3031## How to run the Tests?
Original file line number Diff line number Diff line change 1+ package io .github .mfaisalkhatri .pages .guru99demosite ;
2+
3+
4+ import com .microsoft .playwright .Locator ;
5+ import com .microsoft .playwright .Page ;
6+
7+ import static org .testng .Assert .assertEquals ;
8+
9+ public class ButtonsPage {
10+
11+ private final Page page ;
12+
13+ public ButtonsPage (final Page page ) {
14+ this .page = page ;
15+ }
16+
17+ private Locator alertBtn () {
18+ return this .page .locator ("#authentication > button" );
19+ }
20+
21+ public void doubleClickAndCheckAlertText (final String text ) {
22+ this .page .onDialog (dialog -> {
23+ assertEquals (dialog .message (), text );
24+ dialog .dismiss ();
25+ });
26+
27+ alertBtn ().dblclick ();
28+ }
29+
30+ }
Original file line number Diff line number Diff line change 1+ package io .github .mfaisalkhatri .tests ;
2+
3+ import com .microsoft .playwright .Browser ;
4+ import com .microsoft .playwright .BrowserType ;
5+ import com .microsoft .playwright .Page ;
6+ import com .microsoft .playwright .Playwright ;
7+ import io .github .mfaisalkhatri .pages .guru99demosite .ButtonsPage ;
8+ import org .testng .annotations .Test ;
9+
10+ public class DoubleClickTest {
11+
12+
13+ @ Test
14+ public void testDoubleClick () {
15+ final Playwright playwright = Playwright .create ();
16+ final Browser browser = playwright .chromium ().launch (new BrowserType .LaunchOptions ().setHeadless (false )
17+ .setChannel ("chrome" ));
18+ final Page page = browser .newPage ();
19+ page .navigate ("https://demo.guru99.com/test/simple_context_menu.html" );
20+
21+ final ButtonsPage buttonsPage = new ButtonsPage (page );
22+ buttonsPage .doubleClickAndCheckAlertText ("You double clicked me.. Thank You.." );
23+
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
3+ <suite name =" Browser Navigation test suite " >
4+ <test name =" Browser navigation tests using Playwright on Chrome" >
5+ <parameter name =" browser" value =" chrome" />
6+ <classes >
7+ <class name =" io.github.mfaisalkhatri.tests.DoubleClickTest" >
8+ <methods >
9+ <include name =" testDoubleClick" />
10+ </methods >
11+ </class >
12+ </classes >
13+ </test >
14+ </suite > <!-- Suite -->
Original file line number Diff line number Diff line change 55 <suite-file path =" testng-browsertest.xml" />
66 <suite-file path =" testng-browsernavigationtests.xml" />
77 <suite-file path =" testng-formauthenticationtests.xml" />
8+ <suite-file path =" testng-windowsizetests.xml" />
9+ <suite-file path =" testng-doubleclicktests.xml" />
810 </suite-files >
911</suite > <!-- Suite -->
You can’t perform that action at this time.
0 commit comments