0
0
Selenium Pythontesting~10 mins

Docker containers for test execution in Selenium Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a Selenium WebDriver inside a Docker container.

Selenium Python
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()
Drag options to blanks, or click blank then click option'
A/usr/bin/chromedriver
B/usr/local/bin/geckodriver
C/bin/selenium
D/usr/bin/firefoxdriver
Attempts:
3 left
💡 Hint
Common Mistakes
Using the path for GeckoDriver instead of ChromeDriver.
Using a non-existent driver path inside the container.
2fill in blank
medium

Complete the Docker command to run a Selenium test with Chrome in headless mode.

Selenium Python
docker run -d -p 4444:4444 --shm-size=2g selenium/standalone-chrome:latest [1]
Drag options to blanks, or click blank then click option'
A--headless
B--privileged
C--detach
D--rm
Attempts:
3 left
💡 Hint
Common Mistakes
Using --headless as a Docker option instead of a browser argument.
Using --privileged unnecessarily.
3fill in blank
hard

Fix the error in the Selenium test code to connect to the remote WebDriver in Docker.

Selenium Python
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()
Drag options to blanks, or click blank then click option'
A127.0.0.1
Blocalhost
Cdockerhost
D0.0.0.0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0.0.0.0 which is not a valid target address.
Using dockerhost which is not a standard hostname.
4fill in blank
hard

Fill both blanks to create a Docker Compose service for Selenium Chrome with proper port and shared memory size.

Selenium Python
""version: '3'
services:
  selenium-chrome:
    image: selenium/standalone-chrome:latest
    ports:
      - '[1]:4444'
    shm_size: '[2]'
"""
Drag options to blanks, or click blank then click option'
A4444
B5555
C2g
D512m
Attempts:
3 left
💡 Hint
Common Mistakes
Mapping the wrong port number.
Setting shared memory size too small causing browser crashes.
5fill in blank
hard

Fill all three blanks to write a Python dictionary comprehension that filters test results with status 'passed' and maps test names to durations.

Selenium Python
test_durations = {test[1] test_results if test_results[test]['status'] [2] 'passed'}
result = {k: v[3] for k, v in test_durations.items()}
Drag options to blanks, or click blank then click option'
A['name']
B==
C* 1000
D[test]
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect dictionary keys.
Using assignment '=' instead of comparison '=='.
Forgetting to multiply duration to convert units.