Bird
0
0

Which Dockerfile snippet correctly installs Google Chrome and ChromeDriver for running Selenium tests headlessly in a CI pipeline?

hard📝 Workflow Q8 of 15
Selenium Python - CI/CD Integration
Which Dockerfile snippet correctly installs Google Chrome and ChromeDriver for running Selenium tests headlessly in a CI pipeline?
AFROM python:3.9 RUN pip install selenium RUN apt-get install google-chrome-stable chromedriver
BFROM python:3.9-slim RUN apt-get update && apt-get install -y wget unzip \ && wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \ && dpkg -i google-chrome-stable_current_amd64.deb || apt-get -f install -y \ && wget -q https://chromedriver.storage.googleapis.com/114.0.5735.90/chromedriver_linux64.zip \ && unzip chromedriver_linux64.zip -d /usr/local/bin/ \ && chmod +x /usr/local/bin/chromedriver
CFROM ubuntu RUN apt-get update && apt-get install -y chromium-browser chromedriver
DFROM python:3.9 RUN apt-get update && apt-get install -y firefox geckodriver
Step-by-Step Solution
Solution:
  1. Step 1: Base image

    Use a lightweight Python image like python:3.9-slim.
  2. Step 2: Install dependencies

    Install wget and unzip to download Chrome and ChromeDriver.
  3. Step 3: Download and install Chrome

    Download the official Chrome .deb package and install it, fixing dependencies if needed.
  4. Step 4: Download and install ChromeDriver

    Download matching ChromeDriver version, unzip it to /usr/local/bin, and make it executable.
  5. Final Answer:

    FROM python:3.9-slim RUN apt-get update && apt-get install -y wget unzip \ && wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \ && dpkg -i google-chrome-stable_current_amd64.deb || apt-get -f install -y \ && wget -q https://chromedriver.storage.googleapis.com/114.0.5735.90/chromedriver_linux64.zip \ && unzip chromedriver_linux64.zip -d /usr/local/bin/ \ && chmod +x /usr/local/bin/chromedriver correctly installs Chrome and ChromeDriver for headless Selenium tests.
  6. Quick Check:

    Download official Chrome and matching chromedriver, install properly [OK]
Quick Trick: Download official Chrome and matching chromedriver [OK]
Common Mistakes:
  • Installing chromedriver via apt-get may not match Chrome version
  • Using Firefox and geckodriver instead of Chrome
  • Not fixing dependencies after dpkg install

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes