testinfra: Update selenium calls

Now that all the bridge nodes are Jammy (3.10), we can uncap this
dependency which will bring in the latest selenium.  Unfortunately
after investigation the easier way to do things I hoped this would
allow doesn't work; comments are added and small updates for new API.

Update the users file-match so they run too.

Change-Id: I6a9d02bfc79b90417b1f5b3d9431f4305864869c
This commit is contained in:
Ian Wienand 2022-09-16 14:06:19 +10:00
parent 34dc0f2679
commit deed697853
No known key found for this signature in database
3 changed files with 31 additions and 7 deletions

View File

@ -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)
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(

View File

@ -39,7 +39,7 @@ commands = sphinx-build -W -E -b html doc/source doc/build/html
deps =
pytest-html # MPL-2.0
pytest-testinfra[ansible]>=6.0.0
selenium==3.141.0
selenium
requests
# This environment assumes a gate-hosts.yaml file has been written.

View File

@ -535,9 +535,11 @@
- playbooks/roles/install-docker/
- playbooks/roles/pip3/
- playbooks/roles/run-selenium/
- testinfra/util.py
- docker/hound/
- testinfra/test_codesearch.py
- job:
name: system-config-run-etherpad
parent: system-config-run-containers
@ -637,6 +639,7 @@
# to run this job as well.
- docker/haproxy-statsd/
- playbooks/roles/run-selenium/
- testinfra/util.py
- job:
name: system-config-run-grafana
@ -665,6 +668,7 @@
- playbooks/roles/install-docker/
- playbooks/roles/pip3/
- playbooks/roles/run-selenium/
- tesinfra/util.py
- testinfra/test_grafana.py
- job:
@ -783,6 +787,7 @@
- playbooks/roles/install-docker/
- playbooks/roles/pip3/
- playbooks/roles/run-selenium/
- testinfra/util.py
- playbooks/test-paste.yaml
- testinfra/test_paste.py
@ -964,6 +969,7 @@
- inventory/service/group_vars/review.yaml
- playbooks/roles/pip3/
- playbooks/roles/run-selenium/
- testinfra/util.py
- playbooks/roles/install-docker/
- playbooks/roles/letsencrypt
- playbooks/roles/gerrit/