pytest-pyodide
pytest-pyodide copied to clipboard
Enable setting of selenium runner capabilities
Selenium runners take a desired capabilities option, which allows you to do things like turn off https verification of certificates.
I can see we have access to Options, so I can do e.g.
pytest_pyodide.runner.CHROME_FLAGS.append("ignore-certificate-errors") for chrome, but if I want to do it for all browsers, I need a capability, which is set like below. Could we have a capability setter in there also, similar to CHROME_FLAGS etc.
capabilities = webdriver.DesiredCapabilities().FIREFOX
capabilities['acceptSslCerts'] = False
https://stackoverflow.com/questions/24507078/how-to-deal-with-certificates-using-selenium
Thanks for opening the issue, @joemarshall! I agree that we need some way to provide custom options for browsers.
I can see we have access to Options, so I can do e.g.
pytest_pyodide.runner.CHROME_FLAGS.append("ignore-certificate-errors")
This is actually not a recommended official usage by any means, and is only used to change flags in Pyodide hackily. We need a more robust and better way to handle this.
Currently, the selenium fixture does not allow any modifications at the webdriver level. So I think we need a slightly lower level fixture than the selenium.
What I can think of is:
- Expose
runnerclasses and let users make their own runner class by inheriting existing runner classes. 1.1. We need to document which methods can / need to be modified to use custom webdriver options. - Make a helper function (or fixture) that wraps the runner class and creates a
seleniumcompatible fixture.
For example,
In pytest-pyodide:
@contextlib.contextmanager
def build_selenium_fixture(runner):
runner.clean_logs(...)
runner.set_script_timeout(...)
try:
yield runner
finally:
runner.quit()
Then users can do something like:
from pytest_pyodide.runner import SeleniumChromeRunner
class MyChromeRunner(SeleniumChromeRunner):
def get_driver(): # override
return Chrome(options=my_custom_options)
@pytest.fixture
def selnium_my_custom_chrome():
from pytest_pyodide import build_selenium_fixture
chrome_runner = MyChromeRunner(...)
selenium = build_selenium_fixture(chrome_runner)
try:
yield selenium
finally:
selenium.close()
@ryanking13 Nice idea. In addition to this - I'd like to have the ability to use the node runner with extra packages required (I need to require('xmlhttprequest') in the test runner for urllib3, so I want to subclass that also.
I'd like to have the ability to use the node runner with extra packages required
This would be useful for Pyodide itself cf #120 #121