@@ -51,6 +51,20 @@ public static void initDriver() {
5151
5252 System .out .println (">>> Antes de new ChromeDriver" );
5353 driver = new ChromeDriver (options );
54+
55+ if (headless ) {
56+ ((ChromeDriver ) driver ).executeCdpCommand (
57+ "Emulation.setDeviceMetricsOverride" ,
58+ Map .of (
59+ "width" , 1920 ,
60+ "height" , 1080 ,
61+ "deviceScaleFactor" , 1 ,
62+ "mobile" , false
63+ )
64+ );
65+ System .out .println (">>> Viewport CDP forzado a 1920x1080" );
66+ }
67+
5468 driver .manage ().window ().setSize (new org .openqa .selenium .Dimension (1920 , 1080 ));
5569 System .out .println (">>> Chrome abierto OK" );
5670
@@ -60,18 +74,18 @@ public static void initDriver() {
6074 throw new RuntimeException ("Browser no soportado: " + browser );
6175 }
6276
63- applyConfig (driver );
77+ applyConfig (driver , headless );
6478 }
6579
66- private static void applyConfig (WebDriver driver ) {
80+ private static void applyConfig (WebDriver driver , boolean headless ) {
6781 int implicit = Integer .parseInt (ConfigReader .getProperty ("timeout.implicit" ));
6882 int pageLoad = Integer .parseInt (ConfigReader .getProperty ("timeout.pageLoad" ));
6983 boolean maximize = Boolean .parseBoolean (ConfigReader .getProperty ("window.maximize" ));
7084
7185 driver .manage ().timeouts ().implicitlyWait (Duration .ofSeconds (implicit ));
7286 driver .manage ().timeouts ().pageLoadTimeout (Duration .ofSeconds (pageLoad ));
7387
74- if (maximize ) {
88+ if (maximize && ! headless ) {
7589 driver .manage ().window ().maximize ();
7690 }
7791 }
0 commit comments