Skip to content

Commit

Permalink
Browser tests should use the latest Chrome stable release (#8783)
Browse files Browse the repository at this point in the history
* Browser tests should use the latest Chrome stable release

* Add dependencies for chrome binary and added to path

* Don't try to add chrome to path

* Added script to find chrome dependencies

* Correct var name and added missing &&

* Hard code location of chrome binary

* Remove unused import

* Removed -j from unzipping of chrome binary

* Giving credit to parts of the solution
  • Loading branch information
dwalleck authored Oct 9, 2023
1 parent 110b2db commit f85429b
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 16 deletions.
44 changes: 28 additions & 16 deletions Dockerfile.integration-tests-debian
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,43 @@ RUN \
gpg \
default-jre-headless \
jq \
apt-file \
libnss3 \
xvfb \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists && \
true

# Installing Google Chrome browser
RUN pip install --no-cache-dir selenium==4.9.0 requests

# Install the latest Google Chrome stable release
WORKDIR /opt/chrome
RUN \
curl -sS -o - https://dl.google.com/linux/linux_signing_key.pub | apt-key add && \
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list && \
apt-get -y update && \
apt-get -y install \
google-chrome-stable=117.0.5938.132-1 \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists && \
true
chrome_url=$(curl https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json | jq -r '.channels[] | select(.channel == "Stable") | .downloads.chrome[] | select(.platform == "linux64").url') && \
wget $chrome_url && \
unzip chrome-linux64.zip && \
rm -rf chrome-linux64.zip && \
chmod -R 0755 . && \
ln -s /opt/chrome/chrome-linux64/chrome /usr/bin/chrome

RUN pip install --no-cache-dir selenium==4.9.0 requests
# Install the dependencies for Google Chrome
RUN apt-file update
COPY docker/install_chrome_dependencies.py install_chrome_dependencies.py
RUN \
missing_chrome_deps=$(python install_chrome_dependencies.py) && \
apt-get -y install $missing_chrome_deps

# Install a suggested list of additional packages (https://stackoverflow.com/a/76734752)
RUN apt-get install -y libxi6 libgconf-2-4 jq libjq1 libonig5 libxkbcommon0 libxss1 libglib2.0-0 libnss3 \
libfontconfig1 libatk-bridge2.0-0 libatspi2.0-0 libgtk-3-0 libpango-1.0-0 libgdk-pixbuf2.0-0 libxcomposite1 \
libxcursor1 libxdamage1 libxtst6 libappindicator3-1 libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libxfixes3 \
libdbus-1-3 libexpat1 libgcc1 libnspr4 libgbm1 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxext6 \
libxrandr2 libxrender1 gconf-service ca-certificates fonts-liberation libappindicator1 lsb-release xdg-utils

# Installing Chromedriver
# Installing the latest stable Google Chrome driver release
WORKDIR /opt/chrome-driver
RUN \
chrome_version=$(apt-cache show google-chrome-stable | grep Version | awk '{print $2}' | cut -d '-' -f 1) && \
chrome_version_blob=$(curl -k https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json | jq ".versions[] | select(.version==\"$chrome_version\")") && \
chromedriver_url=https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/117.0.5938.92/linux64/chromedriver-linux64.zip && \
chromedriver_url=$(curl https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json | jq -r '.channels[] | select(.channel == "Stable") | .downloads.chromedriver[] | select(.platform == "linux64").url') && \
wget $chromedriver_url && \
unzip -j chromedriver-linux64.zip chromedriver-linux64/chromedriver && \
rm -rf chromedriver-linux64.zip && \
Expand Down
1 change: 1 addition & 0 deletions docker/entrypoint-integration-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ if [ $COUNTER -gt 10 ]; then
fi

export CHROMEDRIVER=$(find /opt/chrome-driver -name chromedriver)
export CHROME_PATH=/opt/chrome/chrome

# Run available unittests with a simple setup
# All available Integrationtest Scripts are activated below
Expand Down
60 changes: 60 additions & 0 deletions docker/install_chrome_dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""
This solution is largely based on the Playwright's browser dependencies script at
https://github.com/microsoft/playwright/blob/main/utils/linux-browser-dependencies/inside_docker/list_dependencies.js
"""

import subprocess


def find_packages(library_name):
stdout = run_command(["apt-file", "search", library_name])
if not stdout.strip():
return []
libs = [line.split(":")[0] for line in stdout.strip().split("\n")]
return list(set(libs))


def run_command(cmd, cwd=None, env=None):
result = subprocess.run(cmd, cwd=cwd, env=env, capture_output=True, text=True)
return result.stdout


def ldd(file_path):
stdout = run_command(["ldd", file_path])
# For simplicity, I'm assuming if we get an error, the code is non-zero.
try:
result = subprocess.run(
["ldd", file_path], capture_output=True, text=True
)
stdout = result.stdout
code = result.returncode
except subprocess.CalledProcessError:
stdout = ""
code = 1
return stdout, code


raw_deps = ldd("/opt/chrome/chrome")
dependencies = raw_deps[0].splitlines()

missing_deps = {
r[0].strip()
for d in dependencies
for r in [d.split("=>")]
if len(r) == 2 and r[1].strip() == "not found"
}

missing_packages = []
for d in missing_deps:
all_packages = find_packages(d)
packages = [
p
for p in all_packages
if not any(
p.endswith(suffix) for suffix in ["-dbg", "-test", "tests", "-dev", "-mesa"]
)
]
for p in packages:
missing_packages.append(p)

print(" ".join(missing_packages))

0 comments on commit f85429b

Please sign in to comment.