Search code examples
c#seleniumcookiesselenium-chromedriverselenium-hub

Selenium Hub Chrome Node does not get HttpOnly Cookies


I am running Selenium tests in two ways:

  1. locally with Chrome WebDriver, for implementing the tests
  2. in a CI-pipeline with Selenium Hub and a Chrome Node, to run the tests

The backend creates HttpOnly cookies. I want to check their existence. To get a specific cookie I use the following code:

driver.Manage().Cookies.GetCookieNamed("CookieFooBar");

This works perfectly with the Chrome WebDriver, but does not work with the Chrome Node. Any ideas, what might cause this different behavior?


Solution

  • The answer to this problem is already inside the question itself. As the cookies are HttpOnly cookies, the browser can't track their existence - nevertheless they are still existing. This is actually the reason the HttpOnly flag was created for.

    For testing purposes it might be a better approach to test the functionality the cookies should provide instead of simply checking their existence.

    I ran the Chrome WebDriver tests without a docker-compose, which I did in the CI-pipeline. That is why the browser was not able to see the HttpOnly cookies.