Certificates on an application for hybrid framework | Selenium Python Forum
S
Sambhav Puri Posted on 18/06/2020

Hi. I have to access an application through hybrid framework for which i have to use a particular certificate. How could I do it in the framework for different browsers? Could you provide the relevant piece of code 


J
Jaspreet Replied on 16/07/2020

Hey,

If you have to accept the certificates, then i will request you to watch the module no. 16. The code to accept certificates is there. You just need to add that code in your open browser function


S
Sambhav Puri Replied on 21/01/2021

Hi Jaspreet. With selenium firefox driver i am able to open my created profile on my local system. However, it is not working when i want to use a firefox profile using remote webdriver. Please see below my code. Could you help here

 

caps = DesiredCapabilities.FIREFOX.copy()
profile_path = 'path to firefox profile'
profile = webdriver.FirefoxProfile(profile_path)
self.driver = webdriver.Remote(desired_capabilities=caps, command_executor='hub url here', browser_profile=profile)


J
Jaspreet Replied on 23/01/2021

Hey

Are you getting some error or nothing is happening?

 


S
Sambhav Puri Replied on 25/01/2021

Hi Jaspreet. I am not getting any message in the exception but it is failing when connecting to remote(FYI, i use BDD framework). Please see below the exception.

selenium.common.exceptions.WebDriverException: Message: 

  File "C:\Sambhav\venv_py3\lib\site-packages\behave\model.py", line 1329, in run
    match.run(runner.context)
  File "C:\Sambhav\venv_py3\lib\site-packages\behave\matchers.py", line 98, in run
    self.func(context, *args, **kwargs)
  File "C:\Sambhav\TestAutomationBDDFramework\BDDCommon\CommonSteps\webstepscommon.py", line 12, in i_go_to_page
    webcommon.go_to(context, page)
  File "C:\Sambhav\TestAutomationBDDFramework\BDDCommon\CommonFuncs\webcommon.py", line 79, in go_to
    context.driver = webdriver.Remote(desired_capabilities=caps, command_executor='hub url here',browser_profile=profile)
  File "C:\Sambhav\venv_py3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Sambhav\venv_py3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Sambhav\venv_py3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Sambhav\venv_py3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 208, in check_response
    raise exception_class(value)

 

If i do not pass the profile_path i.e.

profile = webdriver.FirefoxProfile() then it creates a new profile and remote is working fine. 
However, my application needs a certificate otherwise it will not open. FYI, the same profile is working fine with Firefox webdriver and I am able to open my application. i.e.
profile_path = 'path to firefox profile'
profile = webdriver.FirefoxProfile(profile_path)
self.driver = webdriver.Firefox(profile)

 

 


J
Jaspreet Replied on 27/01/2021

Hey, 

I am attaching a file in here, request to include the additions in your code and try working with profile.


S
Sambhav Puri Replied on 27/01/2021

Hi Jaspreet. I am getting the same exception I sent in my last post. Is it working on your hub? I was looking at the below url yesterday:

https://github.com/mozilla/geckodriver/issues/1058

 

