Giter Site home page Giter Site logo

joyzoursky / docker-python-chromedriver Goto Github PK

View Code? Open in Web Editor NEW
633.0 20.0 195.0 37 KB

Dockerfile for running Python Selenium in headless Chrome (Python 2.7 / 3.6 / 3.7 / 3.8 / Alpine based Python / Chromedriver / Selenium / Xvfb included in different versions)

Home Page: https://hub.docker.com/r/joyzoursky/python-chromedriver/

License: MIT License

Python 8.01% Dockerfile 86.36% Shell 5.63%
python chromedriver selenium docker dockerfile xvfb headless-chrome

docker-python-chromedriver's Introduction

docker-python-chromedriver (Deprecated)

Python with Chromedriver, for running automated tests

Quick Try

$ git clone https://github.com/joyzoursky/docker-python-chromedriver.git
$ cd docker-python-chromedriver
$ docker run -it -w /usr/workspace -v $(pwd):/usr/workspace joyzoursky/python-chromedriver:latest bash
/usr/workspace# pip install selenium
/usr/workspace# python test_script.py

Warning: Current versions only support for building and running on amd64 (aka x86-64) machines, for arm64 (e.g. Apple M1 chip) machines, sevaral issues are found to be blocking (ref #31 #30).

Image includes

  • Python (Debian or Alpine based)
  • Google Chrome
  • Chromedriver
  • Selenium (in some versions)
  • Xvfb (in some versions)

Versions

Python 3 (Debian-based)

  • 3.9, latest (based on python:3.9, Dockerfile)
  • 3.9-selenium (based on python:3.9 with selenium installed, Dockerfile)
  • 3.8 (based on python:3.8, Dockerfile)
  • 3.8-selenium (based on python:3.8 with selenium installed, Dockerfile)
  • 3.7 (based on python:3.7, Dockerfile)
  • 3.7-selenium (based on python:3.7 with selenium installed, Dockerfile)
  • 3.6 (based on python:3.6, Dockerfile)
  • 3.6-selenium (based on python:3.6 with selenium installed, Dockerfile)

Python 3 (Alpine-based)

  • 3.9-alpine (based on python:3.9-alpine, Dockerfile)
  • 3.9-alpine-selenium (based on python:3.9-alpine with selenium installed, Dockerfile)
  • 3.8-alpine (based on python:3.8-alpine, Dockerfile)
  • 3.8-alpine-selenium (based on python:3.8-alpine with selenium installed, Dockerfile)
  • 3.7-alpine (based on python:3.7-alpine, Dockerfile)
  • 3.7-alpine-selenium (based on python:3.7-alpine3.8 with selenium installed, Dockerfile)
  • 3.6-alpine (based on python:3.6-alpine, Dockerfile)
  • 3.6-alpine-selenium (based on python:3.6-alpine with selenium installed, Dockerfile)

Python 2 (Deprecated)

  • 2.7 (based on python:2.7, Dockerfile)
  • 2.7-selenium (based on python:2.7 with selenium installed, Dockerfile)
  • 2.7-alpine3.7 (based on python:2.7-alpine3.7, Dockerfile)
  • 2.7-alpine3.7-selenium (based on python:2.7-alpine3.7 with selenium installed, Dockerfile)

Versions with Xvfb (Deprecated)

  • 3.6-xvfb (based on python:3.6 with xvfb installed, Dockerfile)
  • 3.6-xvfb-selenium (based on python:3.6 with xvfb and selenium installed, Dockerfile)
  • 2.7-xvfb (based on python:2.7 with xvfb installed, Dockerfile)
  • 2.7-xvfb-selenium (based on python:2.7 with xvfb and selenium installed, Dockerfile)

Usage

For the following Debian-based images:

  • latest
  • 3.9
  • 3.9-selenium
  • 3.8
  • 3.8-selenium
  • 3.7
  • 3.7-selenium
  • 3.6
  • 3.6-selenium
  • 3.6-xvfb
  • 3.6-xvfb-selenium
  • 2.7
  • 2.7-selenium
  • 2.7-xvfb
  • 2.7-xvfb-selenium

Run the followings in your terminal:

$ cd [your working directory]
$ docker run -it -w /usr/workspace -v $(pwd):/usr/workspace joyzoursky/python-chromedriver:[version] bash

For the following Alpine-based images:

  • 3.9-alpine
  • 3.9-alpine-selenium
  • 3.8-alpine
  • 3.8-alpine-selenium
  • 3.7-alpine
  • 3.7-alpine-selenium
  • 3.6-alpine
  • 3.6-alpine-selenium
  • 2.7-alpine
  • 2.7-alpine-selenium

Run the followings in your terminal:

$ cd [your working directory]
$ docker run -it -w /usr/workspace -v $(pwd):/usr/workspace joyzoursky/python-chromedriver:[version] sh

This will create a container from the image. Then you could starting running the commands in the container as in your working directory. The followings are some examples to run a selenium test.

Examples to run selenium test in the container

You can download a selenium test example from here to quick start.

For the following images with selenium pre-installed:

  • 3.9-alpine-selenium
  • 3.9-selenium
  • 3.8-alpine-selenium
  • 3.8-selenium
  • 3.7-alpine-selenium
  • 3.7-selenium
  • 3.6-alpine-selenium
  • 3.6-selenium
  • 2.7-alpine-selenium
  • 2.7-selenium

You may run:

# python test_script.py

For the following images that do not have selenium pre-installed:

  • latest
  • 3.9-alpine
  • 3.9
  • 3.8-alpine
  • 3.8
  • 3.7-alpine
  • 3.7
  • 3.6-alpine
  • 3.6
  • 2.7-alpine
  • 2.7

You may run:

# pip install selenium
# python test_script.py

For 3.6-xvfb or 2.7-xvfb, you may run:

# pip install selenium
# xvfb-run --server-args="-screen 0 1024x768x24" python test_script.py

For 3.6-xvfb-selenium or 2.7-xvfb-selenium, you may run:

# xvfb-run --server-args="-screen 0 1024x768x24" python test_script.py

Then you should see the test result like this:

test_case_1 (__main__.TestTemplate)
Find and click top-left logo button ... ok
test_case_2 (__main__.TestTemplate)
Find and click top-right Start your project button ... ok

----------------------------------------------------------------------
Ran 2 tests in 11.852s

OK

Contributing

To make changes upon the existing Dockerfiles, you are suggested to edit upon the Dockerfile.template files, and generate the new Dockerfiles for different versions by running render.sh.

How to edit and generate new versions of Dockerfiles

  1. cd to the folder that you want to edit, e.g. py-debian
  2. Make changes upon Dockerfile.template or Dockerfile-selenium.template
  3. Run bash render.sh from command-line

Note: The render.sh is written for Mac OS; If you are using Windows or other OS, some commands may need to be optimised before running.

Thanks a lot for helping on improving this project!

docker-python-chromedriver's People

Contributors

aallbrig avatar alexanderroidl avatar joaoemanuell avatar joyzoursky avatar minoic avatar oscarada87 avatar secord0 avatar sootysec avatar ukwksk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-python-chromedriver's Issues

apt update doesn't work on 3.6

If I do apt update on python-chromedriver:3.6, I get:

Err http://deb.debian.org jessie-updates/main amd64 Packages                                                                                                                                             
  404  Not Found
Fetched 10.1 MB in 6s (1644 kB/s)                                                                                                                                                                        
W: Failed to fetch http://deb.debian.org/debian/dists/jessie-updates/main/binary-amd64/Packages  404  Not Found

E: Some index files failed to download. They have been ignored, or old ones used instead.

I presume this is because Debian Jessie has lost some support due to being an old version.

If I build the image manually, it uses Debian Stretch and works fine, so presumably the underlying python:3.6 image has been upgraded to Stretch since the image on Docker Hub was built.

Any chance of you publishing a freshly-built image of python-chromedriver:3.6 on Docker Hub please?

Is there any way to run python script without `--headless` argument?

It seems that options.add_argument('--headless') is required.

options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-automation'])
options.add_argument('--no-sandbox')
# options.add_argument('--headless')
options.add_argument('--disable-gpu')
browser = webdriver.Chrome(options=options)
browser.get(url)
celery_1  | 
celery_1  | [2019-06-07 14:55:42,992: INFO/MainProcess] Received task: spider.get_config_from_url[f3479a81-e4a5-4c5b-b296-830d7f9d0864]  
celery_1  | [2019-06-07 14:55:45,174: ERROR/ForkPoolWorker-1] Task spider.get_config_from_url[f3479a81-e4a5-4c5b-b296-830d7f9d0864] raised unexpected: WebDriverException("unknown error: Chrome failed to start: ex
ited abnormally\n  (unknown error: DevToolsActivePort file doesn't exist)\n  (The process started from chrome location /usr/lib/chromium/chrome is no longer running, so ChromeDriver is assuming that Chrome has cr
ashed.)\n  (Driver info: chromedriver=2.38 (f91d32489882be7df38da3422a19713bfd113fa5),platform=Linux 4.14.91-bbrplus x86_64)", None, None)
celery_1  | Traceback (most recent call last):
celery_1  |   File "/usr/local/lib/python3.7/site-packages/celery/app/trace.py", line 385, in trace_task
celery_1  |     R = retval = fun(*args, **kwargs)
celery_1  |   File "/usr/local/lib/python3.7/site-packages/celery/app/trace.py", line 648, in __protected_call__
celery_1  |     return self.run(*args, **kwargs)
celery_1  |   File "/api/spider.py", line 32, in get_config_from_url
celery_1  |     browser = webdriver.Chrome(options=options)
celery_1  |   File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
celery_1  |     desired_capabilities=desired_capabilities)
celery_1  |   File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
celery_1  |     self.start_session(capabilities, browser_profile)
celery_1  |   File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
celery_1  |     response = self.execute(Command.NEW_SESSION, parameters)
celery_1  |   File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
celery_1  |     self.error_handler.check_response(response)
celery_1  |   File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
celery_1  |     raise exception_class(message, screen, stacktrace)
celery_1  | selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
celery_1  |   (unknown error: DevToolsActivePort file doesn't exist)
celery_1  |   (The process started from chrome location /usr/lib/chromium/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
celery_1  |   (Driver info: chromedriver=2.38 (f91d32489882be7df38da3422a19713bfd113fa5),platform=Linux 4.14.91-bbrplus x86_64)
celery_1  | 
celery_1  | [2019-06-07 14:56:52,964: INFO/MainProcess] Received task: spider.get_config_from_url[02c3befd-ed7e-41e3-8c0f-fbb48fdd0bf4]  
celery_1  | [2019-06-07 14:56:55,159: ERROR/ForkPoolWorker-1] Task spider.get_config_from_url[02c3befd-ed7e-41e3-8c0f-fbb48fdd0bf4] raised unexpected: WebDriverException("unknown error: Chrome failed to start: ex
ited abnormally\n  (unknown error: DevToolsActivePort file doesn't exist)\n  (The process started from chrome location /usr/lib/chromium/chrome is no longer running, so ChromeDriver is assuming that Chrome has cr
ashed.)\n  (Driver info: chromedriver=2.38 (f91d32489882be7df38da3422a19713bfd113fa5),platform=Linux 4.14.91-bbrplus x86_64)", None, None)
celery_1  | Traceback (most recent call last):

This is unusual, but I met it. When developing on my desktop system, I found a rule that when I used the headless parameter, it would be detected, so I could not get the real response.

Using Proxies

Hi Joy! Why do you think I can't connect using proxies?

def selenium_connect():
        PROXY = "66.97.38.58:80"
        url = "http://whatsmyip.org"
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument('--disable-dev-shm-usage')
        chrome_options.add_argument('--proxy-server=%s' % PROXY)
        driver = webdriver.Chrome(chrome_options=chrome_options)
        driver.get(url)

Been struggling with these and can't seem to find a way.

download folder path?

I'm using this container to download a file from a web site. but I cannot find the download folder anyway. Could you give me the download folder path or if it doesn't exist, how to create it? Thanks.

Improve Images

Right now the images don't use any kind of templating I could find cause otherwise I would have done a PR to fix all those issues:

  • apt cache is not getting deleted and apt-get update does not run in the same layer as apt-get install which is against dockers best practices and can lead to caching issues where you never install never packages
  • chromedriver.zip does not get deleted and shipped in the final image which unnecessarily increases image size
  • The script just installs any latest version of Chrome and is not reproducible
  • download mirrors are hard coded
  • older alpine versions are used instead of the latest
  • you run apk update which is not necessary and apk add should be run with --no-cache

Using macOS Docker desktop have some mistake

image
hello,my dear developer , i using my laptop always stop on here.
Warning: apt-key output should not be parsed (stdout is not a terminal)
But i using my linunx ubuntu server is ok.
I cant find what things happend.
Could you help me to sovles this quetion?Tanks

Chrome failed to start: crashed. (chrome not reachable)

I've tested both images 3.8-selenium and 3.9-selenium using the configurations in the test_script.py:

from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument("--window-size=1920,1080")
driver = webdriver.Chrome(options=chrome_options)

Both throw this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
    RemoteWebDriver.__init__(
  File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed.
  (chrome not reachable)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

Random failures when using pytest -N x

Hello,
When I am running my tests in parallel mode, using pytest -N 2 (or more), often I get such exception:

============================= test session starts =============================
platform linux -- Python 3.6.4, pytest-3.8.0, py-1.6.0, pluggy-0.7.1
rootdir: /home/docker/code, inifile:
plugins: xdist-1.23.0, forked-0.2
gw0 I / gw1 I
gw0 [6] / gw1 [6]

scheduling tests via LoadScheduling
F..... [100%]
=================================== FAILURES ===================================
____________________________ GoogleTest.test_search ____________________________
[gw0] linux -- Python 3.6.4 /usr/local/bin/python

self = <test.test_smoke.GoogleTest testMethod=test_search>

def setUp(self):
  super(GoogleTest, self).setUp()

test/test_smoke.py:8:


test/base_test.py:10: in setUp
self.driver = webdriver.Chrome(chrome_options=options)
/usr/local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py:75: in init
desired_capabilities=desired_capabilities)
/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py:156: in init
self.start_session(capabilities, browser_profile)
/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py:251: in start_session
response = self.execute(Command.NEW_SESSION, parameters)
/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py:318: in execute
response = self.command_executor.execute(driver_command, params)
/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py:375: in execute
return self._request(command_info[0], url, body=data)
/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py:397: in _request
resp = self._conn.request(method, url, body=body, headers=headers)
/usr/local/lib/python3.6/site-packages/urllib3/request.py:72: in request
**urlopen_kw)
/usr/local/lib/python3.6/site-packages/urllib3/request.py:150: in request_encode_body
return self.urlopen(method, url, **extra_kw)
/usr/local/lib/python3.6/site-packages/urllib3/poolmanager.py:322: in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py:638: in urlopen
_stacktrace=sys.exc_info()[2])
/usr/local/lib/python3.6/site-packages/urllib3/util/retry.py:367: in increment
raise six.reraise(type(error), error, _stacktrace)
/usr/local/lib/python3.6/site-packages/urllib3/packages/six.py:685: in reraise
raise value.with_traceback(tb)
/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py:600: in urlopen
chunked=chunked)
/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py:384: in _make_request
six.raise_from(e, None)
:2: in raise_from
???
/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py:380: in _make_request
httplib_response = conn.getresponse()
/usr/local/lib/python3.6/http/client.py:1331: in getresponse
response.begin()
/usr/local/lib/python3.6/http/client.py:297: in begin
version, status, reason = self._read_status()
/usr/local/lib/python3.6/http/client.py:258: in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")


self = <socket.SocketIO object at 0x7fd0c99cd8d0>
b = <memory at 0x7fd0c995f048>

def readinto(self, b):
    """Read up to len(b) bytes into the writable buffer *b* and return
        the number of bytes read.  If the socket is non-blocking and no bytes
        are available, None is returned.

        If *b* is non-empty, a 0 return value indicates that the connection
        was shutdown at the other end.
        """
    self._checkClosed()
    self._checkReadable()
    if self._timeout_occurred:
        raise OSError("cannot read from timed out object")
    while True:
        try:
          return self._sock.recv_into(b)

E urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

/usr/local/lib/python3.6/socket.py:586: ProtocolError
===================== 1 failed, 5 passed in 24.40 seconds ======================

Image: 3.6-xvfb-selenium
pytest==3.8.0
pytest-forked==0.2
pytest-xdist==1.23.0

README typo

Python 3 (Alpine-based)
3.9-alpine and 3.9-alpine-selenium Dockerfile link mismatch.

Python 3.9 not supported

I'd like to update my repo to work with the last version of Python. Is it a plan to add an image with Python3.9?

Unable to locate package google-chrome-stable

Trying to run 3.9-selenium

Have used different versions of python including slim-bullseye and regular bullseye as well

 => ERROR [ 6/11] RUN apt-get install -y google-chrome-stable                                                                                                          0.5s
------
 > [ 6/11] RUN apt-get install -y google-chrome-stable:
#9 0.152 Reading package lists...
#9 0.404 Building dependency tree...
#9 0.471 Reading state information...
#9 0.518 E: Unable to locate package google-chrome-stable
------
executor failed running [/bin/sh -c apt-get install -y google-chrome-stable]: exit code: 100

`test_script.py` tests are broken on fresh install

Just installed to use this repo as a guide for a workshop I'll be running in a few weeks, and looks like while this installs selenium just fine, it fails to run your tests correctly:

root@b91ef629f6c9:/usr/workspace# python test_script.py
test_case_1 (__main__.TestTemplate)
Find and click top-right button ... test_script.py:18: DeprecationWarning: use options instead of chrome_options
  self.driver = webdriver.Chrome(chrome_options=chrome_options)
FAIL
test_case_2 (__main__.TestTemplate)
Find and click Learn more button ... test_script.py:18: DeprecationWarning: use options instead of chrome_options
  self.driver = webdriver.Chrome(chrome_options=chrome_options)
FAIL

======================================================================
FAIL: test_case_1 (__main__.TestTemplate)
Find and click top-right button
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_script.py", line 29, in test_case_1
    el = self.driver.find_element_by_class_name('btn-header')
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".btn-header"}
  (Session info: headless chrome=79.0.3945.79)


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_script.py", line 32, in test_case_1
    self.fail(ex.msg)
