Install Chrome for Testing assets.
Project description
c4t: Chrome for Testing - v1.4.0
Install Chrome for Testing assets. A flavor of Chrome, specifically for testing and a matching chromedriver. The version of assets installed are from the stable channel and currently only for linux64 platforms.
Why Chrome for Testing?
Taken from the Chrome Developers Blog
...setting up an adequate browser testing environment is notoriously difficult...
You want consistent, reproducible results across repeated test runs—but this may not happen if the browser executable or binary decides to update itself in between two runs.
You want to pin a specific browser version and check that version number into your source code repository, so that you can check out old commits and branches and re-run the tests against the browser binary from that point in time.
Not only do you have to download a Chrome binary somehow, you also need a correspondingly-versioned ChromeDriver binary to ensure the two binaries are compatible.
Chrome for Testing is a dedicated flavor of Chrome targeting the testing use case, without auto-update, integrated into the Chrome release process, made available for every Chrome release
...finding a matching Chrome and ChromeDriver binary can be completely eliminated by integrating the ChromeDriver release process into the Chrome for Testing infrastructure.
Installation
From PyPI
(venv) $ pip install c4t
(venv) $
From GitHub
(venv) $ pip install git+https://github.com/p4irin/c4t.git
(venv) $
Verify
In a REPL
Show version
(venv) $ python
Python 3.8.10 (default, Jun 2 2021, 10:49:15)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import c4t
>>> c4t.__version__
'<major>.<minor>.<patch>'
>>>
Or on the command line
Show version
(venv) $ c4t --version
v1.1.0
(venv) $
Display package documentation
(venv) $ python -m pydoc c4t
(venv) $
Usage
In code
Install the default, the latest stable version and use it with Selenium
Python 3.8.10 (default, May 26 2023, 14:05:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import c4t
>>> assets = c4t.Assets()
>>> assets.install()
Create directory ${HOME}/.c4t-assets/124.0.6367.91
Downloading chrome-linux64.zip.
100% [......................................................................] 146689409 / 146689409
Downloading chromedriver-linux64.zip.
100% [..........................................................................] 7508443 / 7508443
Unzipping chrome-linux64.zip
Unzipping chromedriver-linux64.zip
Creating symlink to chrome version 117.0.5938.62
Creating symlink to chromedriver version 117.0.5938.62
Finished installing version 117.0.5938.62 of Chrome for Testing and Chromedriver.
-------------------------------------------
Version 117.0.5938.62 is the active version
-------------------------------------------
>>> from selenium.webdriver import ChromeOptions, ChromeService, Chrome
>>> options = ChromeOptions()
>>> options.binary_location = c4t.location.chrome
>>> service = ChromeService(executable_path=c4t.location.chromedriver)
>>> browser = Chrome(options=options, service=service)
>>> browser.get('https://pypi.org/user/p4irin/')
>>> browser.close()
>>> browser.quit()
>>>
On the command line
Display command line help
(venv) $ c4t --help
(venv) $ c4t install --help
Install the default, the latest stable version
# By default assets are installed in ${HOME}/.c4t-assets
# To use a different path, set the C4T_PATH_TO_ASSETS environment variable.
# e.g.: export C4T_PATH_TO_ASSETS=<path>
# Add this export to your .bashrc so the path is set for every bash session.
(venv) $ c4t install
Install a specific version
(venv) $ c4t install --version 116.0.5794.0
Show the currently active version
(venv) $ c4t --active
Active version of 'Chrome for Testing' assets installed: 124.0.6367.91
Show installation path of assets
(venv) $ c4t path
Path to assets: /home/p4irin/.c4t-assets
Show a list of installed versions
(venv) $ c4t list
1 - 124.0.6367.91
2 - 116.0.5794.0
Switch active version
(venv) $ c4t switch
1 - 124.0.6367.91
2 - 116.0.5794.0
Select a version by number: 2
Creating symlink to chrome version 116.0.5794.0
Creating symlink to chromedriver version 116.0.5794.0
Active version is now: 116.0.5794.0
Common workflow
- Install one or more versions of Chrome for testing assets
- Set/switch the active version
- Run your Selenium Webdriver tests with the active version of Chrome for testing
This allows for quickly switching back to a previous version of Chrome to run your tests against in case of a regression on a recent/latest version. For example, a test failing against the latest of Chrome, did it pass consistently on the previous version or is it flaky and in need for a more robust implementation?
Reference
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.