Skip to content

Commit c39aee4

Browse files
Added example code for double clicking on a button and updated readme (#55)
* added example code to double click a button * updated readme and testng.xml
1 parent 6794d8a commit c39aee4

5 files changed

Lines changed: 72 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ I have tried to answer the below questions by providing working code example in
2525
1. How to get the Website URL?
2626
1. How to type values in the textbox?
2727
1. How to set different window sizes?
28+
1. How to double on a button?
2829
1. How to use Page Object Model using Playwright Java?
2930

3031
## How to run the Tests?
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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 -->

test-suites/testng.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
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 -->

0 commit comments

Comments
 (0)