Unable to set capabilities on Chrome WebDriver
aahamlin opened this issue · 6 comments
I am trying to use pytest-splinter
fixtures splinter_webdriver
and splinter_driver_kwargs
to enable Chrome to run in Incognito mode and ignore certificate errors to enable testing from a local dev environment versus a hosted site with valid certs.
I am unable to find the combination of arguments that make Chrome work, and conversely, make Firefox break.
When I do not use the fixtures and just create my own splinter Browser instance it works fine.
@pytest.fixture(scope='session')
def my_browser():
caps = webdriver.DesiredCapabilities.CHROME.copy()
caps["acceptInsecureCerts"] = True
caps["acceptSslCerts"] = True
browser = Browser('chrome', incognito=True, desired_capabilities=caps)
return browser
However, in my desired scenario, when splinter_webdriver
returns "chrome" and splinter_driver_kwargs
returns any of the following configurations, the invalid cert authority error has not been bypassed. Also, of note, attempting to override the capabilities for FireFox and force it to fail on the invalid certs also does not work.
def splinter_driver_kwargs():
chrome_options = webdriver.ChromeOptions()
chrome_options.set_capability("acceptInsecureCerts", True)
chrome_options.set_capability("acceptSslCerts", True)
# caps = webdriver.DesiredCapabilities.CHROME.copy()
# caps["acceptInsecureCerts"] = True
# caps["acceptSslCerts"] = True
# XXX just a test to try and break FF on insecure certs, but it does not work =(
# caps = webdriver.DesiredCapabilities.FIREFOX.copy()
# caps["acceptInsecureCerts"] = False
return {
"incognito": True,
"options": chrome_options,
# "capabilities": caps,
# "desired_capabilities": caps
}
What are the recommended steps in this case?
Thanks.
Hi, I was searching for the same answer, I was able to update Chrome options with this:
@pytest.fixture(scope='session')
def splinter_driver_kwargs():
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--ignore-ssl-errors=yes")
chrome_options.add_argument("--ignore-certificate-errors")
return {"options": chrome_options}
Based on this: https://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.chrome.webdriver and https://stackoverflow.com/a/60250587
@mdpdesign Where is webdriver
imported from?
Found it: from selenium import webdriver
Hi @aahamlin , does the reply from @mdpdesign solve your problem? Would any of you like to add this wonderful code snippet to docs, so we won't lose it? PRs accepted!
@mpasternak - opened a PR - #167