From c7e1a6e5aa3e7d0e8177040162c99af78e48e6ad Mon Sep 17 00:00:00 2001 From: Mohammad Faisal Khatri Date: Tue, 27 Aug 2024 08:50:18 +0300 Subject: [PATCH] Example code for added for checking if element is disabled, enabled. checked and visible (#68) * work in progress for checking element is selected * added example code for checking elements state --- .../mfaisalkhatri/tests/TestElementState.java | 76 +++++++++++++++++++ test-suites/testng-elementstatetest.xml | 18 +++++ test-suites/testng.xml | 1 + 3 files changed, 95 insertions(+) create mode 100644 src/test/java/io/github/mfaisalkhatri/tests/TestElementState.java create mode 100644 test-suites/testng-elementstatetest.xml diff --git a/src/test/java/io/github/mfaisalkhatri/tests/TestElementState.java b/src/test/java/io/github/mfaisalkhatri/tests/TestElementState.java new file mode 100644 index 0000000..ca9d712 --- /dev/null +++ b/src/test/java/io/github/mfaisalkhatri/tests/TestElementState.java @@ -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(); + } + +} diff --git a/test-suites/testng-elementstatetest.xml b/test-suites/testng-elementstatetest.xml new file mode 100644 index 0000000..3c69f96 --- /dev/null +++ b/test-suites/testng-elementstatetest.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test-suites/testng.xml b/test-suites/testng.xml index 0307703..319519a 100644 --- a/test-suites/testng.xml +++ b/test-suites/testng.xml @@ -13,5 +13,6 @@ + \ No newline at end of file