Test Overview
This test opens a webpage, locates a button element, and verifies its size and position on the page.
This test opens a webpage, locates a button element, and verifies its size and position on the page.
import org.openqa.selenium.By; import org.openqa.selenium.Dimension; import org.openqa.selenium.Point; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; 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.*; public class ElementDimensionsLocationTest { private WebDriver driver; @BeforeEach public void setUp() { // Set the path to chromedriver executable if necessary // System.setProperty("webdriver.chrome.driver", "path/to/chromedriver"); driver = new ChromeDriver(); } @AfterEach public void tearDown() { if (driver != null) { driver.quit(); } } @Test public void testButtonDimensionsAndLocation() { driver.get("https://example.com"); WebElement button = driver.findElement(By.id("submit-button")); Dimension size = button.getSize(); Point location = button.getLocation(); assertEquals(100, size.getWidth(), "Button width should be 100 pixels"); assertEquals(50, size.getHeight(), "Button height should be 50 pixels"); assertTrue(location.getX() >= 0, "Button X coordinate should be non-negative"); assertTrue(location.getY() >= 0, "Button Y coordinate should be non-negative"); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Chrome browser window is open and ready | - | PASS |
| 2 | Navigates to https://example.com | Page loads with visible elements including a button with id 'submit-button' | - | PASS |
| 3 | Finds element by id 'submit-button' | Button element is located on the page | - | PASS |
| 4 | Gets size of the button element | Size object with width and height retrieved | Button width equals 100 pixels and height equals 50 pixels | PASS |
| 5 | Gets location of the button element | Location object with X and Y coordinates retrieved | Button X and Y coordinates are non-negative | PASS |
| 6 | Assertions verify size and location values | Test verifies expected dimensions and location | All assertions pass confirming correct size and location | PASS |