Careeroza
Window Size and Position
Managing the Window
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
driver.manage().window().maximize(); // full screen work area
driver.manage().window().setSize(new Dimension(375, 812)); // iPhone-like width for responsive checks
driver.manage().window().setPosition(new Point(0, 0));
Dimension size = driver.manage().window().getSize();
System.out.println(size.getWidth() + " x " + size.getHeight());Example
Output:
Run WindowTest.main()Example output
375 x 812
Why Size Matters
ShopEase shows a hamburger menu below 768 px width and a full menu above it. If your test machine has a small screen, a locator for the full menu can fail. Set a fixed size at the start of every test so results are the same on every laptop and CI server.
Note: maximize() does nothing useful in headless mode. Use --window-size=1920,1080 there (next page).