Skip to content
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

feat: add Playwright package for screenshot testing #327

Merged
merged 46 commits into from
Nov 20, 2024

Conversation

Pavel-Tyan
Copy link
Contributor

No description provided.

package.json Outdated
@@ -51,7 +51,7 @@
"deps:install": "npm ci",
"deps:truncate": "npm prune --production",
"typecheck": "tsc -p . --noEmit",
"test": "exit 0",
"test": "npx playwright test",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the launch of the storybook should happen before the playwright tests

Copy link
Contributor Author

@Pavel-Tyan Pavel-Tyan Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i run "npm run test", playwright runs the storybook before tests.
I configured it in playwright.config.ts (webServer property):
437c10b#diff-f679bf1e58e8dddfc6cff0fa37c8e755c8d2cfc9e6b5dc5520a5800beba59a92R14

image

tests/utils.ts Outdated
@@ -0,0 +1,3 @@
export const URL_SEGMENT = 'http://localhost:6006/iframe.html?args=&id=';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe these are constants and not utilities

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is also necessary to make it so that the domain can be specified through an environment variable

package.json Outdated
@@ -51,7 +51,7 @@
"deps:install": "npm ci",
"deps:truncate": "npm prune --production",
"typecheck": "tsc -p . --noEmit",
"test": "exit 0",
"test": "npx playwright test",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is necessary to add a section about tests in the readme, how to run them and how to update them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added more info about testing in README: fb2595c

testDir: './tests',
fullyParallel: true,
forbidOnly: Boolean(process.env.CI),
retries: process.env.CI ? 2 : 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is process.env.CI needed?

README.md Outdated

`**.spec.ts` files contain test code.

`**.spec.ts-snapshots` folders contain screenshots which are used for comparison with test screenshots. If screenshot is incorrect you can delete it and after the tests playwright will replace it with test screenshot.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to update screenshot you need to run
npx playwright test --update-snapshots

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit: 10b491b

README.md Outdated

### Preparation

You need to add `.env` file in repository's root directory with the data below:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add .env

This should not be necessary by default, tests should be started by this variable. It should be written that by default such and such domain is used, but if you want to change it, you can fix it through the environment variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit: eb75627

package.json Outdated
@@ -73,8 +73,10 @@
"@gravity-ui/icons": "^2.5.0",
"@gravity-ui/page-constructor": "^5.22.0",
"@gravity-ui/uikit": "^6.2.0",
"@playwright/test": "^1.48.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dev dependency

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commits:
23a8be4
952eb85

package.json Outdated
"@popperjs/core": "^2.11.2",
"bem-cn-lite": "4.1.0",
"dotenv": "^16.4.5",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it probably should be a development dependency.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

folder name for tests __tests__

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit: b9a1629

Comment on lines 5 to 8
test.beforeEach(async ({page}) => {
await page.goto(DOC_PAGE_URL);
await page.waitForSelector(ROOT_ELEMENT_SELECTOR);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you have repetitive actions before each test, then it is worth taking them out into a separate function for test setup in utils.ts and reusing them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit: b9bd607

workflows: ['CI']
types:
- completed
branches: [test]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

master

Add webServer property in config. Before starting
the tests playwright will run and wait for the launch
of storybook dev server (if storybook is not running).

Server URL is stored in .env file.
Dotenv package needs for reading URL from .env.
Change "utils.ts" to "constants.ts".
Combined URL variables in "DOC_PAGE_URL" variable.

Change snapshot for DocPage test to correct image
(for Chrome).
If .env file with 'BASE_URL' variable
doesn't exist, playwright will use 'http://localhost:6006'
as base URL
Dotenv package was used in playwright config only
to get env variable (BASE_URL). Now config gets
variable from tests/constants.ts file.
Change playwright to dev dependency.
Remove dotenv
Rename files with snapshots to "__screenshots__"
@martyanovandrey martyanovandrey merged commit 61d9b97 into diplodoc-platform:master Nov 20, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants