Test Overview
This test performs a mouse hover action on a menu item using Selenium WebDriver in Java. It verifies that the submenu becomes visible after hovering.
This test performs a mouse hover action on a menu item using Selenium WebDriver in Java. It verifies that the submenu becomes visible after hovering.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Actions; import org.junit.Assert; import org.junit.After; import org.junit.Before; import org.junit.Test; public class MouseHoverTest { private WebDriver driver; @Before public void setUp() { driver = new ChromeDriver(); driver.manage().window().maximize(); driver.get("https://example.com/menu"); } @Test public void testMouseHoverShowsSubMenu() { WebElement menu = driver.findElement(By.id("menu-item")); Actions actions = new Actions(driver); actions.moveToElement(menu).perform(); WebElement subMenu = driver.findElement(By.id("submenu-item")); Assert.assertTrue(subMenu.isDisplayed()); } @After public void tearDown() { if (driver != null) { driver.quit(); } } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Browser window is maximized and ready | - | PASS |
| 2 | Navigates to https://example.com/menu | Page with menu loaded | - | PASS |
| 3 | Finds the menu item element by id 'menu-item' | Menu item element is located on the page | - | PASS |
| 4 | Performs mouse hover action on the menu item using Actions.moveToElement().perform() | Mouse pointer is over the menu item, submenu should appear | - | PASS |
| 5 | Finds the submenu item element by id 'submenu-item' | Submenu element is located on the page | - | PASS |
| 6 | Checks if submenu item is displayed using isDisplayed() | Submenu is visible on the page | Assert.assertTrue(subMenu.isDisplayed()) verifies submenu visibility | PASS |
| 7 | Test ends and browser closes | Browser closed, resources released | - | PASS |