I’ve started to use Selenium’s related products and how found that documentation is misleading, it doesn’t promote best practice.
Moreover, many components has memory/resource leaks that are not fixed for years.
So I’ve created utility project that encapsulated my “fixes” to Selenium and promotes best practice.
I will list some of the capabilities of my library:
- create/destroy BmpDaemon(aka browsermobproxy.Server).
- create/destroy BmpProxy (aka browsermobproxy.Client).
- create/destroy SeleniumWebDriver (for example selenium.webdriver.Chrome.webdriver). (Can be any supported browser).
- Taking screenshots.
- Preparing browser’s data-dir for usage.
- Enabling browser to download files.
- Capturing network in har format.
- Waiting for page to load.
- Synchronous click (on the button).
- Wait for Google Chrome to finish to download file (Chrome specific).
- Wait for display.
python -m pip install -U selenium-support
python -m pip install -U https://github.com/alex-ber/selenium-support/archive/master.zip
Optionally installing tests requirements.
python -m pip install -U https://github.com/alex-ber/selenium-support/archive/master.zip#egg=alex-ber-utils[tests]
Or explicitly:
wget https://github.com/alex-ber/selenium-support/archive/master.zip -O master.zip; unzip master.zip; rm master.zip
And then installing from source (see below).
python -m pip install -r req.txt # only installs "required" (relaxed)
python -m pip install . # only installs "required"
python -m pip install .[tests] # installs dependencies for tests
python -m pip install -r requirements.txt # only installs "required"
python -m pip install -r requirements-tests.txt # installs dependencies for tests
alexberkovich/selenium_support:latest
contains all selenium_support
dependencies.
This Dockerfile is very simple, you can take relevant part for you and put them into your Dockerfile.
Alternatively, you can use it as base Docker image for your project and add/upgrade another dependencies as you need.
For example:
FROM alexberkovich/selenium_support:latest
COPY requirements.txt etc/requirements.txt
RUN set -ex && \
#latest pip,setuptools,wheel
pip install --upgrade pip setuptools wheel && \
pip install selenium_support
pip install -r etc/requirements.txt
CMD ["/bin/sh"]
#CMD tail -f /dev/null
where requirements.txt
is requirements for your project.
From the directory with setup.py
python setup.py test #run all tests
or
pytest
See https://docs.python.org/3.1/distutils/uploading.html
python38 -m pip uninstall --yes selenium-support
python38 setup.py clean sdist bdist_wheel
python38 -m pip install --find-links=./dist selenium-support==0.1
python setup.py sdist upload
selenium-support requires the following modules.
- Python 3.8+
- selenium
- browsermob-proxy
- psutil