Skip to content

Commit f4f0100

Browse files
committed
updated playwright dependency version, added test for delay click, drag and drop and click with modifiers
1 parent 7e38602 commit f4f0100

2 files changed

Lines changed: 89 additions & 60 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<properties>
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15-
<playwright.version>1.58.0</playwright.version>
15+
<playwright.version>1.59.0</playwright.version>
1616
<testng.version>7.12.0</testng.version>
1717
<maven.compiler.version>3.15.0</maven.compiler.version>
1818
<surefire.version>3.5.5</surefire.version>

src/test/java/io/github/mfaisalkhatri/tests/ClickOperationTests.java

Lines changed: 88 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.testng.annotations.BeforeMethod;
1010
import org.testng.annotations.Test;
1111

12+
import java.util.Arrays;
1213
import java.util.List;
1314

1415
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
@@ -17,110 +18,138 @@
1718
public class ClickOperationTests {
1819

1920
private Playwright playwright;
20-
private Page page;
21+
private Page page;
2122

2223
@BeforeMethod
23-
public void setup() {
24-
this.playwright = Playwright.create();
25-
Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false)
26-
.setChannel("chrome"));
27-
this.page = browser.newPage();
24+
public void setup () {
25+
this.playwright = Playwright.create ();
26+
Browser browser = this.playwright.chromium ()
27+
.launch (new BrowserType.LaunchOptions ().setHeadless (false)
28+
.setChannel ("chrome"));
29+
this.page = browser.newPage ();
2830
}
2931

3032
@Test
31-
public void testLeftClick() {
32-
this.page.navigate("https://the-internet.herokuapp.com/");
33-
this.page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName("Challenging DOM"))
34-
.click();
33+
public void testLeftClick () {
34+
this.page.navigate ("https://the-internet.herokuapp.com/");
35+
this.page.getByRole (AriaRole.LINK, new Page.GetByRoleOptions ().setName ("Challenging DOM"))
36+
.click ();
3537
//Locator challenginDomLink = page.getByRole (AriaRole.LINK,
3638
// new Page.GetByRoleOptions ().setName ("Challenging DOM"));
3739
//challenginDomLink.click ();
3840

39-
assertThat(
40-
this.page.getByRole(AriaRole.HEADING, new Page.GetByRoleOptions().setName("Challenging DOM"))).isVisible();
41+
assertThat (this.page.getByRole (AriaRole.HEADING,
42+
new Page.GetByRoleOptions ().setName ("Challenging DOM"))).isVisible ();
4143
}
4244

