2

Headless Selenium tests can be well run on my machine (yup, I should definitely move in this ideal place where problems doesn't exist).

However, when I launch those tests via Jenkins, none of the page elements are found. I took a screenshot to figure out why, and it shows a blank page.

This is how I instanciate my headless Chrome browser.

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--window-size=1920x1080");
chromeOptions.addArguments("start-maximised");
chromeOptions.addArguments("enable-automation");
chromeOptions.addArguments("--no-sandbox");
chromeOptions.addArguments("--disable-infobars");
chromeOptions.addArguments("--disable-dev-shm-usage");
chromeOptions.addArguments("--disable-browser-side-navigation");
chromeOptions.addArguments("--disable-gpu");
driver = new ChromeDriver(chromeOptions);
driver.manage().timeouts().pageLoadTimeout(30L, TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(3L, TimeUnit.SECONDS);
driver.manage().window().maximize();

I have a guess but my coworker says it can't be this: should I install Xvfb on Jenkins server? I mean, is it mandatory? (I must be at least 51% sure before trying this approach ^^)

Thanks in advance.

Zoette
  • 1,241
  • 2
  • 18
  • 49
  • Do the tests run in headless mode on your machine as well? – Greg Burghardt May 14 '20 at 01:13
  • Which version of Chrome and ChromeDriver are installed on the Jenkins machine? – Greg Burghardt May 14 '20 at 01:14
  • @GregBurghardt yes they run headless on my machine wtih no problem. For the versions, I guess they are ok, because I'm using `webdrivermanager`... – Zoette May 14 '20 at 20:57
  • That's not necessarily true. The versions matter a lot. A version mismatch between browser and web driver can cause this. – Greg Burghardt May 14 '20 at 21:46
  • @GregBurghardt hi, `google-chrome --product-version` returns `81.0.4044.138`, and then I see `Starting ChromeDriver 81.0.4044.138`, so I guess there are no compatibility issues... I'm definitely stuck :( – Zoette May 24 '20 at 22:23
  • @Y-B Cause: Was this ever resolved? – Shashank Kadne May 30 '20 at 09:38
  • @ShashankKadne not yet. I'll keep you updated – Zoette Jun 02 '20 at 22:53
  • @Y-B Cause: You usually will not need xvbf. It's only required if you want to run your tests in head mode. Also can you confirm if the site that you are trying to access has security issues? If so you will need to accept insecure certs by setting the option in chrome driver. – Shashank Kadne Jun 07 '20 at 14:15

1 Answers1

0

I tried lots of solutions but it turned out that Jenkins wasn't allowed to access the resources I needed to test. So... I couldn't solve it myself anyway. Sysadmins did.

Zoette
  • 1,241
  • 2
  • 18
  • 49