SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.52k stars 8.16k forks source link

Selenium 3.0.1+ Firefox 50.0 would sometimes have WebDriverException: Message: connection refused #3201

Closed HackToday closed 7 years ago

HackToday commented 7 years ago

Meta -

OS: CentOS 7.2

Selenium Version: 3.0.1

Browser: Firefox 50.0

Browser Version: 50.0

Expected Behavior -

Test would run OK

Actual Behavior -

Sometimes test would fail with connection refused, it is clearly not test issue, it is possible about selenium or Firefox issue

Steps to reproduce -

Can not give a easy steps to reproduce, it can sometime happen. (maybe 3 in 10 times)

request = <SubRequest 'driver' for <Function 'test_app_rs_edit_port'>>
driver_class = <class 'selenium.webdriver.firefox.webdriver.WebDriver'>
driver_kwargs = {'firefox_profile': <selenium.webdriver.firefox.firefox_profile.FirefoxProfile object at 0x2603c10>}

    @pytest.yield_fixture
    def driver(request, driver_class, driver_kwargs):
        """Returns a WebDriver instance based on options and capabilities"""
>       driver = driver_class(**driver_kwargs)

/usr/lib/python2.7/site-packages/pytest_selenium/pytest_selenium.py:107: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py:145: in __init__
    keep_alive=True)
/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py:92: in __init__
    self.start_session(desired_capabilities, browser_profile)
/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py:179: in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py:236: in execute
    self.error_handler.check_response(response)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x273fad0>
response = {'status': 500, 'value': '{"error":"unknown error","message":"connection refused"}'}

    def check_response(self, response):
        """
            Checks that a JSON response from the WebDriver does not have an error.

            :Args:
             - response - The JSON response from the WebDriver server as a dictionary
               object.

            :Raises: If the response contains an error message.
            """
        status = response.get('status', None)
        if status is None or status == ErrorCode.SUCCESS:
            return

        value = None
        message = response.get("message", "")
        screen = response.get("screen", "")
        stacktrace = None
        if isinstance(status, int):
            value_json = response.get('value', None)
            if value_json and isinstance(value_json, basestring):
                import json
                try:
                    value = json.loads(value_json)
                    status = value.get('error', None)
                    if status is None:
                        status = value["status"]
                        message = value["value"]
                        if not isinstance(message, basestring):
                            value = message
                            try:
                                message = message['message']
                            except TypeError:
                                message = None
                    else:
                        message = value.get('message', None)
                except ValueError:
                    pass

        exception_class = ErrorInResponseException
        if status in ErrorCode.NO_SUCH_ELEMENT:
            exception_class = NoSuchElementException
        elif status in ErrorCode.NO_SUCH_FRAME:
            exception_class = NoSuchFrameException
        elif status in ErrorCode.NO_SUCH_WINDOW:
            exception_class = NoSuchWindowException
        elif status in ErrorCode.STALE_ELEMENT_REFERENCE:
            exception_class = StaleElementReferenceException
        elif status in ErrorCode.ELEMENT_NOT_VISIBLE:
            exception_class = ElementNotVisibleException
        elif status in ErrorCode.INVALID_ELEMENT_STATE:
            exception_class = InvalidElementStateException
        elif status in ErrorCode.INVALID_SELECTOR \
                or status in ErrorCode.INVALID_XPATH_SELECTOR \
                or status in ErrorCode.INVALID_XPATH_SELECTOR_RETURN_TYPER:
            exception_class = InvalidSelectorException
        elif status in ErrorCode.ELEMENT_IS_NOT_SELECTABLE:
            exception_class = ElementNotSelectableException
        elif status in ErrorCode.INVALID_COOKIE_DOMAIN:
            exception_class = WebDriverException
        elif status in ErrorCode.UNABLE_TO_SET_COOKIE:
            exception_class = WebDriverException
        elif status in ErrorCode.TIMEOUT:
            exception_class = TimeoutException
        elif status in ErrorCode.SCRIPT_TIMEOUT:
            exception_class = TimeoutException
        elif status in ErrorCode.UNKNOWN_ERROR:
            exception_class = WebDriverException
        elif status in ErrorCode.UNEXPECTED_ALERT_OPEN:
            exception_class = UnexpectedAlertPresentException
        elif status in ErrorCode.NO_ALERT_OPEN:
            exception_class = NoAlertPresentException
        elif status in ErrorCode.IME_NOT_AVAILABLE:
            exception_class = ImeNotAvailableException
        elif status in ErrorCode.IME_ENGINE_ACTIVATION_FAILED:
            exception_class = ImeActivationFailedException
        elif status in ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS:
            exception_class = MoveTargetOutOfBoundsException
        else:
            exception_class = WebDriverException
        if value == '' or value is None:
            value = response['value']
        if isinstance(value, basestring):
            if exception_class == ErrorInResponseException:
                raise exception_class(response, value)
            raise exception_class(value)
        if message == "" and 'message' in value:
            message = value['message']

        screen = None
        if 'screen' in value:
            screen = value['screen']

        stacktrace = None
        if 'stackTrace' in value and value['stackTrace']:
            stacktrace = []
            try:
                for frame in value['stackTrace']:
                    line = self._value_or_default(frame, 'lineNumber', '')
                    file = self._value_or_default(frame, 'fileName', '<anonymous>')
                    if line:
                        file = "%s:%s" % (file, line)
                    meth = self._value_or_default(frame, 'methodName', '<anonymous>')
                    if 'className' in frame:
                        meth = "%s.%s" % (frame['className'], meth)
                    msg = "    at %s (%s)"
                    msg = msg % (meth, file)
                    stacktrace.append(msg)
            except TypeError:
                pass
        if exception_class == ErrorInResponseException:
            raise exception_class(response, message)
        elif exception_class == UnexpectedAlertPresentException and 'alert' in value:
            raise exception_class(message, screen, stacktrace, value['alert'].get('text'))
>       raise exception_class(message, screen, stacktrace)
E       WebDriverException: Message: connection refused

/usr/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py:192: WebDriverException

Note I think it was an old issue, like in selenium 2.53.x WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details. Googled The https://snakeycode.wordpress.com/2016/06/11/selenium-and-firefox-problems/ the link said selenium and Marionette could solve that issue. Right now, we did not see the The browser appears to have exited , However, we have a new issue above 'WebDriverException: Message: connection refused'

lukeis commented 7 years ago

Most of us on the selenium project don't use CentOS, thus why no one has likely figured out what issues are occurring on that platform. There was a previously reported issue #3122

But based on the selenium and firefox versions listed, I assume you are using GeckoDriver. The connection refused would be happening when trying to communicate with GeckoDriver. Please log a bug for that project here: https://github.com/mozilla/geckodriver/issues

HackToday commented 7 years ago

@lukeis CentOS would possible not a good reason about this issue. First. CentOS is not mini OS. it is used by many people. And second, this connectivity is not OS related. The above log error not related with CentOS itself.

Perhaps we thought we could ask Firefox first, If they can give more hint if it is related with selenium support or not.