Skip to content

Commit

Permalink
Example code for added for checking if element is disabled, enabled. …
Browse files Browse the repository at this point in the history
…checked and visible (#68)

* work in progress for checking element is selected

* added example code for checking elements state
  • Loading branch information
mfaisalkhatri authored Aug 27, 2024
1 parent 80c619a commit c7e1a6e
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/test/java/io/github/mfaisalkhatri/tests/TestElementState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package io.github.mfaisalkhatri.tests;

import com.microsoft.playwright.*;
import com.microsoft.playwright.options.AriaRole;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;

public class TestElementState {

private Playwright playwright;
private Page page;


@BeforeClass
public void setup() {
this.playwright = Playwright.create();
final Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false).setChannel("chrome"));
this.page = browser.newPage();
}

@Test
public void testElementIsDisabled() {
page.navigate("https://the-internet.herokuapp.com/jqueryui/menu#");
Locator disabledMenu = page.locator("#ui-id-1 > a");
assertThat(disabledMenu).isDisabled();
}

@Test
public void testElementIsEnabled() {
page.navigate("https://the-internet.herokuapp.com/jqueryui/menu#");
Locator enabledMenu = page.locator("#ui-id-3 > a");
assertThat(enabledMenu).isEnabled();
}

@Test
public void testElementIsDisplayed() {
page.navigate("https://www.lambdatest.com/selenium-playground/");

Locator radioButtonLink = page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName("Radio Buttons Demo"));
radioButtonLink.click();
Locator pageHeading = page.getByRole(AriaRole.HEADING, new Page.GetByRoleOptions().setName("Radio button Demo"));
assertThat(pageHeading).isVisible();
assertThat(pageHeading).equals("Radio button Demo");
}

@Test
public void testElementIsSelected() {
page.navigate("https://www.lambdatest.com/selenium-playground/radiobutton-demo");
Locator maleRadioButton = page.getByLabel("Male").first();
maleRadioButton.click();
assertThat(maleRadioButton).isChecked();
}

@Test
public void testRadioButtonIsDisabled() {
page.navigate("https://www.lambdatest.com/selenium-playground/radiobutton-demo");
Locator disabledRadioButton = page.getByLabel("Disabled Radio Button").first();
assertThat(disabledRadioButton).isDisabled();
}
@Test
public void testTextBoxIsEditable() {
page.navigate("https://www.lambdatest.com/selenium-playground/simple-form-demo");
Locator enterMessagField = page.getByPlaceholder("Please enter your Message");
assertThat(enterMessagField).isEditable();
}

@AfterClass
public void tearDown() {
this.page.close();
this.playwright.close();
}

}
18 changes: 18 additions & 0 deletions test-suites/testng-elementstatetest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Browser Navigation test suite " >
<test name="Browser navigation tests using Playwright on Chrome">
<classes>
<class name="io.github.mfaisalkhatri.tests.TestElementState">
<methods>
<include name="testElementIsDisabled"/>
<include name="testElementIsEnabled"/>
<include name="testElementIsDisplayed"/>
<include name="testElementIsSelected"/>
<include name="testRadioButtonIsDisabled"/>
<include name="testTextBoxIsEditable"/>
</methods>
</class>
</classes>
</test>
</suite>
1 change: 1 addition & 0 deletions test-suites/testng.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
<suite-file path="testng-mousehovertest.xml"/>
<suite-file path="testng-playwrightdemotests.xml"/>
<suite-file path="testng-radiobuttons.xml"/>
<suite-file path="testng-elementstatetest.xml"/>
</suite-files>
</suite>

0 comments on commit c7e1a6e

Please sign in to comment.