-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(playwright): file loading, snapshots, and browsers (oh my!)
feat: added basic visual regression testing feat: added choice of browser: chromium, firefox, webkit feat: added options: - host: the base url host - port: the base url port - screenshotDir: the directory for sceenshots - nojsTags: tags to start the browser without js - showBrowserTags: tags to show a browser for that test - slowMoTags: tags to run that test with slowMo enabled - slowMoMs: number of milliseconds to run slowMo feat: added world.baseUrl getter fix: remove timeouts for all step defintions (use slowmo instead) fix: fixed expression for outcome step "I should see {string} element with {string}" feat: added outcome step "the user agent should contain/be {string}" feat: added outcome step "the screenshot should match" feat: added outcome step "the screenshot {string} should match" fix: make the action steps for navigation respect the config feat: added action step "I load the file {string}" fix: fixed the screenshot steps test: added test html files for faster loading test: removed old tests dependent on internet test: tests for concurrent testing in different browsers test: tests for showing brorwser and slowmo test: tests for visual regression testing
- Loading branch information
Showing
16 changed files
with
742 additions
and
81 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
"@quickpickle/playwright": patch | ||
--- | ||
|
||
feat(playwright): file loading, snapshots, and browsers (oh my!) | ||
|
||
feat: added basic visual regression testing | ||
feat: added choice of browser: chromium, firefox, webkit | ||
feat: added options: - host: the base url host - port: the base url port - screenshotDir: the directory for sceenshots - nojsTags: tags to start the browser without js - showBrowserTags: tags to show a browser for that test - slowMoTags: tags to run that test with slowMo enabled - slowMoMs: number of milliseconds to run slowMo | ||
feat: added world.baseUrl getter | ||
fix: remove timeouts for all step defintions (use slowmo instead) | ||
fix: fixed expression for outcome step "I should see {string} element with {string}" | ||
feat: added outcome step "the user agent should contain/be {string}" | ||
feat: added outcome step "the screenshot should match" | ||
feat: added outcome step "the screenshot {string} should match" | ||
fix: make the action steps for navigation respect the config | ||
feat: added action step "I load the file {string}" | ||
fix: fixed the screenshot steps | ||
|
||
test: added test html files for faster loading | ||
test: removed old tests dependent on internet | ||
test: tests for concurrent testing in different browsers | ||
test: tests for showing brorwser and slowmo | ||
test: tests for visual regression testing |
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 |
---|---|---|
|
@@ -49,6 +49,9 @@ export default { | |
'vite', | ||
'node:path', | ||
'node:url', | ||
'node:fs', | ||
'lodash-es', | ||
'pngjs', | ||
'pixelmatch', | ||
] | ||
}; |
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.
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,55 +1,45 @@ | ||
import { Then } from "quickpickle"; | ||
import type { PlaywrightWorld } from "./PlaywrightWorld"; | ||
import { expect } from '@playwright/test' | ||
import './snapshotMatcher' | ||
|
||
Then('I should see {string}', async function (world:PlaywrightWorld, text) { | ||
await world.page.waitForTimeout(50) | ||
await expect(world.page.getByText(text)).toBeVisible() | ||
}) | ||
Then('I should not see {string}', async function (world:PlaywrightWorld, text) { | ||
await world.page.waitForTimeout(50) | ||
await expect(world.page.getByText(text)).not.toBeVisible() | ||
}) | ||
|
||
Then('I should see a(n)/the {string} {word}', async function (world:PlaywrightWorld, identifier, role) { | ||
await world.page.waitForTimeout(50) | ||
if (role === 'element') await expect(world.page.locator(identifier)).toBeVisible() | ||
else await expect(world.page.getByRole(role, { name: identifier })).toBeVisible() | ||
}) | ||
Then('I should not see a(n)/the {string} {word}', async function (world:PlaywrightWorld, identifier, role) { | ||
await world.page.waitForTimeout(50) | ||
if (role === 'element') await expect(world.page.locator(identifier)).not.toBeVisible() | ||
else await expect(world.page.getByRole(role, { name: identifier })).not.toBeVisible() | ||
}) | ||
|
||
Then('I should see a(n)/the {string} with the text {string}', async function (world:PlaywrightWorld, identifier, text) { | ||
await world.page.waitForTimeout(50) | ||
Then('I should see a(n)/the {string} (element )with (the )(text ){string}', async function (world:PlaywrightWorld, identifier, text) { | ||
await expect(world.page.locator(identifier).filter({ hasText: text })).toBeVisible() | ||
}) | ||
Then('I should not see a(n)/the {string} with the text {string}', async function (world:PlaywrightWorld, identifier, text) { | ||
await world.page.waitForTimeout(50) | ||
Then('I should not see a(n)/the {string} (element )with (the )(text ){string}', async function (world:PlaywrightWorld, identifier, text) { | ||
await expect(world.page.locator(identifier).filter({ hasText: text })).not.toBeVisible() | ||
}) | ||
|
||
|
||
|
||
Then('the (value of ){string} (value )should contain/include/be/equal {string}', async function (world:PlaywrightWorld, identifier, val) { | ||
let exact = world.info.step?.match(/should not (?:be|equal) ["']/) ? true : false | ||
await world.page.waitForTimeout(50) | ||
let value = await (await world.page.locator(identifier)).inputValue() | ||
if (exact) await expect(value).toEqual(val) | ||
else await expect(value).toContain(val) | ||
}) | ||
Then('the (value of ){string} (value )should not contain/include/be/equal {string}', async function (world:PlaywrightWorld, identifier, val) { | ||
let exact = world.info.step?.match(/should not (?:be|equal) ["']/) ? true : false | ||
await world.page.waitForTimeout(50) | ||
let value = await (await world.page.locator(identifier)).inputValue() | ||
if (exact) await expect(value).not.toEqual(val) | ||
else await expect(value).not.toContain(val) | ||
}) | ||
|
||
Then(/^the metatag for "([^"]+)" should (be|equal|contain) "(.*)"$/, async function (world:PlaywrightWorld, name, eq, value) { | ||
await world.page.waitForTimeout(50) | ||
let val:string|null | ||
|
||
if (name === 'title') val = await world.page.title() | ||
|
@@ -61,13 +51,22 @@ Then(/^the metatag for "([^"]+)" should (be|equal|contain) "(.*)"$/, async funct | |
}) | ||
|
||
Then('the active element should be {string}', async function (world:PlaywrightWorld, identifier) { | ||
await world.page.waitForTimeout(50) | ||
let locator = await world.page.locator(identifier) | ||
await expect(locator).toBeFocused() | ||
}) | ||
|
||
Then('the active element should be the {string} {word}', async function (world:PlaywrightWorld, identifier, role) { | ||
await world.page.waitForTimeout(50) | ||
let locator = await world.page.getByRole(role, { name: identifier }) | ||
await expect(locator).toBeFocused() | ||
}) | ||
|
||
Then('the user agent should contain/be {string}', async function (world:PlaywrightWorld, ua) { | ||
await expect(world.browser.browserType().name()).toContain(ua) | ||
}) | ||
|
||
Then('(the )screenshot should match', async function (world:PlaywrightWorld) { | ||
await expect(world.page).toMatchScreenshot(`${world.playwrightConfig.screenshotDir}/${world.info.rule ? world.info.rule + '__' + world.info.scenario : world.info.scenario}__${world.info.line}.png`) | ||
}) | ||
Then('(the )screenshot {string} should match', async function (world:PlaywrightWorld, name:string) { | ||
await expect(world.page).toMatchScreenshot(`${world.playwrightConfig.screenshotDir}/${name}.png`) | ||
Check failure on line 71 in packages/playwright/src/outcomes.steps.ts
|
||
}) |
Oops, something went wrong.