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

Enable setting of selenium runner capabilities #118

Open
joemarshall opened this issue Nov 9, 2023 · 3 comments
Open

Enable setting of selenium runner capabilities #118

joemarshall opened this issue Nov 9, 2023 · 3 comments

Comments

@joemarshall
Copy link
Collaborator

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

@ryanking13
Copy link
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()

@joemarshall
Copy link
Collaborator Author

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

@hoodmane
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants