Skip to content

Enable setting of selenium runner capabilities #118

Description

@joemarshall

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

Activity

  1. ryanking13 commented on Nov 12, 2023

    @ryanking13
    Member

    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()
  2. joemarshall commented on Nov 17, 2023

    @joemarshall
    CollaboratorAuthor

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

  3. hoodmane commented on Nov 17, 2023

    @hoodmane
    Member

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions