0
0
Selenium Javatesting~10 mins

Multi-page navigation flow in Selenium Java - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test automates a user navigating through multiple pages on a website. It verifies that each page loads correctly by checking the page title after navigation.

Test Code - JUnit with Selenium WebDriver
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.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
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;
import java.time.Duration;

public class MultiPageNavigationTest {
    private WebDriver driver;
    private WebDriverWait wait;

    @BeforeEach
    public void setUp() {
        driver = new ChromeDriver();
        wait = new WebDriverWait(driver, Duration.ofSeconds(10));
    }

    @Test
    public void testMultiPageNavigation() {
        // Step 1: Open homepage
        driver.get("https://example.com");
        wait.until(ExpectedConditions.titleIs("Example Domain"));
        assertEquals("Example Domain", driver.getTitle());

        // Step 2: Click on More Information link
        WebElement moreInfoLink = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("a[href='https://www.iana.org/domains/example']")));
        moreInfoLink.click();

        // Step 3: Wait for new page and verify title
        wait.until(ExpectedConditions.titleContains("IANA"));
        assertEquals(true, driver.getTitle().contains("IANA"));

        // Step 4: Navigate back to homepage
        driver.navigate().back();
        wait.until(ExpectedConditions.titleIs("Example Domain"));
        assertEquals("Example Domain", driver.getTitle());
    }

    @AfterEach
    public void tearDown() {
        if (driver != null) {
            driver.quit();
        }
    }
}
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Test starts and Chrome browser opensBrowser window is open with no page loaded-PASS
2Navigates to https://example.comHomepage loads with title 'Example Domain'Check page title equals 'Example Domain'PASS
3Finds 'More Information' link by CSS selector and clicks itBrowser navigates to https://www.iana.org/domains/exampleWait until page title contains 'IANA'PASS
4Verifies page title contains 'IANA'Page loaded with title containing 'IANA'Assert page title contains 'IANA'PASS
5Navigates back to previous pageBrowser returns to https://example.com homepageWait until page title is 'Example Domain'PASS
6Verifies page title is 'Example Domain' againHomepage displayed with correct titleAssert page title equals 'Example Domain'PASS
7Test ends and browser closesBrowser window closed-PASS
Failure Scenario
Failing Condition: The 'More Information' link is not found or not clickable
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after clicking the 'More Information' link?
AThat the URL is exactly 'https://example.com'
BThat the new page title contains 'IANA'
CThat the homepage title is still 'Example Domain'
DThat the browser closes immediately
Key Result
Always use explicit waits like WebDriverWait with ExpectedConditions to ensure elements or page states are ready before interacting or asserting. This prevents flaky tests in multi-page navigation flows.