Complete the code to start a Selenium WebDriver inside a Docker container.
from selenium import webdriver from selenium.webdriver.chrome.service import Service service = Service('[1]') driver = webdriver.Chrome(service=service) driver.get('https://example.com') driver.quit()
The correct path for ChromeDriver in the Docker container is /usr/bin/chromedriver. This allows Selenium to control Chrome inside the container.
Complete the Docker command to run a Selenium test with Chrome in headless mode.
docker run -d -p 4444:4444 --shm-size=2g selenium/standalone-chrome:latest [1]
--headless as a Docker option instead of a browser argument.--privileged unnecessarily.The --rm option removes the container after it stops, which is useful for test runs to keep the system clean.
Fix the error in the Selenium test code to connect to the remote WebDriver in Docker.
from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities options = webdriver.ChromeOptions() options.add_argument('--headless') driver = webdriver.Remote(command_executor='http://[1]:4444/wd/hub', desired_capabilities=DesiredCapabilities.CHROME, options=options) driver.get('https://example.com') driver.quit()
0.0.0.0 which is not a valid target address.dockerhost which is not a standard hostname.When running Selenium tests locally connecting to Docker, localhost is the correct hostname to reach the Selenium server inside the container.
Fill both blanks to create a Docker Compose service for Selenium Chrome with proper port and shared memory size.
""version: '3' services: selenium-chrome: image: selenium/standalone-chrome:latest ports: - '[1]:4444' shm_size: '[2]' """
The Selenium server listens on port 4444, so mapping host port 4444 to container port 4444 is standard. The shared memory size 2g helps Chrome run smoothly inside the container.
Fill all three blanks to write a Python dictionary comprehension that filters test results with status 'passed' and maps test names to durations.
test_durations = {test[1] test_results if test_results[test]['status'] [2] 'passed'}
result = {k: v[3] for k, v in test_durations.items()}The comprehension uses test_results[test] to access each test's data. It filters where status == 'passed'. Then it multiplies the duration by 1000 to convert seconds to milliseconds.