mozilla / geckodriver

WebDriver for Firefox
https://firefox-source-docs.mozilla.org/testing/geckodriver/
Mozilla Public License 2.0
7.16k stars 1.52k forks source link

Selenium 3.0.1+ Firefox 50.0 would sometimes have connection refused #380

Closed HackToday closed 7 years ago

HackToday commented 7 years ago

If you are having an issue with GeckoDriver starting up, please make sure that your client bindings support using it.

Meta -

OS: CentOS 7.2 e.g.: Windows 10? OSX?

Browser Version: Firefox 50.0 e.g.: 50.0.2623.87 (64-bit)

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 -

Note: Please be sure to include an SSCCE (Short, Self Contained, Correct [compilable] example) http://sscce.org/ If you can't provide a link to the page, consider creating a reproducible page on https://jsfiddle.net/

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

As issue here https://github.com/SeleniumHQ/selenium/issues/3201 selenium guys said The connection refused would be happening when trying to communicate with GeckoDriver

If any of the above are missing we will have to unforunately close your issue. We will gladly reopen the issue once all the information requested has been added

andreastt commented 7 years ago

Not information here to reproduce, and I also suspect this is a Selenium issue. You need to include the stdout from geckodriver as it starts up. I would suggest checking the geckodriver.log file that the Python bindings produce and post it here. If you provide enough reproducible information, I’m happy to re-open this.

HackToday commented 7 years ago

@andreastt sure. I can post here. The firefox and selenium did have such serious annoying random failure issue like this. I suggest we try to solve that issue instead of suspect each other. :smile:

andreastt commented 7 years ago

We want to fix all issues in geckodriver, but we can’t fix the issue unless we know what is wrong or how to reproduce it.

HackToday commented 7 years ago

@andreastt I have collected geckodriver.log please check the file. Let's debug the root cause of the issue. Thanks

https://gist.github.com/HackToday/76c7a767342d495dac0e6b815e0d3c2d

HackToday commented 7 years ago

Also found more serious errors in log here

1481771416951   addons.manager  DEBUG   Provider finished startup: PluginProvider
1481771416951   addons.manager  DEBUG   Completed startup sequence
1481771417136   Marionette  ERROR   Error on starting server: [Exception... "Component returned failure code: 0x804b0036 (NS_ERROR_SOCKET_ADDRESS_IN_USE) [nsIServerSocket.initSpecialConnection]"  nsresult: "0x804b0036 (NS_ERROR_SOCKET_ADDRESS_IN_USE)"  location: "JS frame :: chrome://marionette/content/server.js :: MarionetteServer.prototype.start :: line 85"  data: no]
[Exception... "Component returned failure code: 0x804b0036 (NS_ERROR_SOCKET_ADDRESS_IN_USE) [nsIServerSocket.initSpecialConnection]"  nsresult: "0x804b0036 (NS_ERROR_SOCKET_ADDRESS_IN_USE)"  location: "JS frame :: chrome://marionette/content/server.js :: MarionetteServer.prototype.start :: line 85"  data: no]
MarionetteServer.prototype.start@chrome://marionette/content/server.js:85:19
MarionetteComponent.prototype.init@resource://gre/components/marionettecomponent.js:218:5
MarionetteComponent.prototype.observe@resource://gre/components/marionettecomponent.js:142:7

Perhaps you can check full logs to discover more. @andreastt

andreastt commented 7 years ago

@HackToday That Gecko log doesn’t include Marionette unfortunately. See the README on how to enable verbose logging from Marionette.

Your last paste shows you have something already bound on port 2828.

lock[bot] commented 5 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have run into an issue you think is related, please open a new issue.