Looks like it is related to it. I am out of options right now :(


S
Sambhav Puri Replied on 03/02/2021

Hi Jaspreet. Could you suggest some solution?


J
Jaspreet Replied on 03/02/2021

Hey,

I am looking for the solution at the earliest possible.


S
Sambhav Puri 1 day ago

Hey Jaspreet,

Any luck until now or some workaround?


S
Sambhav Puri 11 hours ago

Hey Jaspreet,

I tried another way of using the profile. I have put my firefox profile inside the container and i am referring the path to it in the argument. However, now the connection is refused if I specify the profile (if i dont specify the profile then the website opens).

Could you help on this.

 

Code:

options = webdriver.FirefoxOptions()
options.add_argument("-profile")

#this profile is present in the container at this path
options.add_argument("/tmp/firefox_profiles/profilename")

profile = webdriver.FirefoxProfile()
profile.set_preference("security.default_personal_cert", "Select Automatically")
profile.set_preference("security.osclientcerts.autoload", True)
profile.set_preference("security.disable_button.openCertManager", True)
profile.set_preference("security.enterprise_roots.enabled", True)
profile.set_preference("accept_untrusted_certs", True)
profile.set_preference("assume_untrusted_cert_issuer", True)
options.profile = profile
context.driver = webdriver.Remote(desired_capabilities=caps, command_executor='hub url here', options=options)

 

Exception:

selenium.common.exceptions.TimeoutException: Message: Connection refused (os error 111)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'firefox container name', ip: 'ip address', os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.0-1035-azure', java.version: '1.8.0_275'
Driver info: driver.version: unknown
remote stacktrace: 
Stacktrace:
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0 (NativeConstructorAccessorImpl.java:-2)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance (Constructor.java:423)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0 (W3CHandshakeResponse.java:62)
    at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0 (HandshakeResponse.java:30)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0 (ProtocolHandshake.java:126)
    at java.util.stream.ReferencePipeline$3$1.accept (ReferencePipeline.java:193)
    at java.util.Spliterators$ArraySpliterator.tryAdvance (Spliterators.java:958)
    at java.util.stream.ReferencePipeline.forEachWithCancel (ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel (AbstractPipeline.java:499)
    at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:486)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:472)
    at java.util.stream.FindOps$FindOp.evaluateSequential (FindOps.java:152)
    at java.util.stream.AbstractPipeline.evaluate (AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst (ReferencePipeline.java:531)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession (ProtocolHandshake.java:128)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession (ProtocolHandshake.java:74)
    at org.openqa.selenium.grid.session.remote.RemoteSession$Factory.performHandshake (RemoteSession.java:147)
    at org.openqa.selenium.grid.session.remote.ServicedSession$Factory.apply (ServicedSession.java:161)
    at org.openqa.selenium.remote.server.ActiveSessionFactory.lambda$apply$12 (ActiveSessionFactory.java:180)
    at java.util.stream.ReferencePipeline$3$1.accept (ReferencePipeline.java:193)
    at java.util.stream.ReferencePipeline$11$1.accept (ReferencePipeline.java:440)
    at java.util.stream.ReferencePipeline$2$1.accept (ReferencePipeline.java:175)
    at java.util.Spliterators$ArraySpliterator.tryAdvance (Spliterators.java:958)
    at java.util.stream.ReferencePipeline.forEachWithCancel (ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel (AbstractPipeline.java:499)
    at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:486)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:472)
    at java.util.stream.FindOps$FindOp.evaluateSequential (FindOps.java:152)
    at java.util.stream.AbstractPipeline.evaluate (AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst (ReferencePipeline.java:531)
    at org.openqa.selenium.remote.server.ActiveSessionFactory.apply (ActiveSessionFactory.java:183)
    at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$null$2 (NewSessionPipeline.java:66)
    at java.util.stream.ReferencePipeline$3$1.accept (ReferencePipeline.java:193)
    at java.util.stream.ReferencePipeline$2$1.accept (ReferencePipeline.java:175)
    at java.util.Collections$2.tryAdvance (Collections.java:4719)
    at java.util.stream.ReferencePipeline.forEachWithCancel (ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel (AbstractPipeline.java:499)
    at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:486)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:472)
    at java.util.stream.FindOps$FindOp.evaluateSequential (FindOps.java:152)
    at java.util.stream.AbstractPipeline.evaluate (AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst (ReferencePipeline.java:531)
    at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$createNewSession$3 (NewSessionPipeline.java:69)
    at java.util.stream.ReferencePipeline$3$1.accept (ReferencePipeline.java:193)
    at java.util.stream.ReferencePipeline$3$1.accept (ReferencePipeline.java:193)
    at java.util.stream.ReferencePipeline$3$1.accept (ReferencePipeline.java:193)
    at java.util.stream.DistinctOps$1$2.accept (DistinctOps.java:175)
    at java.util.stream.ReferencePipeline$2$1.accept (ReferencePipeline.java:175)
    at java.util.stream.ReferencePipeline$3$1.accept (ReferencePipeline.java:193)
    at java.util.stream.ReferencePipeline$2$1.accept (ReferencePipeline.java:175)
    at java.util.stream.Streams$StreamBuilderImpl.tryAdvance (Streams.java:405)
    at java.util.stream.Streams$ConcatSpliterator.tryAdvance (Streams.java:728)
    at java.util.stream.ReferencePipeline.forEachWithCancel (ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel (AbstractPipeline.java:499)
    at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:486)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:472)
    at java.util.stream.FindOps$FindOp.evaluateSequential (FindOps.java:152)
    at java.util.stream.AbstractPipeline.evaluate (AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst (ReferencePipeline.java:531)
    at org.openqa.selenium.remote.server.NewSessionPipeline.createNewSession (NewSessionPipeline.java:72)
    at org.openqa.selenium.remote.server.commandhandler.BeginSession.execute (BeginSession.java:65)
    at org.openqa.selenium.remote.server.WebDriverServlet.lambda$handle$0 (WebDriverServlet.java:235)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
    at java.lang.Thread.run (Thread.java:748)

 

Logs:

1614181838608 mozrunner::runner INFO Running command: "/usr/bin/firefox" "--marionette" "-profile" "/tmp/firefox_profiles/profilename" "-foreground" "-no-remote"
[GFX1-]: glxtest: libpci missing
[GFX1-]: glxtest: libEGL missing
 
(firefox:122): Gtk-WARNING **: 15:50:40.563: Error loading theme icon 'dialog-question' for stock: Icon 'dialog-question' not present in theme Yaru


M
9 hours ago

I also read through some googling that workaround is to set marionette port to 2828. How can we set that? The below deidnt work:

#options.add_argument("--marionette-port")               

#options.add_argument("2828")

 


Related Posts