Test Overview
This test opens a web page, sets an implicit wait, tries to find a button by its ID, clicks it, and verifies the page title changes as expected.
This test opens a web page, sets an implicit wait, tries to find a button by its ID, clicks it, and verifies the page title changes as expected.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.time.Duration; import static org.junit.Assert.assertEquals; import org.junit.After; import org.junit.Before; import org.junit.Test; public class ImplicitWaitTest { private WebDriver driver; @Before public void setUp() { driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); } @Test public void testButtonClickChangesTitle() { driver.get("https://example.com/testpage"); WebElement button = driver.findElement(By.id("delayedButton")); button.click(); String expectedTitle = "Button Clicked"; assertEquals(expectedTitle, driver.getTitle()); } @After public void tearDown() { if (driver != null) { driver.quit(); } } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Chrome browser window is open and ready | - | PASS |
| 2 | Set implicit wait timeout to 10 seconds | Driver configured to wait up to 10 seconds when locating elements | - | PASS |
| 3 | Navigate to https://example.com/testpage | Page loads with a button having id 'delayedButton' that appears after a short delay | - | PASS |
| 4 | Find element by id 'delayedButton' using implicit wait | Driver waits up to 10 seconds until the button is present in DOM | Element with id 'delayedButton' is found | PASS |
| 5 | Click the found button | Button is clicked, triggering page title change | - | PASS |
| 6 | Verify page title is 'Button Clicked' | Page title updated after button click | Assert that driver.getTitle() equals 'Button Clicked' | PASS |
| 7 | Close browser and end test | Browser closed, resources released | - | PASS |