Skip to content

Commit

Permalink
Merge fa79364 into e0f2160
Browse files Browse the repository at this point in the history
  • Loading branch information
icemac committed Sep 14, 2023
2 parents e0f2160 + fa79364 commit 7d0330f
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 20 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- headless
# - head # disabled because it needs xvfb which is not so easy to set up on GHA

runs-on: ubuntu-20.04
runs-on: ubuntu-latest
name: ${{ matrix.config[1] }}-${{ matrix.browser }}-${{ matrix.state }}
steps:
- uses: actions/checkout@v2
Expand All @@ -36,7 +36,7 @@ jobs:
with:
python-version: ${{ matrix.config[0] }}
- name: Pip cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('setup.*', 'tox.ini') }}
Expand All @@ -45,7 +45,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install 'tox < 4' tox-factor
pip install tox
- name: Install dependencies (firefox)
if: matrix.browser == 'ff'
run: |
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ repos:
- id: rst
name: rst
entry: rst-lint --encoding utf-8
exclude: ./doc/*
exclude: ./doc/.*
# We have Sphinx directives in the docs. This cannot be validated
# here. We therefore include two rst-linter. They complement each
# other. This regex matches all *.rst not in the doc/ folder.
Expand Down
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ python_files = test[s|_]*.py
filterwarnings =
error
ignore::pytest.PytestUnraisableExceptionWarning
ignore:pkg_resources is deprecated as an API:DeprecationWarning
ignore:Deprecated call to `pkg_resources.declare_namespace.*:DeprecationWarning
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
install_requires = [
'gocept.httpserverlayer >= 3',
'httpagentparser',
'importlib-resources',
'plone.testing >= 7.0',
'selenium >= 4',
'Pillow',
Expand Down
6 changes: 3 additions & 3 deletions src/gocept/selenium/screenshot.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from PIL import Image
from PIL import ImageChops
import importlib_resources
import inspect
import itertools
import math
import os
import pkg_resources
import tempfile


Expand All @@ -13,7 +13,7 @@


def get_path(resource):
return pkg_resources.resource_filename('gocept.selenium', resource)
return importlib_resources.files('gocept.selenium') / resource


WHITE = (255, 255, 255, 0)
Expand Down Expand Up @@ -215,7 +215,7 @@ def _screenshot_path(screenshot_directory):
if screenshot_directory == '.':
screenshot_directory = \
inspect.currentframe().f_back.f_back.f_back.f_globals['__name__']
return pkg_resources.resource_filename(screenshot_directory, '')
return importlib_resources.files(screenshot_directory)


def save_screenshot_temporary(screenshot):
Expand Down
Binary file modified src/gocept/selenium/tests/fixture/screenshot-edge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 17 additions & 7 deletions src/gocept/selenium/tests/test_wd_selenese.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
from selenium.webdriver.common.by import By
from unittest import mock
import gocept.httpserverlayer.static
import gocept.selenium
import gocept.testing.assertion
import importlib_resources
import os.path
import pathlib
import pkg_resources
import pytest
import shutil
import stat
Expand Down Expand Up @@ -98,8 +98,7 @@ class HTMLTestCase(gocept.selenium.webdriver.WebdriverSeleneseTestCase,

def setUp(self):
super().setUp()
directory = pathlib.Path(pkg_resources.resource_filename(
'gocept.selenium.tests.fixture', ''))
directory = importlib_resources.files('gocept.selenium.tests.fixture')
for glob in ('*.html', '*.pdf'):
for name in directory.glob(glob):
shutil.copy(directory / name, self.layer['documentroot'])
Expand Down Expand Up @@ -293,18 +292,29 @@ def test_successful_comparison_chrome(self):
def test_successful_comparison_edge(self):
self.selenium.open('screenshot.html')
self.selenium.assertScreenshot(
'screenshot-edge', 'css=#block-1', threshold=14)
'screenshot-edge', 'css=#block-1', threshold=5)

def test_raises_exception_if_image_sizes_differ(self):
self.selenium.open('screenshot.html')
with self.assertRaises(ScreenshotSizeMismatchError):
self.selenium.assertScreenshot('screenshot', 'css=#block-2')

@pytest.mark.skipif(
os.environ.get('GOCEPT_WEBDRIVER_BROWSER').lower() == 'edge',
reason='Screenshots of Edge are currently broken.')
def test_does_not_fail_if_threshold_greater_than_distance(self):
self.selenium.open('screenshot_threshold.html')
self.selenium.assertScreenshot(
'screenshot_threshold', 'css=#block-2', threshold=12)

@pytest.mark.skipif(
os.environ.get('GOCEPT_WEBDRIVER_BROWSER').lower() != 'edge',
reason='Test the broken screenshots of Edge.')
def test_does_not_fail_if_threshold_greater_than_distance_edge(self):
self.selenium.open('screenshot_threshold.html')
self.selenium.assertScreenshot(
'screenshot_threshold_edge', 'css=#block-2', threshold=12)

def test_does_fail_if_threshold_less_than_distance(self):
self.selenium.open('screenshot_threshold.html')
with self.assertRaises(ScreenshotMismatchError):
Expand Down Expand Up @@ -373,7 +383,7 @@ class ScreenshotDirectorySettingTest(HTMLTestCase):

def test_default_setting_when_not_set(self):
# the default is the directory where the current test is
img = pkg_resources.resource_filename(self.__module__, 'foo.png')
img = str(importlib_resources.files(self.__module__) / 'foo.png')
self.selenium.capture_screenshot = True
self.selenium.open('screenshot.html')
with self.assertRaisesRegex(ValueError, img):
Expand All @@ -384,7 +394,7 @@ def test_default_setting_when_not_set(self):
def test_screenshot_directory_setting_resolves_dotted_name(self):
directory = 'gocept.selenium.tests.screenshot_directory'
self.selenium.screenshot_directory = directory
img = pkg_resources.resource_filename(directory, 'foo.png')
img = str(importlib_resources.files(directory) / 'foo.png')
self.selenium.capture_screenshot = True
self.selenium.open('screenshot.html')
with self.assertRaisesRegex(ValueError, img):
Expand Down
12 changes: 8 additions & 4 deletions src/gocept/selenium/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,11 @@ def get_firefox_webdriver_args(self):
"browser.helperApps.neverAsk.saveToDisk", "application/pdf")
options.set_preference("pdfjs.disabled", True)

return {'options': options,
'service': FirefoxService(GeckoDriverManager().install())}
return {
'options': options,
'service': FirefoxService(
GeckoDriverManager().install(),
log_output=open("geckodriver.log", "a+", encoding="utf-8"))}

def get_edge_webdriver_args(self):
options = selenium.webdriver.edge.options.Options()
Expand Down Expand Up @@ -147,8 +150,9 @@ def get_chrome_webdriver_args(self):

return {
'options': options,
'service_args': ['--log-path=chromedriver.log'],
'service': ChromeService(ChromeDriverManager().install()),
'service': ChromeService(
ChromeDriverManager().install(),
service_args=['--log-path=chromedriver.log']),
}

def _start_selenium(self):
Expand Down
7 changes: 5 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ envlist =
py{37,38,39}-{wsgi,plonetesting,grok}-{chrome,ff,edge}-headless
py38-wsgi-{chrome,ff,edge}-head
coverage-report
minversion = 3.7
minversion = 4.0

[testenv]
passenv = DISPLAY GOCEPT_*
passenv =
DISPLAY
GOCEPT_*
GH_TOKEN
usedevelop = true
setenv =
COVERAGE_FILE=.coverage.{envname}
Expand Down

0 comments on commit 7d0330f

Please sign in to comment.