Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enabled 'parallel' mode for all Playwright test files
And added testing for `/blog/272`.
- Loading branch information
1 parent
2200482
commit b199949
Showing
20 changed files
with
129 additions
and
47 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import type { TestInfo } from '@playwright/test'; | ||
import { expect, test } from '@playwright/test'; | ||
import path from 'node:path'; | ||
|
||
test.describe.configure({ mode: 'parallel' }); | ||
|
||
// setupSnapshot is a helper that creates handles the necessary boilerplate | ||
// for snapshot testing. It returns a function that can be called after the | ||
// snapshot test has executed. | ||
// | ||
// See: | ||
// https://github.com/microsoft/playwright/issues/14527#issuecomment-1143352769 | ||
export function setupSnapshot(testInfo: TestInfo) { | ||
const snapshotDir = testInfo.snapshotDir; | ||
const snapshotSuffix = testInfo.snapshotSuffix; | ||
const projectName = testInfo.project.name; | ||
|
||
testInfo.snapshotDir = path.resolve(snapshotDir, '..', 'screenshots'); | ||
testInfo.snapshotSuffix = ''; | ||
testInfo.project.name = ''; | ||
|
||
return { | ||
data: { projectName }, | ||
cleanupSnapshot() { | ||
testInfo.snapshotDir = snapshotDir; | ||
testInfo.snapshotSuffix = snapshotSuffix; | ||
testInfo.project.name = projectName; | ||
}, | ||
}; | ||
} | ||
|
||
test('blog post h1 matches page title', async ({ page }) => { | ||
await page.goto('/blog/272'); | ||
expect(await page.title()).toContain(await page.textContent('h1')); | ||
}); | ||
|
||
test('blog post page matches screenshot', async ({ page }, testInfo) => { | ||
const { cleanupSnapshot, data } = setupSnapshot(testInfo); | ||
|
||
if (testInfo.project.use.viewport) { | ||
await page.setViewportSize(testInfo.project.use.viewport); | ||
} | ||
|
||
if (testInfo.project.use.colorScheme) { | ||
await page.emulateMedia({ | ||
colorScheme: testInfo.project.use.colorScheme, | ||
}); | ||
} | ||
|
||
await page.goto('/blog/272'); | ||
expect(await page.screenshot({ fullPage: true, scale: 'css' })).toMatchSnapshot({ | ||
name: `page-${data.projectName}.png`, | ||
threshold: 0.1, | ||
}); | ||
|
||
cleanupSnapshot(); | ||
}); |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,9 +1,10 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
test.describe.configure({ mode: 'parallel' }); | ||
|
||
test('index page has expected h1', async ({ page }) => { | ||
await page.goto('/'); | ||
|
||
const h1 = await page.locator('h1'); | ||
const textContext = await h1.textContent(); | ||
const textContext = await page.locator('h1').textContent(); | ||
expect(textContext).toContain('largest computer science community'); | ||
}); |
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