Issues with running Headless


I have recently created a test suite with tests that run and pass 100& of the time when running in Chrome.
I am trying to integrate a Docker pipeline so I will need these tests to run in headless mode.

The problem I see is that when running the test suite in headless random elements will not be found on each run.
When I run a single test it passes. When I run the suite of more than one test it will fail on different tests at different stages.

I have tried the ‘Wait for element to be visible etc’ but as different elements cannot be found each time it fails, i am against wrapping every step of every test in this.
Can anyone offer any advice as to how to manage this?


That maybe because the page is rendered differently for headless and GUI mode. You can confirm this by capturing the page sources and compare them between 2 modes

WebDriver driver = DriverFactory.getWebDriver()
println driver.getPageSource()