Skip to content

Commit 7b566cc

Browse files
Added example code for radio button and mouse hover (#66)
* added example code for handling radio buttons * added radio buttons testng xml file
1 parent 608f781 commit 7b566cc

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package io.github.mfaisalkhatri.tests;
2+
3+
import com.microsoft.playwright.*;
4+
import org.testng.annotations.AfterClass;
5+
import org.testng.annotations.BeforeClass;
6+
import org.testng.annotations.Test;
7+
8+
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
9+
10+
public class RadioButtonTests {
11+
12+
private Playwright playwright;
13+
private Page page;
14+
15+
16+
@BeforeClass
17+
public void setup() {
18+
this.playwright = Playwright.create();
19+
final Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false).setChannel("chrome"));
20+
this.page = browser.newPage();
21+
}
22+
23+
@Test
24+
public void testRadioButtonIsChecked() {
25+
page.navigate("https://www.lambdatest.com/selenium-playground/radiobutton-demo");
26+
Locator maleRadioBtn = page.getByLabel("Male").first();
27+
maleRadioBtn.click();
28+
assertThat(maleRadioBtn).isChecked();
29+
}
30+
31+
@Test
32+
public void testRadioButtonIsNotChecked() {
33+
page.navigate("https://www.lambdatest.com/selenium-playground/radiobutton-demo");
34+
Locator femaleRadioBtn = page.getByLabel("Female").first();
35+
femaleRadioBtn.click();
36+
assertThat(femaleRadioBtn).isChecked();
37+
38+
Locator maleRadioBtn = page.getByLabel("Male").first();
39+
assertThat(maleRadioBtn).not().isChecked();
40+
}
41+
42+
43+
@AfterClass
44+
public void tearDown() {
45+
this.page.close();
46+
this.playwright.close();
47+
}
48+
49+
}

test-suites/testng-radiobuttons.xml

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="Playwright demo test suite ">
4+
<test name="Radio buttons demo on Chrome">
5+
<classes>
6+
<class name="io.github.mfaisalkhatri.tests.RadioButtonTests">
7+
<methods>
8+
<include name="testRadioButtonIsChecked"/>
9+
<include name="testRadioButtonIsNotChecked"/>
10+
</methods>
11+
</class>
12+
</classes>
13+
</test>
14+
</suite>

0 commit comments

Comments
 (0)