Ouranosinc / PAVICS-e2e-workflow-tests

Test user-level workflow.
Apache License 2.0
0 stars 2 forks source link

Selenium+Firefox within pavics does not work (X-server?) #120

Closed SarahG-579462 closed 1 year ago

SarahG-579462 commented 1 year ago

Selenium et firefox sont installés, but doesn't seem to work, details below on basic test:

example ``` --------------------------------------------------------------------------- WebDriverException Traceback (most recent call last) Cell In [5], line 3 1 from selenium import webdriver ----> 3 browser = webdriver.Firefox() 4 browser.get('http://selenium.dev/') File /opt/conda/envs/birdy/lib/python3.8/site-packages/selenium/webdriver/firefox/webdriver.py:197, in WebDriver.__init__(self, firefox_profile, firefox_binary, capabilities, proxy, executable_path, options, service_log_path, service_args, service, desired_capabilities, log_path, keep_alive) 192 self.service.start() 194 executor = FirefoxRemoteConnection( 195 remote_server_addr=self.service.service_url, ignore_proxy=options._ignore_local_proxy 196 ) --> 197 super().__init__(command_executor=executor, options=options, keep_alive=True) 199 self._is_remote = False File /opt/conda/envs/birdy/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py:288, in WebDriver.__init__(self, command_executor, desired_capabilities, browser_profile, proxy, keep_alive, file_detector, options) 286 self._authenticator_id = None 287 self.start_client() --> 288 self.start_session(capabilities, browser_profile) File /opt/conda/envs/birdy/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py:381, in WebDriver.start_session(self, capabilities, browser_profile) 379 w3c_caps = _make_w3c_caps(capabilities) 380 parameters = {"capabilities": w3c_caps} --> 381 response = self.execute(Command.NEW_SESSION, parameters) 382 if "sessionId" not in response: 383 response = response["value"] File /opt/conda/envs/birdy/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py:444, in WebDriver.execute(self, driver_command, params) 442 response = self.command_executor.execute(driver_command, params) 443 if response: --> 444 self.error_handler.check_response(response) 445 response["value"] = self._unwrap_value(response.get("value", None)) 446 return response File /opt/conda/envs/birdy/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py:249, in ErrorHandler.check_response(self, response) 247 alert_text = value["alert"].get("text") 248 raise exception_class(message, screen, stacktrace, alert_text) # type: ignore[call-arg] # mypy is not smart enough here --> 249 raise exception_class(message, screen, stacktrace) WebDriverException: Message: Process unexpectedly closed with status 1 ```

c'est probablement à cause d'un manque de x-server. Une option pour un X-server headless c'est Xvfb

tlvu commented 1 year ago

I am pretty sure Selenium + FF works in the Jupyter env because I think Bokeh use it to save interractive graphics.

Have you tried specifying headless mode:

from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium import webdriver

options = FirefoxOptions()
options.add_argument("--headless")
driver = webdriver.Firefox(options=options)
driver.get("http://google.com")

From https://stackoverflow.com/a/55834112

This answer is from 2020. Maybe the procedure is different now but the idea remains the same, try to use headless mode because no X-server.

SarahG-579462 commented 1 year ago

Ah, thanks, the headless argument was what was missing! cheers :)