-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade browser/accessibility tests for Puppeteer v18 #2532
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
de01f2b
Upgrade to `puppeteer@18` for axe updates
colinrotherham a0f6ed1
Use `@axe-core/puppeteer` to replace `axe-puppeteer` (deprecated)
colinrotherham 83e3ae7
Pin to `puppeteer@18` using Dependabot
colinrotherham 615ee15
Turn off axe iframe example reporting
colinrotherham 9c99f53
Add Puppeteer helpers from `govuk-frontend`
colinrotherham fb845c3
Update Puppeteer tests using `govuk-frontend` helpers
colinrotherham b5c6016
Run Puppeteer (Chromium) in ‘incognito’ context
colinrotherham ee37169
Remove Jest retry for flaky tests
colinrotherham ea4ec2b
Set up Jest config files etc
colinrotherham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,63 @@ | ||
|
||
const { setupPage } = require('../lib/jest-utilities.js') | ||
const configPaths = require('../lib/paths.js') | ||
const PORT = configPaths.testPort | ||
const { goTo, isVisible } = require('../lib/puppeteer-helpers.js') | ||
|
||
let page | ||
const baseUrl = 'http://localhost:' + PORT | ||
describe('Back to top', () => { | ||
let $module | ||
let $backToTopLink | ||
let pageHeight | ||
|
||
beforeAll(async () => { | ||
page = await setupPage() | ||
}) | ||
async function setup (page) { | ||
$module = await page.$('[data-module="app-back-to-top"]') | ||
$backToTopLink = await $module.$('a') | ||
|
||
afterAll(async () => { | ||
await page.close() | ||
}) | ||
// Scrollable height of body | ||
pageHeight = await page.$eval('body', ($element) => $element.scrollHeight) ?? 0 | ||
} | ||
|
||
const BACK_TO_TOP_LINK_SELECTOR = '[data-module="app-back-to-top"] a' | ||
function scrollTo (page, scrollY) { | ||
return page.evaluate((y) => window.scroll(0, y), scrollY) | ||
} | ||
|
||
beforeEach(async () => { | ||
await page.setJavaScriptEnabled(true) | ||
|
||
await goTo(page, '/styles/colour/') | ||
await scrollTo(page, 0) | ||
await setup(page) | ||
}) | ||
|
||
describe('Back to top', () => { | ||
it('is always visible when JavaScript is disabled', async () => { | ||
await page.setJavaScriptEnabled(false) | ||
await page.goto(`${baseUrl}/styles/colour/`, { waitUntil: 'load' }) | ||
const isBackToTopVisible = await page.waitForSelector(BACK_TO_TOP_LINK_SELECTOR, { visible: true }) | ||
expect(isBackToTopVisible).toBeTruthy() | ||
|
||
// Reload page again | ||
await page.reload() | ||
await setup(page) | ||
|
||
// Visible on page | ||
await expect(isVisible($backToTopLink)).resolves.toBe(true) | ||
}) | ||
|
||
it('is hidden when at the top of the page', async () => { | ||
await page.goto(`${baseUrl}/styles/colour/`, { waitUntil: 'load' }) | ||
const isBackToTopHidden = await page.waitForSelector(BACK_TO_TOP_LINK_SELECTOR, { visible: false }) | ||
expect(isBackToTopHidden).toBeTruthy() | ||
await scrollTo(page, 0) | ||
|
||
// Visible on page, hidden from viewport | ||
await expect(isVisible($backToTopLink)).resolves.toBe(true) | ||
await expect($backToTopLink.isIntersectingViewport()).resolves.toBe(false) | ||
}) | ||
|
||
it('is visible when at the bottom of the page', async () => { | ||
await page.goto(`${baseUrl}/styles/colour/`, { waitUntil: 'load' }) | ||
// Scroll to the bottom of the page | ||
await page.evaluate(() => window.scrollBy(0, document.body.scrollHeight)) | ||
const isBackToTopVisible = await page.waitForSelector(BACK_TO_TOP_LINK_SELECTOR, { visible: true }) | ||
expect(isBackToTopVisible).toBeTruthy() | ||
await scrollTo(page, pageHeight) | ||
|
||
// Visible on page, shown in viewport | ||
await expect(isVisible($backToTopLink)).resolves.toBe(true) | ||
await expect($backToTopLink.isIntersectingViewport()).resolves.toBe(true) | ||
}) | ||
|
||
it('goes back to the top of the page when interacted with', async () => { | ||
await page.goto(`${baseUrl}/styles/colour/`, { waitUntil: 'load' }) | ||
// Scroll to the bottom of the page | ||
await page.evaluate(() => window.scrollBy(0, document.body.scrollHeight)) | ||
// Make sure the back to top component is available to click | ||
await page.waitForSelector(BACK_TO_TOP_LINK_SELECTOR, { visible: true }) | ||
await page.click(BACK_TO_TOP_LINK_SELECTOR) | ||
const isAtTopOfPage = await page.evaluate(() => window.scrollY === 0) | ||
expect(isAtTopOfPage).toBeTruthy() | ||
await scrollTo(page, pageHeight) | ||
await $backToTopLink.click() | ||
|
||
// Scrolled to top | ||
await expect(page.evaluate(() => window.scrollY)).resolves.toBe(0) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allows the
jest-puppeteer
page and browser globals to work without lint errors