AssertionError: no such element: Unable to locate element: {"method":"css selector","selector":".btn-header"}
  (Session info: headless chrome=79.0.3945.79)

======================================================================
FAIL: test_case_2 (__main__.TestTemplate)
Find and click Learn more button
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_script.py", line 38, in test_case_2
    el = self.driver.find_element_by_xpath(".//*[@id='tag-line-wrap']/span/a")
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":".//*[@id='tag-line-wrap']/span/a"}
  (Session info: headless chrome=79.0.3945.79)


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_script.py", line 41, in test_case_2
    self.fail(ex.msg)
AssertionError: no such element: Unable to locate element: {"method":"xpath","selector":".//*[@id='tag-line-wrap']/span/a"}
  (Session info: headless chrome=79.0.3945.79)

----------------------------------------------------------------------
Ran 2 tests in 25.545s

FAILED (failures=2)

Not working on python-chromedriver:3.6-selenium

Hi,
I'm trying your code but it's not working on this version:
joyzoursky/python-chromedriver:3.6-selenium

>>> from selenium import webdriver
>>> driver = webdriver.Chrome()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 311, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
  (Driver info: chromedriver=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.9.60-linuxkit-aufs x86_64

Unable to run the python selenium docker

Hello,
I am very new to docker concept. I am using Windows 10. I have created the docker build successfully using the dockerfile that you have mentioned for Python 3.8 ( https://github.com/joyzoursky/docker-python-chromedriver/blob/master/py3/py3.8/Dockerfile) My docker image name is selenium_test_python:latest Now when I try to run the docker to run the python script test_script.py using the following command as below,then I am getting this as C:\Users\SAYOMGHOSH>docker run -it selenium_test_python:latest
Python 3.8.3 (default, May 14 2020, 22:42:38)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

I am also sending you the folder structure which can help you to debug the situation. Can you
Docker_Python.zip

noob question about xvfb

thanks for this repo.

sorry I'm new to automated selenium - but I'm curious about what the value of xvfb is?

are you able to indicate what it's inclusion gives?

Error: 'chromedriver' executable needs to be in PATH.

I have implemented your dockfile into my project which uses webdriver chrome to run the python test script (using mac OS) . However when tried, it errors out as follows:

image

Docker file:

Use an official Python runtime as a parent image

FROM python:3.7
ENV APP_DIR /app
WORKDIR $APP_DIR

ENV PYTHONPATH="$PYTHONPATH:/app"

COPY uits uits
COPY requirements.txt requirements.txt
COPY setup.py setup.py

install google chrome

RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
RUN apt-get -y update
RUN apt-get install -y google-chrome-stable

install chromedriver

RUN apt-get install -yqq unzip
RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/

set display port to avoid crash

ENV DISPLAY=:99

install selenium

RUN pip install selenium

upgrade pip

RUN pip install --upgrade pip

#install required additional dependencies
RUN pip install -r requirements.txt

Test script look like this:

class SeleniumClient(object):
"""
A wrapper for selenium's client with various handy extensions.
"""
def init(self, params=None, config="default", driver=None):
if driver is not None:
self.driver = driver
return

    if params['location'] != "local":
        return

    root = os.path.dirname(os.path.realpath(__file__))
    self.logger.info("%s" , _platform)
    if _platform == "darwin":
        user = getpass.getuser()
        download_folder = "/Users/%s/downloads/" % user
    elif "win32" in _platform:
        user = getpass.getuser()
        download_folder = "/Users/%s/downloads/" % user
    elif "linux" in _platform:
        download_folder = "/var/lib/docker"
    else:
        raise NotImplemented("don't know where to save data")
    if "chrome" in config:
        options = webdriver.ChromeOptions()
        preferences = {
            "profile.default_content_settings.popups": 0,
            "download.default_directory": download_folder,
            "credentials_enable_service": 0,
            "profile.password_manager_enabled": 0
        }
        options.add_experimental_option("prefs", preferences)
        if config == "chrome":
            options.add_argument("--start-fullscreen")
        elif config == "chrome_headless":
            options.add_argument('--headless')
            options.add_argument('--disable-gpu')
            options.add_argument("--window-size=1920, 1200")
        self.driver = webdriver.Chrome(executable_path='usr/bin/local',options=options)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.