Since you're running tests in a headless mode, there is no active
browser window available. As such your
driver.driver.manage().window().maximize()
would always fail in such situations because the driver doesn't know which window to maximize since there aren't any available.
You can either follow what @DebanjanB has mentioned or you can start the headless browser with a specific screen size like 1440x900 etc, doing something like this
driver.manage().window().setSize(new Dimension(1440, 900));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…