Skip to content

Docker debian container with python, selenium webdriver (headless chrome and gecko), pytest

Notifications You must be signed in to change notification settings

rafalf/docker-debian-selenium-headless

Repository files navigation

update drivers (current: geckodriver-v0.19.0 , chrome-2.33)

geckodriver releases
chromedriver releases

Cleaning local docker repository

docker ps -a | egrep "[Ee]xited" | awk '{print $1}' | xargs -Izz55 docker rm zz55
docker images | sed -E "s/[[:space:]]+/ /g" | awk '{print $3}' | xargs -Izz55 docker rmi zz55
docker volume ls | sed -E "s/[[:space:]]+/ /g" | awk '{print $2}' | xargs -Izz55 docker volume rm zz55

Build

docker build -t debian-headless .

Running an interactive shell

docker run -it debian-headless /bin/bash

Chrome tests:

  1. xfvb
chrome_test_xfvb.py
from selenium import webdriver  
from selenium.webdriver.common.keys import Keys  
from selenium.webdriver.chrome.options import Options  
import xvfbwrapper

# Start headless display
display = xvfbwrapper.Xvfb()
display.start()
print('display started')

chrome_options = Options()  
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument("--disable-gpu")
driver = webdriver.Chrome(chrome_options=chrome_options)  
driver.get("http://www.google.com")
print(driver.title)
driver.quit()
display.stop()
print('display stopped')
  1. --headless
chrome_test.py
from selenium import webdriver  
from selenium.webdriver.common.keys import Keys  
from selenium.webdriver.chrome.options import Options  

chrome_options = Options()  
chrome_options.add_argument("--headless") 
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument("--disable-gpu")
driver = webdriver.Chrome(chrome_options=chrome_options)  
driver.get("http://www.google.com")
print(driver.title)
driver.quit()

Resources:

debian library
python-headless-chromedriver fail out of the box
firefox-headless
docker ignore error

About

Docker debian container with python, selenium webdriver (headless chrome and gecko), pytest

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages