Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set capabilities on Chrome WebDriver #156

Closed
aahamlin opened this issue Jun 25, 2021 · 6 comments
Closed

Unable to set capabilities on Chrome WebDriver #156

aahamlin opened this issue Jun 25, 2021 · 6 comments

Comments

@aahamlin
Copy link

aahamlin commented Jun 25, 2021

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.

@mdpdesign
Copy link

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

@jace
Copy link

jace commented Aug 2, 2022

@mdpdesign Where is webdriver imported from?

@jace
Copy link

jace commented Aug 2, 2022

Found it: from selenium import webdriver

@mpasternak
Copy link
Contributor

mpasternak commented Aug 7, 2022

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!

@mdpdesign
Copy link

mdpdesign commented Aug 7, 2022

@mpasternak - opened a PR - #167

@mpasternak
Copy link
Contributor

Merged #167. Closing this issue, as the documentation in #167 somehow explains what to do in case reported by @aahamlin . On the other hand, if you need any other assistance, please reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants