@ -16,6 +16,7 @@ import socket
import time
from selenium import webdriver
from selenium . webdriver . common . by import By
from selenium . webdriver . support . ui import WebDriverWait
from selenium . common . exceptions import TimeoutException
@ -30,9 +31,11 @@ def take_screenshots(host, shots):
* ( str ) Javascript to execute before shot , None to skip
* ( str ) filename . png , will be placed in / var / log / screenshots for collection
"""
firefox_options = webdriver . FirefoxOptions ( )
driver = webdriver . Remote (
command_executor = ' http:// %s :4444/wd/hub ' % ( host . backend . get_hostname ( ) ) ,
desired_capabilities = webdriver . DesiredCapabilities . FIREFOX )
command_executor = ' http:// %s :4444/wd/hub ' % ( host . backend . get_hostname ( ) ) ,
options = firefox_options )
try :
for url , execute , png in shots :
@ -52,9 +55,24 @@ def take_screenshots(host, shots):
# screenshot". You expand the viewport and take a
# shot of the <body> element so that you don't also
# get scrollbars in the shot, with some tweaking
# because the window size. Apparently selinum 4
# will have getFullPageScreeshotAs, so we should switch
# to that when available.
# because of the window size.
#
# Update 2022-20-09 : The Firefox driver with Selenium 4
# has a very simple get_full_page_screenshot_as_png()
# which would be perfect -- but -- this only works when
# using the local Firefox connection, not the remote
# connection we are using here to talk to the docker
# container. I looked at switching this, but to talk to
# the local firefox you need geckodriver -- and that
# doesn't work with Ubuntu Jammy because Firefox is now
# distributed as a snap, not a regular package, and it
# doesn't work together [1] (apparently you can get around
# it, but it's just other hacks [2]). So we still have
# this ...
#
# [1] https://bugs.launchpad.net/ubuntu/+source/firefox/+bug/1968266
# [2] https://github.com/mozilla/geckodriver/releases/tag/v0.31.0
original_size = driver . get_window_size ( )
required_width = driver . execute_script (
' return document.body.parentNode.scrollWidth ' )
@ -62,7 +80,7 @@ def take_screenshots(host, shots):
' return document.body.parentNode.scrollHeight ' ) + 100
driver . set_window_size ( required_width , required_height )
driver . find_element _by_tag_name( ' body ' ) . \
driver . find_element ( By . TAG_NAME , ' body ' ) . \
screenshot ( " /var/log/screenshots/ %s " % png )
driver . set_window_size (