-
Notifications
You must be signed in to change notification settings - Fork 35
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
MWPW-135084 POC Visual Comparison Test #375
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## Scenario Test | ||
|
||
E2E tests that simulate an end user's journey and ensure that UI elements exist as expected. | ||
|
||
``` | ||
npx run test/e2e/frictionless -t "@smoke and @gnav" | ||
``` | ||
|
||
## Visual Test | ||
|
||
Scenario tests fall short of detecting layout and rendering issues. Visual tests fill the gaps. | ||
|
||
Visual tests leverage the existing user steps. and verify the screenshots of selected elements. | ||
|
||
``` | ||
npx run test/e2e/frictionless -t "@visual and @gnav" | ||
``` | ||
|
||
For example, a feature file `test/e2e/frictionless/features/visual/gnav.feature` | ||
|
||
``` | ||
Scenario: Navigate Gnav Menus | ||
Given I go to the compress-pdf page | ||
Then I screenshot the submenu of the 1st and 3rd menu items | ||
Then I should see the same screenshots as baseline | ||
``` | ||
|
||
The baseline screenshots are stored in the folder `test/e2e/frictionless/features/visual/gnav`. Each OS platform and browser has its own baseline. When the test is running, the current screenshots are stored in `reports/screenshot/visual/gnav`. The final step compares screenshots just taken with the baseline. The differences are stored under `reports` with the file name format `${platform}_${browser}_${image-name}.png` | ||
|
||
It can also compare the rendering of two different browers. For exmaple, the following command will run the test with the Webkit browser and compare to Firefox's baseline. | ||
|
||
``` | ||
npx run test/e2e/frictionless -t "@visual and @gnav" -b webkit --baseBrowser firefox | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Feature: Frictionless Gnav Visual Tests | ||
|
||
Background: | ||
Given I have a new browser context | ||
|
||
@MWPW-136087 @visual @gnav | ||
Scenario: Navigate Gnav Menus | ||
Given I go to the compress-pdf page | ||
When I resize the browser window to 1920x1080 | ||
And I screenshot the submenu of the 1st and 3rd menu items | ||
Then I should see the same screenshots as baseline | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -23,8 +23,10 @@ import { CompressPdfPage } from "../page-objects/compresspdf.page"; | |||||||||
import { FrictionlessPage } from "../page-objects/frictionless.page"; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||
import { cardinal } from "../support/cardinal"; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <import/extensions> reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||
import { expect } from "@playwright/test"; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <import/no-extraneous-dependencies> reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <import/newline-after-import> reported by reviewdog 🐶
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <import/order> reported by reviewdog 🐶 reviewdog suggestion errorGitHub comment range and suggestion line range must be same. L25-L25 v.s. L2-L25There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||
const os = require("os"); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||
const path = require("path"); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||
const fs = require("fs"); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <import/newline-after-import> reported by reviewdog 🐶
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||
import { getComparator } from 'playwright-core/lib/utils'; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <import/first> reported by reviewdog 🐶 reviewdog suggestion errorGitHub comment range and suggestion line range must be same. L29-L29 v.s. L1-L29There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <import/no-extraneous-dependencies> reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <import/order> reported by reviewdog 🐶 reviewdog suggestion errorGitHub comment range and suggestion line range must be same. L29-L29 v.s. L2-L29There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <import/extensions> reported by reviewdog 🐶 |
||||||||||
|
||||||||||
async function enableNetworkLogging(page) { | ||||||||||
if (global.config.profile.enableAnalytics) { | ||||||||||
|
@@ -253,20 +255,63 @@ Then(/^I dismiss the extension modal$/, async function () { | |||||||||
await this.page.closeExtensionModal.click(); | ||||||||||
}); | ||||||||||
|
||||||||||
Then(/^I should be able to open the submenu of the (.*) menu item(?:|s)$/, async function (items) { | ||||||||||
Then(/^I (screenshot|should be able to open) the submenu of the (.*) menu item(?:|s)$/, async function (action, items) { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||
this.context(FrictionlessPage); | ||||||||||
|
||||||||||
let menuItems = items.replace(/ and /g, ",").split(","); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||
menuItems = menuItems.map((x) => x.trim()).filter((x) => x.length > 0); | ||||||||||
for (let item of menuItems) { | ||||||||||
for (let item of menuItems) { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <prefer-const> reported by reviewdog 🐶
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <no-trailing-spaces> reported by reviewdog 🐶
Suggested change
|
||||||||||
const index = cardinal(item); | ||||||||||
await this.page.openSubMenu(index); | ||||||||||
await expect(this.page.fedsPopup).toBeVisible(); | ||||||||||
await this.page.fedsPopup.screenshot({path: `fedsPopup-${item}.png`}); | ||||||||||
if (action === 'screenshot') { | ||||||||||
const profile = global.config.profile; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <prefer-destructuring> reported by reviewdog 🐶
Suggested change
|
||||||||||
let outputDir = this.gherkinDocument.uri.split('/features/')[1].replace('.feature', ''); | ||||||||||
outputDir = `${profile.reportDir}/screenshots/${outputDir}/${os.platform()}/${profile.browser}`; | ||||||||||
await this.page.fedsPopup.screenshot({path: `${outputDir}/gnav-submenu-${item}.png`}); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <object-curly-spacing> reported by reviewdog 🐶
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <object-curly-spacing> reported by reviewdog 🐶
Suggested change
|
||||||||||
} | ||||||||||
await this.page.closeSubMenu(index); | ||||||||||
await expect(this.page.fedsPopup).not.toBeVisible(); | ||||||||||
} | ||||||||||
}); | ||||||||||
|
||||||||||
/*** | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <spaced-comment> reported by reviewdog 🐶
Suggested change
|
||||||||||
* This step is used to compare the current screenshots with the baseline | ||||||||||
* screenshots. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <no-trailing-spaces> reported by reviewdog 🐶
Suggested change
|
||||||||||
* | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <no-trailing-spaces> reported by reviewdog 🐶
Suggested change
|
||||||||||
* Baseline Folder: features/${feature-name}/${platform}/${browser} | ||||||||||
* Current Folder: ${report-dir}/screenshots/${feature-name}/${platform}/${browser} | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <no-trailing-spaces> reported by reviewdog 🐶
Suggested change
|
||||||||||
* Diff Image: ${report-dir}/${platform}_${browser}_${image-name}.png | ||||||||||
* | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <no-trailing-spaces> reported by reviewdog 🐶
Suggested change
|
||||||||||
* Command line options: | ||||||||||
* --baseBrowser: Use a different browser to compare with the current browser | ||||||||||
*/ | ||||||||||
Then(/^I should see the same screenshots as baseline$/, async function () { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||
const comparator = getComparator('image/png'); | ||||||||||
let baseDir = this.gherkinDocument.uri.replace('.feature', ''); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <prefer-const> reported by reviewdog 🐶
Suggested change
|
||||||||||
|
||||||||||
const profile = global.config.profile; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <prefer-destructuring> reported by reviewdog 🐶
Suggested change
|
||||||||||
let outputDir = this.gherkinDocument.uri.split('/features/')[1].replace('.feature', ''); | ||||||||||
outputDir = `${profile.reportDir}/screenshots/${outputDir}/${os.platform()}/${profile.browser}`; | ||||||||||
const images = fs.readdirSync(outputDir).filter(x => x.endsWith('.png')); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <arrow-parens> reported by reviewdog 🐶
Suggested change
|
||||||||||
|
||||||||||
const baseBrowser = profile.baseBrowser || profile.browser; | ||||||||||
|
||||||||||
const errors = []; | ||||||||||
for (let image of images) { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <prefer-const> reported by reviewdog 🐶
Suggested change
|
||||||||||
const baseImage = fs.readFileSync(`${baseDir}/${os.platform()}/${baseBrowser}/${image}`); | ||||||||||
const currImage = fs.readFileSync(`${outputDir}/${image}`); | ||||||||||
let diffImage = comparator(baseImage, currImage); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <prefer-const> reported by reviewdog 🐶
Suggested change
|
||||||||||
if (diffImage) { | ||||||||||
errors.push(image); | ||||||||||
fs.writeFileSync(`${profile.reportDir}/${os.platform()}_${profile.browser}_${image}`, diffImage.diff); | ||||||||||
} | ||||||||||
} | ||||||||||
if (errors.length > 0) { | ||||||||||
throw `Differences found: ${errors.join(', ')}`; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <no-throw-literal> reported by reviewdog 🐶 |
||||||||||
} | ||||||||||
}); | ||||||||||
|
||||||||||
Then(/^I should be able to use the "([^\"]*)" submenu$/, async function (menu) { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <no-useless-escape> reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||
this.context(FrictionlessPage); | ||||||||||
await this.page.openSubMenu(menu); | ||||||||||
|
@@ -296,14 +341,3 @@ Then(/^I switch to the new page after clicking "Buy now" button in the header$/, | |||||||||
this.page.native = newPage; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <no-trailing-spaces> reported by reviewdog 🐶
Suggested change
|
||||||||||
}); | ||||||||||
|
||||||||||
Then( | ||||||||||
/^I should not see the address bar contains "([^\"]*)"$/, | ||||||||||
async function (fragment) { | ||||||||||
const pattern = fragment.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'); | ||||||||||
await expect(this.page.native).not.toHaveURL(new RegExp(pattern), {timeout: 10000}); | ||||||||||
} | ||||||||||
); | ||||||||||
|
||||||||||
Then(/^I go back$/, async function () { | ||||||||||
await this.page.native.goBack(); | ||||||||||
}); |
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.
🚫 [eslint] <import/extensions> reported by reviewdog 🐶
Missing file extension "js" for "../page-objects/frictionless.page"