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:
parent
34dc0f2679
commit
deed697853
@ -16,6 +16,7 @@ import socket
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
|
from selenium.webdriver.common.by import By
|
||||||
from selenium.webdriver.support.ui import WebDriverWait
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
from selenium.common.exceptions import TimeoutException
|
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) Javascript to execute before shot, None to skip
|
||||||
* (str) filename.png, will be placed in /var/log/screenshots for collection
|
* (str) filename.png, will be placed in /var/log/screenshots for collection
|
||||||
"""
|
"""
|
||||||
|
firefox_options = webdriver.FirefoxOptions()
|
||||||
|
|
||||||
driver = webdriver.Remote(
|
driver = webdriver.Remote(
|
||||||
command_executor='http://%s:4444/wd/hub' % (host.backend.get_hostname()),
|
command_executor='http://%s:4444/wd/hub' % (host.backend.get_hostname()),
|
||||||
desired_capabilities=webdriver.DesiredCapabilities.FIREFOX)
|
options=firefox_options)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for url, execute, png in shots:
|
for url, execute, png in shots:
|
||||||
@ -52,9 +55,24 @@ def take_screenshots(host, shots):
|
|||||||
# screenshot". You expand the viewport and take a
|
# screenshot". You expand the viewport and take a
|
||||||
# shot of the <body> element so that you don't also
|
# shot of the <body> element so that you don't also
|
||||||
# get scrollbars in the shot, with some tweaking
|
# get scrollbars in the shot, with some tweaking
|
||||||
# because the window size. Apparently selinum 4
|
# because of the window size.
|
||||||
# will have getFullPageScreeshotAs, so we should switch
|
#
|
||||||
# to that when available.
|
# 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()
|
original_size = driver.get_window_size()
|
||||||
required_width = driver.execute_script(
|
required_width = driver.execute_script(
|
||||||
'return document.body.parentNode.scrollWidth')
|
'return document.body.parentNode.scrollWidth')
|
||||||
@ -62,7 +80,7 @@ def take_screenshots(host, shots):
|
|||||||
'return document.body.parentNode.scrollHeight') + 100
|
'return document.body.parentNode.scrollHeight') + 100
|
||||||
driver.set_window_size(required_width, required_height)
|
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)
|
screenshot("/var/log/screenshots/%s" % png)
|
||||||
|
|
||||||
driver.set_window_size(
|
driver.set_window_size(
|
||||||
|
2
tox.ini
2
tox.ini
@ -39,7 +39,7 @@ commands = sphinx-build -W -E -b html doc/source doc/build/html
|
|||||||
deps =
|
deps =
|
||||||
pytest-html # MPL-2.0
|
pytest-html # MPL-2.0
|
||||||
pytest-testinfra[ansible]>=6.0.0
|
pytest-testinfra[ansible]>=6.0.0
|
||||||
selenium==3.141.0
|
selenium
|
||||||
requests
|
requests
|
||||||
|
|
||||||
# This environment assumes a gate-hosts.yaml file has been written.
|
# This environment assumes a gate-hosts.yaml file has been written.
|
||||||
|
@ -535,9 +535,11 @@
|
|||||||
- playbooks/roles/install-docker/
|
- playbooks/roles/install-docker/
|
||||||
- playbooks/roles/pip3/
|
- playbooks/roles/pip3/
|
||||||
- playbooks/roles/run-selenium/
|
- playbooks/roles/run-selenium/
|
||||||
|
- testinfra/util.py
|
||||||
- docker/hound/
|
- docker/hound/
|
||||||
- testinfra/test_codesearch.py
|
- testinfra/test_codesearch.py
|
||||||
|
|
||||||
|
|
||||||
- job:
|
- job:
|
||||||
name: system-config-run-etherpad
|
name: system-config-run-etherpad
|
||||||
parent: system-config-run-containers
|
parent: system-config-run-containers
|
||||||
@ -637,6 +639,7 @@
|
|||||||
# to run this job as well.
|
# to run this job as well.
|
||||||
- docker/haproxy-statsd/
|
- docker/haproxy-statsd/
|
||||||
- playbooks/roles/run-selenium/
|
- playbooks/roles/run-selenium/
|
||||||
|
- testinfra/util.py
|
||||||
|
|
||||||
- job:
|
- job:
|
||||||
name: system-config-run-grafana
|
name: system-config-run-grafana
|
||||||
@ -665,6 +668,7 @@
|
|||||||
- playbooks/roles/install-docker/
|
- playbooks/roles/install-docker/
|
||||||
- playbooks/roles/pip3/
|
- playbooks/roles/pip3/
|
||||||
- playbooks/roles/run-selenium/
|
- playbooks/roles/run-selenium/
|
||||||
|
- tesinfra/util.py
|
||||||
- testinfra/test_grafana.py
|
- testinfra/test_grafana.py
|
||||||
|
|
||||||
- job:
|
- job:
|
||||||
@ -783,6 +787,7 @@
|
|||||||
- playbooks/roles/install-docker/
|
- playbooks/roles/install-docker/
|
||||||
- playbooks/roles/pip3/
|
- playbooks/roles/pip3/
|
||||||
- playbooks/roles/run-selenium/
|
- playbooks/roles/run-selenium/
|
||||||
|
- testinfra/util.py
|
||||||
- playbooks/test-paste.yaml
|
- playbooks/test-paste.yaml
|
||||||
- testinfra/test_paste.py
|
- testinfra/test_paste.py
|
||||||
|
|
||||||
@ -964,6 +969,7 @@
|
|||||||
- inventory/service/group_vars/review.yaml
|
- inventory/service/group_vars/review.yaml
|
||||||
- playbooks/roles/pip3/
|
- playbooks/roles/pip3/
|
||||||
- playbooks/roles/run-selenium/
|
- playbooks/roles/run-selenium/
|
||||||
|
- testinfra/util.py
|
||||||
- playbooks/roles/install-docker/
|
- playbooks/roles/install-docker/
|
||||||
- playbooks/roles/letsencrypt
|
- playbooks/roles/letsencrypt
|
||||||
- playbooks/roles/gerrit/
|
- playbooks/roles/gerrit/
|
||||||
|
Loading…
Reference in New Issue
Block a user