-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
80c619a
commit c7e1a6e
Showing
3 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
src/test/java/io/github/mfaisalkhatri/tests/TestElementState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters