Skip to content

Commit

Permalink
Organized images in the screenshots workflow.
Browse files Browse the repository at this point in the history
Added a top-level directory in the zip archive that is the commit
hash which makes it easier when downloading multiple artifacts
for comparison. Updated the filenames of screenshots for easier
comparison between different cases. Added that an error is
raised if no screenshots uploaded in workflow.
  • Loading branch information
ngnpope authored and sarahboyce committed May 10, 2024
1 parent 02c2090 commit 962215d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/screenshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ jobs:
- name: Optimize screenshots
run: oxipng --interlace=0 --opt=4 --strip=safe tests/screenshots/*.png

- name: Organize screenshots
run: |
mkdir --parents "/tmp/screenshots/${{ github.event.pull_request.head.sha }}"
mv tests/screenshots/* "/tmp/screenshots/${{ github.event.pull_request.head.sha }}/"
- name: Upload screenshots
uses: actions/upload-artifact@v4
with:
name: screenshots-${{ github.event.pull_request.head.sha }}
path: tests/screenshots/
path: /tmp/screenshots/
if-no-files-found: error
6 changes: 5 additions & 1 deletion django/test/selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def test(self, *args, _func=func, _case=screenshot_case, **kwargs):

test.__name__ = f"{name}_{screenshot_case}"
test.__qualname__ = f"{test.__qualname__}_{screenshot_case}"
test._screenshot_name = name
test._screenshot_case = screenshot_case
setattr(cls, test.__name__, test)

@classproperty
Expand Down Expand Up @@ -214,7 +216,9 @@ def high_contrast(self):
def take_screenshot(self, name):
if not self.screenshots:
return
path = Path.cwd() / "screenshots" / f"{self._testMethodName}-{name}.png"
test = getattr(self, self._testMethodName)
filename = f"{test._screenshot_name}--{name}--{test._screenshot_case}.png"
path = Path.cwd() / "screenshots" / filename
path.parent.mkdir(exist_ok=True, parents=True)
self.selenium.save_screenshot(path)

Expand Down

0 comments on commit 962215d

Please sign in to comment.