diff --git a/README.md b/README.md index 7d34a92..5f6ddc4 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,8 @@ I have tried to answer the below questions by providing working code example in 1. How to set different window sizes? 1. How to double on a button? 1. How to use Page Object Model using Playwright Java? -1. How to perform browser navigations? +1. How to perform browser navigation? +1. How to perform Mouse hover? ## How to run the Tests? @@ -45,6 +46,7 @@ I have tried to answer the below questions by providing working code example in - [Playwright Java Tutorial: Web Automation Testing | Installation and Setup](https://medium.com/@iamfaisalkhatri/playwright-java-tutorial-web-automation-testing-installation-and-setup-545c9c7661c8) - [Playwright Java Tutorial: Web Automation Testing | Writing and running tests on Chrome, Firefox and Edge browsers](https://medium.com/@iamfaisalkhatri/playwright-java-tutorial-web-automation-testing-writing-and-running-tests-on-chrome-firefox-and-d2446b9a69ce) - [Playwright Java Tutorial: Web Automation Testing | How to perform browser navigation?](https://medium.com/@iamfaisalkhatri/playwright-java-tutorial-web-automation-testing-how-to-perform-browser-navigation-043f14af5c97) +- [Playwright Java Tutorial: Web Automation Testing | How to work with text fields?](https://medium.com/@iamfaisalkhatri/playwright-java-tutorial-web-automation-testing-how-to-work-with-text-fields-6cc9982ed7b2) ## :question: Need Assistance? diff --git a/pom.xml b/pom.xml index 194e312..8a5f7ea 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ UTF-8 - 1.45.0 + 1.45.1 7.10.2 3.13.0 3.3.0 diff --git a/src/main/java/io/github/mfaisalkhatri/browsers/BrowserManager.java b/src/main/java/io/github/mfaisalkhatri/browsers/BrowserManager.java index d9d61e3..b611fc1 100644 --- a/src/main/java/io/github/mfaisalkhatri/browsers/BrowserManager.java +++ b/src/main/java/io/github/mfaisalkhatri/browsers/BrowserManager.java @@ -46,6 +46,7 @@ public Page getPage() { public void closeBrowser() { this.browser.close(); + this.playwright.close(); } diff --git a/src/test/java/io/github/mfaisalkhatri/tests/DoubleClickTest.java b/src/test/java/io/github/mfaisalkhatri/tests/DoubleClickTest.java index 6731f31..82eed4c 100644 --- a/src/test/java/io/github/mfaisalkhatri/tests/DoubleClickTest.java +++ b/src/test/java/io/github/mfaisalkhatri/tests/DoubleClickTest.java @@ -21,5 +21,8 @@ public void testDoubleClick () { final ButtonsPage buttonsPage = new ButtonsPage(page); buttonsPage.doubleClickAndCheckAlertText("You double clicked me.. Thank You.."); + browser.close(); + playwright.close(); + } } \ No newline at end of file diff --git a/src/test/java/io/github/mfaisalkhatri/tests/DropdownTests.java b/src/test/java/io/github/mfaisalkhatri/tests/DropdownTests.java index 02b4025..dc5bce6 100644 --- a/src/test/java/io/github/mfaisalkhatri/tests/DropdownTests.java +++ b/src/test/java/io/github/mfaisalkhatri/tests/DropdownTests.java @@ -86,6 +86,7 @@ public void testMultiSelectOptions() { @AfterClass public void tearDown() { + this.page.close(); this.playwright.close(); } } \ No newline at end of file diff --git a/src/test/java/io/github/mfaisalkhatri/tests/MouseHoverTest.java b/src/test/java/io/github/mfaisalkhatri/tests/MouseHoverTest.java new file mode 100644 index 0000000..eb34bb7 --- /dev/null +++ b/src/test/java/io/github/mfaisalkhatri/tests/MouseHoverTest.java @@ -0,0 +1,38 @@ +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 MouseHoverTest { + + 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 testMouseHover() { + page.navigate("https://the-internet.herokuapp.com/hovers"); + Locator firstImage = page.locator("#content div.figure:nth-child(3)"); + firstImage.hover(); + Locator userNameText = page.getByRole(AriaRole.HEADING, new Page.GetByRoleOptions().setName("name: user1")); + assertThat(userNameText).hasText("name: user1"); + } + + @AfterClass + public void tearDown() { + this.page.close(); + this.playwright.close(); + } +} \ No newline at end of file diff --git a/src/test/java/io/github/mfaisalkhatri/tests/PlaywrightDemoTests.java b/src/test/java/io/github/mfaisalkhatri/tests/PlaywrightDemoTests.java index 1172e54..7e00ad6 100644 --- a/src/test/java/io/github/mfaisalkhatri/tests/PlaywrightDemoTests.java +++ b/src/test/java/io/github/mfaisalkhatri/tests/PlaywrightDemoTests.java @@ -19,6 +19,7 @@ public void testOnChromeHeadless() { final String pageTitle = page.title(); assertEquals(pageTitle, "Your Store"); browser.close(); + playwright.close(); } @@ -32,6 +33,7 @@ public void testOnChrome() { final String pageTitle = page.title(); assertEquals(pageTitle, "Your Store"); browser.close(); + playwright.close(); } @Test @@ -43,6 +45,7 @@ public void testOnFirefoxHeadless() { final String pageTitle = page.title(); assertEquals(pageTitle, "Your Store"); browser.close(); + playwright.close(); } @Test @@ -54,6 +57,7 @@ public void testOnFirefox() { final String pageTitle = page.title(); assertEquals(pageTitle, "Your Store"); browser.close(); + playwright.close(); } @@ -66,6 +70,7 @@ public void testOnFirefoxSlowMo() { final String pageTitle = page.title(); assertEquals(pageTitle, "Your Store"); browser.close(); + playwright.close(); } @Test @@ -77,6 +82,7 @@ public void testOnChromeSlowMo() { final String pageTitle = page.title(); assertEquals(pageTitle, "Your Store"); browser.close(); + playwright.close(); } @Test @@ -88,6 +94,7 @@ public void testOnEdge() { final String pageTitle = page.title(); assertEquals(pageTitle, "Your Store"); browser.close(); + playwright.close(); } @Test @@ -124,6 +131,7 @@ public void testBrowserNavigation() { assertEquals(currentPageUrl, websiteLink); browser.close(); + playwright.close(); } } \ No newline at end of file diff --git a/src/test/java/io/github/mfaisalkhatri/tests/TextFieldTest.java b/src/test/java/io/github/mfaisalkhatri/tests/TextFieldTest.java index b65fd79..34bfb8b 100644 --- a/src/test/java/io/github/mfaisalkhatri/tests/TextFieldTest.java +++ b/src/test/java/io/github/mfaisalkhatri/tests/TextFieldTest.java @@ -2,6 +2,7 @@ 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; @@ -95,4 +96,11 @@ public void testKeyPress() { textBox.press("9"); assertThat(resultText).containsText("9"); } + + @AfterClass + public void tearDown() { + this.page.close(); + this.playwright.close(); + } + } diff --git a/src/test/java/io/github/mfaisalkhatri/tests/WindowSizeTest.java b/src/test/java/io/github/mfaisalkhatri/tests/WindowSizeTest.java index 8fd5274..a457beb 100644 --- a/src/test/java/io/github/mfaisalkhatri/tests/WindowSizeTest.java +++ b/src/test/java/io/github/mfaisalkhatri/tests/WindowSizeTest.java @@ -21,6 +21,7 @@ public void testDifferentWindowSize() { final String pageHeaderText = pageHeader.textContent(); assertEquals(pageHeaderText, "Selenium Playground"); browser.close(); + playwright.close(); } @@ -40,6 +41,7 @@ public void testDifferentWindowSizeMethodTwo() { final String pageHeaderText = pageHeader.textContent(); assertEquals(pageHeaderText, "Selenium Playground"); browser.close(); + playwright.close(); } diff --git a/test-suites/testng-formauthenticationtests.xml b/test-suites/testng-formauthenticationtests.xml index 9dbe5f7..c462358 100644 --- a/test-suites/testng-formauthenticationtests.xml +++ b/test-suites/testng-formauthenticationtests.xml @@ -2,7 +2,7 @@ - + diff --git a/test-suites/testng-mousehovertest.xml b/test-suites/testng-mousehovertest.xml new file mode 100644 index 0000000..03bf43b --- /dev/null +++ b/test-suites/testng-mousehovertest.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/test-suites/testng-playwrightdemotests.xml b/test-suites/testng-playwrightdemotests.xml new file mode 100644 index 0000000..6fbceea --- /dev/null +++ b/test-suites/testng-playwrightdemotests.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test-suites/testng.xml b/test-suites/testng.xml index f0ed434..1f30ffa 100644 --- a/test-suites/testng.xml +++ b/test-suites/testng.xml @@ -1,6 +1,6 @@ - + @@ -10,5 +10,7 @@ + + \ No newline at end of file