pytest-pyodide icon indicating copy to clipboard operation
pytest-pyodide copied to clipboard

Enable setting of selenium runner capabilities

Open joemarshall opened this issue 2 years ago • 3 comments

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

joemarshall avatar Nov 09 '23 16:11 joemarshall

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:

  1. Expose runner classes 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.
  2. Make a helper function (or fixture) that wraps the runner class and creates a selenium compatible 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 avatar Nov 12 '23 12:11 ryanking13

@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.

joemarshall avatar Nov 17 '23 15:11 joemarshall

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

hoodmane avatar Nov 17 '23 19:11 hoodmane