Select client certificate for authorization in Chrome headless mode
Asked Answered
H

1

6

I'm trying to run tests in headless Chrome using Geb. Before enter the page, I have to select client certificate for authentication. How to do this in headless mode?

Robot class not working without UI.

Is there any way to handle certificate selection? I read about policies and AutoSelectCertificateForUrls but I can't find way to load policy from file or set this particular parameter as option/argument (Chrome on Linux).

In PhantomJS there is option to provide certificate as argument but how to do this using Chrome driver?

Haemocyte answered 9/5, 2019 at 8:23 Comment(7)
As for AutoSelectCertificateForUrls, which OS are you working on? Windows, Linux, MacOS?Planogamete
I'm working on Linux.Haemocyte
Have you read this and are you in control of directory /etc/opt/chrome/policies? Then you could add AutoSelectCertificateForUrls to a JSON file in the managed subdirectory. Tell me if that helps and I will convert the comment into an answer.Planogamete
Yes, it works but only when running chrome in normal mode (not headless). In headless mode policies are not supported.Haemocyte
I think PhantomJS is dead, so question is more relevant today. We have the same problem.Hammerfest
Does anyone have an answer for this? Firefox has an option for this, but we can't come up with a viable approach with Chrome.Pages
At the moment, the only way is to install certificate manualy like this and run Chrome in xvfb. Another way might be to use stunnel with a client certificate, but to change certificate you have to reconfigure and restart stunnel.Haemocyte
L
2

I had the same problem and ended up running in headful mode instead. There are some stuff required to be installed on the server though to be able to run Selenium in headful mode. I wrote an article on the subject using Selenium with .NET Core in linux with environment setup through docker.

https://sgedda.medium.com/running-selenium-with-chromedriver-together-with-client-certificate-set-in-headful-mode-with-net-a79bde19e472

Dockerfile https://gist.githubusercontent.com/sgedda/584aa35a0d9162ad24f9cca836266959/raw/1fc0b4e6e8c76b791437bc847b67b2ed676c5d9b/Dockerfile

Logjam answered 21/3, 2021 at 14:10 Comment(1)
After a lot of trial and error with headless mode, this post really helped me ... using xvfb was the only way I could get client certs to work with selenium and the chrome driver. One tip for making the solution just a bit more elegant: Use xvfb-run. This will prevent you from having to explicitly export the port variable and kill the xvfb process when done. I got this tip form elementalselenium.com/tips/38-headlessStines

© 2022 - 2024 — McMap. All rights reserved.