-
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.
added example code for fetching text and clearing values from the fields
- Loading branch information
1 parent
962a550
commit f53b4f6
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
package io.github.mfaisalkhatri.tests; | ||
|
||
import com.microsoft.playwright.*; | ||
import com.microsoft.playwright.options.AriaRole; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat; | ||
|
||
public class TextFieldTest { | ||
|
||
private Playwright playwright; | ||
|
@@ -30,4 +33,47 @@ public void locateFirstNameByPlaceholder() { | |
Locator firstNameField = page.getByPlaceholder("Your first name *"); | ||
firstNameField.fill("John"); | ||
} | ||
|
||
@Test | ||
public void locateFirstNameByRole() { | ||
page.navigate("https://practicesoftwaretesting.com/contact"); | ||
Locator firstNameField = page.getByRole(AriaRole.TEXTBOX, new Page.GetByRoleOptions().setName("First name")); | ||
firstNameField.fill("Tom"); | ||
} | ||
|
||
@Test | ||
public void testFocusOnField() { | ||
page.navigate("https://practicesoftwaretesting.com/contact"); | ||
Locator emailAddressField = page.getByLabel("Email address"); | ||
emailAddressField.focus(); | ||
assertThat(emailAddressField).isFocused(); | ||
} | ||
|
||
@Test | ||
public void testGetValuesFromTextField() { | ||
page.navigate("https://practicesoftwaretesting.com/contact"); | ||
Locator emailAddressField = page.getByLabel("Email address"); | ||
|
||
String emailAddress = "[email protected]"; | ||
emailAddressField.fill(emailAddress); | ||
|
||
String emailValue = emailAddressField.inputValue(); | ||
System.out.println(emailValue); | ||
|
||
assertThat(emailAddressField).hasValue(emailValue); | ||
} | ||
|
||
@Test | ||
public void testClearFieldValues() { | ||
page.navigate("https://practicesoftwaretesting.com/contact"); | ||
Locator messageField = page.getByLabel("Message *"); | ||
String messageOne = "This is the first message"; | ||
messageField.fill(messageOne); | ||
|
||
messageField.clear(); | ||
String messageTwo = "This is the second message"; | ||
messageField.fill(messageTwo); | ||
|
||
assertThat(messageField).hasValue(messageTwo); | ||
} | ||
} |
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="Working with Text fields using Playwright Java" > | ||
<test name="Text fields tests"> | ||
<classes> | ||
<class name="io.github.mfaisalkhatri.tests.TextFieldTest"> | ||
<methods> | ||
<include name="locateFirstNameByLabel"/> | ||
<include name="locateFirstNameByPlaceholder"/> | ||
<include name="locateFirstNameByRole"/> | ||
<include name="testFocusOnField"/> | ||
<include name="testGetValuesFromTextField"/> | ||
<include name="testClearFieldValues"/> | ||
</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