0

I'm trying to run a simple test on a headless browser. In my sample test when I take a screenshot I just get a blank screen when accessing my staging website, but production websites such as http://www.google.co.uk work correctly. So I guess we need to set headers in order to access our staging?

Does anyone know how to do this on selenium for a headless browser?

The code I have is:

public void testPhantom() throws IOException {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setJavascriptEnabled(true);
    caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "phantomjs");
    Webdriver driver = new PhantomJSDriver(caps);

    open("https://mywebsite.staging.com/");
    takeAScreenshot("Website");
}

==================================================

UPDATE

Found the solution by reading this post: PhantomJSDriver works for HTTP but not for HTTPS

Community
  • 1
  • 1
Daredevi1
  • 103
  • 3
  • 13

1 Answers1

0

I have not tested this personally, but the GhostDriver documentation has the following at https://github.com/detro/ghostdriver#what-extra-webdriver-capabilities-ghostdriver-offers

phantomjs.page.customHeaders.HEADER = VALUE - Add extra HTTP Headers when loading a URL

And from the PR: https://github.com/detro/ghostdriver/pull/229 :

PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX = "phantomjs.page.customHeaders."; //< notice the dot at the end
capabilities.setCapability(PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + "Accept-Language", "it-IT");
nofacade
  • 96
  • 2
  • 4