atlassian / docker-chromium-xvfb

Docker image for running browser tests against headless Chromium
MIT License
398 stars 125 forks source link

Python 3 sample fails #20

Closed mschwager closed 7 years ago

mschwager commented 7 years ago

Hey!

Interesting project you've got here! Who knew trying to run Selenium tests in a Docker container would be such a PITA?

So, I'm trying to run your sample images, and Python 2 works while Python 3 doesn't:

$ docker build -t sample-2 python2/
Sending build context to Docker daemon 4.608 kB
Step 1 : FROM markadams/chromium-xvfb-py2:latest-onbuild
# Executing 3 build triggers...
Step 1 : COPY requirements.txt /usr/src/app/requirements.txt
 ---> Using cache
Step 1 : RUN pip install -r requirements.txt
 ---> Using cache
Step 1 : COPY . /usr/src/app
 ---> Using cache
 ---> 477e657c73e4
Step 2 : RUN mkdir test-results
 ---> Using cache
 ---> 3d1115ee728b
Successfully built 3d1115ee728b
$ docker run sample-2
============================= test session starts ==============================
platform linux2 -- Python 2.7.9, pytest-3.0.6, py-1.4.32, pluggy-0.4.0
rootdir: /usr/src/app, inifile: setup.cfg
collected 1 items

test_google.py .

--------- generated xml file: /usr/src/app/test-results/results.py.xml ---------
=========================== 1 passed in 2.61 seconds ===========================
$ docker build -t sample-3 python3/
Sending build context to Docker daemon 4.608 kB
Step 1 : FROM markadams/chromium-xvfb-py3:latest-onbuild
# Executing 3 build triggers...
Step 1 : COPY requirements.txt /usr/src/app/requirements.txt
 ---> Using cache
Step 1 : RUN pip3 install -r requirements.txt
 ---> Using cache
Step 1 : COPY . /usr/src/app
 ---> Using cache
 ---> a503c017e9ba
Step 2 : RUN mkdir test-results
 ---> Using cache
 ---> 57808ed4257e
Successfully built 57808ed4257e
$ docker run sample-3
============================= test session starts ==============================
platform linux -- Python 3.4.2, pytest-3.0.6, py-1.4.32, pluggy-0.4.0
rootdir: /usr/src/app, inifile: setup.cfg
collected 1 items

test_google.py FE

--------- generated xml file: /usr/src/app/test-results/results.py.xml ---------
==================================== ERRORS ====================================
__ ERROR at teardown of ExampleTests.test_google_title_matches_correct_value ___

self = <test_google.ExampleTests testMethod=test_google_title_matches_correct_value>

    def tearDown(self):
>       self.driver.close()

test_google.py:15: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py:510: in close
    self.execute(Command.CLOSE)
/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py:234: in execute
    response = self.command_executor.execute(driver_command, params)
/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/remote_connection.py:408: in execute
    return self._request(command_info[0], url, body=data)
/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/remote_connection.py:439: in _request
    self._conn.request(method, parsed_url.path, body, headers)
/usr/lib/python3.4/http/client.py:1090: in request
    self._send_request(method, url, body, headers)
/usr/lib/python3.4/http/client.py:1128: in _send_request
    self.endheaders(body)
/usr/lib/python3.4/http/client.py:1086: in endheaders
    self._send_output(message_body)
/usr/lib/python3.4/http/client.py:924: in _send_output
    self.send(msg)
/usr/lib/python3.4/http/client.py:859: in send
    self.connect()
/usr/lib/python3.4/http/client.py:836: in connect
    self.timeout, self.source_address)
/usr/lib/python3.4/socket.py:509: in create_connection
    raise err
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

address = ('127.0.0.1', '43205'), timeout = <object object at 0x7f80cb82d0e0>
source_address = None

    def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT,
                          source_address=None):
        """Connect to *address* and return the socket object.

        Convenience function.  Connect to *address* (a 2-tuple ``(host,
        port)``) and return the socket object.  Passing the optional
        *timeout* parameter will set the timeout on the socket instance
        before attempting to connect.  If no *timeout* is supplied, the
        global default timeout setting returned by :func:`getdefaulttimeout`
        is used.  If *source_address* is set it must be a tuple of (host, port)
        for the socket to bind as a source address before making the connection.
        An host of '' or port 0 tells the OS to use the default.
        """

        host, port = address
        err = None
        for res in getaddrinfo(host, port, 0, SOCK_STREAM):
            af, socktype, proto, canonname, sa = res
            sock = None
            try:
                sock = socket(af, socktype, proto)
                if timeout is not _GLOBAL_DEFAULT_TIMEOUT:
                    sock.settimeout(timeout)
                if source_address:
                    sock.bind(source_address)
>               sock.connect(sa)
E               ConnectionRefusedError: [Errno 111] Connection refused

/usr/lib/python3.4/socket.py:500: ConnectionRefusedError
=================================== FAILURES ===================================
_____________ ExampleTests.test_google_title_matches_correct_value _____________

self = <test_google.ExampleTests testMethod=test_google_title_matches_correct_value>

    def test_google_title_matches_correct_value(self):
>       self.driver.get("http://www.google.com")

test_google.py:11: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py:248: in get
    self.execute(Command.GET, {'url': url})
/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py:234: in execute
    response = self.command_executor.execute(driver_command, params)
/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/remote_connection.py:408: in execute
    return self._request(command_info[0], url, body=data)
/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/remote_connection.py:440: in _request
    resp = self._conn.getresponse()
/usr/lib/python3.4/http/client.py:1172: in getresponse
    response.begin()
/usr/lib/python3.4/http/client.py:351: in begin
    version, status, reason = self._read_status()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <http.client.HTTPResponse object at 0x7f80c80939e8>

    def _read_status(self):
        line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
        if len(line) > _MAXLINE:
            raise LineTooLong("status line")
        if self.debuglevel > 0:
            print("reply:", repr(line))
        if not line:
            # Presumably, the server closed the connection before
            # sending a valid response.
>           raise BadStatusLine(line)
E           http.client.BadStatusLine: ''

/usr/lib/python3.4/http/client.py:321: BadStatusLine
============================ pytest-warning summary ============================
WC1 None [pytest] section in setup.cfg files is deprecated, use [tool:pytest] instead.
============= 1 failed, 1 pytest-warnings, 1 error in 1.86 seconds =============

This is coming from an Ubuntu 16.04 machine, with Docker version:

$ docker version
Client:
 Version:      1.12.3
 API version:  1.24
 Go version:   go1.6.2
 Git commit:   6b644ec
 Built:        Mon, 19 Dec 2016 09:20:48 +1300
 OS/Arch:      linux/amd64

Server:
 Version:      1.12.3
 API version:  1.24
 Go version:   go1.6.2
 Git commit:   6b644ec
 Built:        Mon, 19 Dec 2016 09:20:48 +1300
 OS/Arch:      linux/amd64
mschwager commented 7 years ago

Nvm, I figured it out. It's because you're using Chrome driver 2.14 instead of 2.26 in the Python 3 version. I'll open a PR.