0
0
Selenium Javatesting~10 mins

Nested frames in Selenium Java - Test Execution Trace

Choose your learning style9 modes available
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.

Test Code - JUnit + Selenium
Selenium Java
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();
        }
    }
}
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Test starts and Chrome browser opensBrowser window is open and ready-PASS
2Navigate to URL 'https://the-internet.herokuapp.com/nested_frames'Page with nested frames is loadedPage loaded successfullyPASS
3Wait and switch to outer frame named 'frame-top'Driver context is inside 'frame-top' frameFrame 'frame-top' is available and switchedPASS
4Wait 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 switchedPASS
5Find element with id 'content' inside 'frame-middle'Element with text 'MIDDLE' is visible inside inner frameElement with id 'content' is found and visiblePASS
6Assert that the text of element 'content' equals 'MIDDLE'Text inside inner frame is 'MIDDLE'Text equals 'MIDDLE'PASS
7Test ends and browser closesBrowser window is closed-PASS
Failure Scenario
Failing Condition: If the frame name is incorrect or element with id 'content' is missing
Execution Trace Quiz - 3 Questions
Test your understanding
What is the first frame the test switches to?
Aframe-middle
Bframe-bottom
Cframe-top
Dmain-frame
Key Result
Always switch to the outer frame before switching to nested inner frames. Use explicit waits to ensure frames and elements are available before interacting.