4345
@Test
44-
public void testRightClick() {
45-
this.page.navigate("https://the-internet.herokuapp.com/context_menu");
46-
this.page.locator("#hot-spot")
47-
.click(new Locator.ClickOptions().setButton(MouseButton.RIGHT));
48-
this.page.onDialog(dialog -> {
49-
String alertText = dialog.message();
50-
assert alertText.equals("You selected a context menu");
51-
dialog.accept();
46+
public void testRightClick () {
47+
this.page.navigate ("https://the-internet.herokuapp.com/context_menu");
48+
this.page.locator ("#hot-spot")
49+
.click (new Locator.ClickOptions ().setButton (MouseButton.RIGHT));
50+
this.page.onDialog (dialog -> {
51+
String alertText = dialog.message ();
52+
assert alertText.equals ("You selected a context menu");
53+
dialog.accept ();
5254
});
5355
}
5456

5557
@Test
56-
public void testDoubleClick() {
57-
this.page.navigate("https://demo.guru99.com/test/simple_context_menu.html");
58+
public void testDoubleClick () {
59+
this.page.navigate ("https://demo.guru99.com/test/simple_context_menu.html");
5860

59-
Locator alertBtn = this.page.locator("#authentication > button");
60-
this.page.onDialog(dialog -> {
61+
Locator alertBtn = this.page.locator ("#authentication > button");
62+
this.page.onDialog (dialog -> {
6163
String text = "You double clicked me.. Thank You..";
62-
assertEquals(dialog.message(), text);
63-
dialog.accept();
64+
assertEquals (dialog.message (), text);
65+
dialog.accept ();
6466
});
65-
alertBtn.dblclick();
67+
alertBtn.dblclick ();
6668
}
6769

6870
@Test
69-
public void testMouseHover() {
70-
this.page.navigate("https://automationteststore.com/");
71-
this.page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions()
72-
.setName(" Apparel & accessories")).hover();
73-
this.page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions()
74-
.setName("Shoes").setExact(true)).click();
75-
assertThat(this.page.getByRole(AriaRole.HEADING,
76-
new Page.GetByRoleOptions().setName("Shoes"))).isVisible();
71+
public void testMouseHover () {
72+
this.page.navigate ("https://automationteststore.com/");
73+
this.page.getByRole (AriaRole.LINK, new Page.GetByRoleOptions ().setName (" Apparel & accessories"))
74+
.hover ();
75+
this.page.getByRole (AriaRole.LINK, new Page.GetByRoleOptions ().setName ("Shoes")
76+
.setExact (true))
77+
.click ();
78+
assertThat (
79+
this.page.getByRole (AriaRole.HEADING, new Page.GetByRoleOptions ().setName ("Shoes"))).isVisible ();
7780
}
7881

7982
@Test
80-
public void testForceMouseClick() {
81-
this.page.navigate("https://automationteststore.com/");
82-
this.page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions()
83-
.setName("Specials")).click(new Locator.ClickOptions().setForce(true));
84-
assertThat(this.page.getByRole(AriaRole.HEADING, new Page.GetByRoleOptions()
85-
.setName("Special Offers"))).isVisible();
83+
public void testForceMouseClick () {
84+
this.page.navigate ("https://automationteststore.com/");
85+
this.page.getByRole (AriaRole.LINK, new Page.GetByRoleOptions ().setName ("Specials"))
86+
.click (new Locator.ClickOptions ().setForce (true));
87+
assertThat (this.page.getByRole (AriaRole.HEADING,
88+
new Page.GetByRoleOptions ().setName ("Special Offers"))).isVisible ();
8689
}
8790

8891
@Test
89-
public void testPositionBasedClick() {
90-
this.page.navigate("https://the-internet.herokuapp.com/horizontal_slider");
91-
Locator slider = this.page.getByRole(AriaRole.SLIDER);
92-
BoundingBox box = slider.boundingBox();
92+
public void testPositionBasedClick () {
93+
this.page.navigate ("https://the-internet.herokuapp.com/horizontal_slider");
94+
Locator slider = this.page.getByRole (AriaRole.SLIDER);
95+
BoundingBox box = slider.boundingBox ();
9396
double width = box.width;
9497
double height = box.height;
9598

9699
double x = width * 0.5;
97100
double y = height * 0.5;
98101

99-
slider.click(new Locator.ClickOptions().setPosition(x, y));
100-
this.page.waitForTimeout(3000);
102+
slider.click (new Locator.ClickOptions ().setPosition (x, y));
103+
this.page.waitForTimeout (3000);
101104

102105
}
103106

104107
@Test
105-
public void testClickWithModifiers() {
106-
page.navigate("https://jqueryui.com/selectable/");
107-
FrameLocator frame = page.frameLocator(".demo-frame");
108+
public void testClickWithModifiers () {
109+
this.page.navigate ("https://jqueryui.com/selectable/");
110+
FrameLocator frame = this.page.frameLocator (".demo-frame");
108111

109-
Locator items = frame.locator("#selectable li");
112+
Locator items = frame.locator ("#selectable li");
110113

111-
items.nth(0).click(new Locator.ClickOptions()
112-
.setModifiers(List.of(KeyboardModifier.CONTROL)));
114+
items.nth (0)
115+
.click (new Locator.ClickOptions ().setModifiers (List.of (KeyboardModifier.CONTROL)));
113116

114-
items.nth(3).click(new Locator.ClickOptions()
115-
.setModifiers(List.of(KeyboardModifier.CONTROL)));
117+
items.nth (3)
118+
.click (new Locator.ClickOptions ().setModifiers (List.of (KeyboardModifier.CONTROL)));
116119

117-
page.waitForTimeout(4000);
120+
this.page.waitForTimeout (2000);
121+
122+
this.page.navigate ("https://the-internet.herokuapp.com/");
123+
this.page.getByRole (AriaRole.LINK, new Page.GetByRoleOptions ().setName ("File Download")
124+
.setExact (true))
125+
.click (new Locator.ClickOptions ().setModifiers (List.of (KeyboardModifier.SHIFT)));
126+
127+
this.page.waitForTimeout (2000);
128+
129+
}
130+
131+
@Test
132+
public void testDelayClick () {
133+
this.page.navigate ("https://the-internet.herokuapp.com/");
134+
this.page.getByRole (AriaRole.LINK, new Page.GetByRoleOptions ().setName ("Challenging DOM"))
135+
.click (new Locator.ClickOptions ().setDelay (2000));
136+
assertThat (this.page.getByRole (AriaRole.HEADING,
137+
new Page.GetByRoleOptions ().setName ("Challenging DOM"))).isVisible ();
138+
}
139+
140+
@Test
141+
public void testDragAndDropActions () {
142+
this.page.navigate ("https://the-internet.herokuapp.com/");
143+
this.page.getByRole (AriaRole.LINK, new Page.GetByRoleOptions ().setName ("Drag and Drop"))
144+
.click ();
145+
this.page.locator ("#column-a").dragTo (this.page.locator ("#column-b"));
146+
assertThat(this.page.locator ("#column-a")).containsText ("B");
118147

119148
}
120149

121150
@AfterMethod
122-
public void tearDown() {
123-
this.page.close();
124-
this.playwright.close();
151+
public void tearDown () {
152+
this.page.close ();
153+
this.playwright.close ();
125154
}
126155
}

0 commit comments

Comments
 (0)