Test Overview
This test opens a webpage with nested frames. It switches to the inner frame inside the outer frame and verifies the text inside the inner frame.
This test opens a webpage with nested frames. It switches to the inner frame inside the outer frame and verifies the text inside the inner frame.
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.support.ui.WebDriverWait; import org.openqa.selenium.support.ui.ExpectedConditions; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class NestedFramesTest { WebDriver driver; WebDriverWait wait; @BeforeEach public void setUp() { driver = new ChromeDriver(); wait = new WebDriverWait(driver, 10); } @Test public void testNestedFramesText() { driver.get("https://the-internet.herokuapp.com/nested_frames"); // Switch to the outer frame named 'frame-top' wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("frame-top")); // Switch to the inner frame named 'frame-middle' wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("frame-middle")); // Find the content element inside the inner frame WebElement content = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("content"))); // Verify the text inside the inner frame assertEquals("MIDDLE", content.getText()); } @AfterEach public void tearDown() { if (driver != null) { driver.quit(); } } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Browser window is open and ready | - | PASS |
| 2 | Navigate to URL 'https://the-internet.herokuapp.com/nested_frames' | Page with nested frames is loaded | Page loaded successfully | PASS |
| 3 | Wait and switch to outer frame named 'frame-top' | Driver context is inside 'frame-top' frame | Frame 'frame-top' is available and switched | PASS |
| 4 | Wait and switch to inner frame named 'frame-middle' inside 'frame-top' | Driver context is inside 'frame-middle' frame nested in 'frame-top' | Frame 'frame-middle' is available and switched | PASS |
| 5 | Find element with id 'content' inside 'frame-middle' | Element with text 'MIDDLE' is visible inside inner frame | Element with id 'content' is found and visible | PASS |
| 6 | Assert that the text of element 'content' equals 'MIDDLE' | Text inside inner frame is 'MIDDLE' | Text equals 'MIDDLE' | PASS |
| 7 | Test ends and browser closes | Browser window is closed | - | PASS |