Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
73 changes: 73 additions & 0 deletions e2e/playwright/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,67 @@ docker/run.sh --update-snapshots # rewrite the etalons of the tests that ran
The etalons here are recorded anew, not copied from `e2e/testcafe-devextreme`: the two runners
crop and render differently, so a TestCafe image is not a valid reference for this suite.

It is still the check of the port. Recording writes whatever the test reached, and a verify run
compares against that same file, so neither notices a test that shot the wrong state. Before
deleting the TestCafe etalon, compare the new one with it: the same picture, within the per-pixel
threshold. Three differences are expected:

- A scrollbar. This suite shows it, TestCafe cut it off, so a viewport shot of a page that
overflows comes out up to 15 px larger, with the scrollbar in the extra strip.
- Anything under a TestCafe mask (`<name>_mask.png` next to the etalon, black where ignored).
- Single antialiased pixels on the edges of shapes that sit on fractional coordinates. The TestCafe
comparer ignored antialiasing (looks-same, `ignoreAntialiasing`, tolerance 5), so its etalon
could drift there unnoticed; this suite compares them strictly.

Anything else, a block of pixels or a moved edge, means the test reached a different state; find
out why rather than accept the image.

**Masks.** `testScreenshot` takes no mask, and the usual reason for one is gone:
`toHaveScreenshot` stops CSS animations (an infinite one at its first frame) and hides the caret.
Port a masked test without its mask, then run it strictly in the container a few times in a row
(`--repeat-each 10`). If it is stable, delete the mask with the TestCafe etalon. If it is not, make
the state deterministic (stop the animation, fix the data or the clock) rather than hide it.

Migrating a test means, in one PR: port the test, record its etalon here, and delete the TestCafe
test together with its etalon. The two sets must never cover the same case at once — a stale pair
left behind gets updated by whoever touches the component next and starts asserting a render
nobody checks.

### Record etalons on a Mac

The image is `linux/amd64`, the platform of the CI agent. On Apple Silicon it runs through Rosetta;
under QEMU emulation Chrome is several times slower. [Colima](https://github.com/abiosoft/colima)
gives the `docker` CLI a free runtime that uses Rosetta:

```bash
softwareupdate --install-rosetta --agree-to-license
brew install colima docker docker-buildx
colima start --vm-type vz --vz-rosetta --cpu 4 --memory 8
docker run --rm --platform linux/amd64 ubuntu:24.04 uname -m # prints x86_64
```

4 CPUs and 8 GB are enough for a component folder: `docker/run.sh` takes half the cores, so two
workers. Give the VM more for a larger run (`colima stop`, then `colima start --cpu 8 --memory 12`).
After a reboot, `colima start` brings it back with the same settings.

The container uses the host's `node_modules` and DevExtreme build, so build first and rebuild after
a source change. Then, from `e2e/playwright`, record and verify the etalons of the folder in both
themes the CI jobs run:

```bash
pnpm exec nx build devextreme-scss # from the repository root
pnpm exec nx build devextreme -c testing

docker/run.sh --update-snapshots tests/editors/selectBox/
THEME=fluent-next.blue.light docker/run.sh --update-snapshots tests/editors/selectBox/

docker/run.sh tests/editors/selectBox/
THEME=fluent-next.blue.light docker/run.sh tests/editors/selectBox/
```

The first run builds the image and takes a few minutes. Look through the new files before
committing them, as with etalons from CI.

### Etalons from CI

Without a container, CI records the etalons. A test whose etalon does not exist fails, and
Expand Down Expand Up @@ -183,6 +239,13 @@ viewport is 1200×800 and the widgets of the previous test are disposed.
Port a test one to one: the same steps, the same checks, the same screenshot names. A title changes
only when it repeats in the file, which Playwright rejects: add the loop parameters to it.

**`runInTheme`.** In TestCafe it was a filter, not a setting: the test ran only in the job whose
theme matched — usually one of the whole-suite theme jobs — and the folder jobs skipped it.
`test.use({ theme })` instead runs the test in that theme in every job that takes its folder, the
default and the `- fluent-next` one. That is the port: the result does not depend on the job, and a
screenshot keeps one etalon named after the pinned theme. Do not add a theme tag on top of it: the
test would run once more in the tagged job.

**Typing.** `fill` sets the value at once and sends no key events, so masked, numeric and date
editors do not react to it. Type with `pressSequentially`, and press keys under their Playwright
names: `Enter`, `Escape`, `ArrowLeft`, `Control+a`.
Expand All @@ -202,5 +265,15 @@ the observer runs.
that is not the target. TestCafe delivered a click to a covered element anyway, so a test that
relied on it needs the target made reachable, not the check switched off.

**Scrolling before a click.** TestCafe scrolled the whole target into view before a click;
Playwright scrolls only as far as the click point. When the target is wider or taller than the
window, the focus then scrolls the page after the click, and a drop-down closes on that scroll —
sometimes before the next step, sometimes after it. Scroll the target into view first, as TestCafe
did: `element.scrollIntoView({ block: 'nearest', inline: 'nearest' })` in `locator.evaluate`.

**Page errors.** A test fails on an uncaught error in the page, as it did in TestCafe. A test whose
TestCafe version ended with `expect(true).ok()` checks exactly that and needs no assertion.

**Old models.** A model in `packages/testcafe-models` that the ported tests used goes in the same
PR, but only after a search proves nothing else uses it: grep all of `e2e/` and `packages/` for its
import path, since other tests and other models import models too. A model still in use stays.
20 changes: 20 additions & 0 deletions e2e/playwright/helpers/domUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,26 @@ export const addFocusableElementBefore = async (
{ selector: targetSelector, id: elementId },
);

export const addFocusableElementAfter = async (
page: Page,
targetSelector: string,
elementId = 'focusable-end',
): Promise<string> => page.evaluate(
({ selector, id }) => {
document.getElementById(id)?.remove();

const target = document.querySelector(selector);
const button = document.createElement('button');

button.id = id;
button.textContent = 'End';
target?.parentElement?.insertBefore(button, target.nextElementSibling);

return button.id;
},
{ selector: targetSelector, id: elementId },
);

export const waitForNextFrame = async (page: Page): Promise<void> => page.evaluate(
() => new Promise<void>((resolve) => {
requestAnimationFrame(() => requestAnimationFrame(() => resolve()));
Expand Down
13 changes: 13 additions & 0 deletions e2e/playwright/models/dropDownButton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Locator } from '@playwright/test';
import type { WidgetName } from './types';
import DropDownList from './internal/dropDownList';

export default class DropDownButton extends DropDownList {
// eslint-disable-next-line class-methods-use-this
public getName(): WidgetName { return 'dxDropDownButton'; }

// The widget element itself names the popup content.
public getPopupOwner(): Locator {
return this.element;
}
}
34 changes: 34 additions & 0 deletions e2e/playwright/models/fileUploader/fileContent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { Locator, Page } from '@playwright/test';
import Button from '../button';

const CLASS = {
cancelButton: 'dx-fileuploader-cancel-button',
fileName: 'dx-fileuploader-file-name',
fileSize: 'dx-fileuploader-file-size',
statusMessage: 'dx-fileuploader-file-status-message',
};

export default class FileContent {
public static className = 'dx-fileuploader-file-container';

public readonly element: Locator;

public readonly cancelButton: Button;

public readonly fileName: Locator;

public readonly fileSize: Locator;

public readonly statusMessage: Locator;

public readonly validationMessage: Locator;

constructor(page: Page, element: Locator) {
this.element = element;
this.cancelButton = new Button(page, element.locator(`.${CLASS.cancelButton}`));
this.fileName = element.locator(`.${CLASS.fileName}`);
this.fileSize = element.locator(`.${CLASS.fileSize}`);
this.statusMessage = element.locator(`.${CLASS.statusMessage}`);
this.validationMessage = this.statusMessage.locator('> span');
}
}
31 changes: 31 additions & 0 deletions e2e/playwright/models/fileUploader/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { Locator, Page } from '@playwright/test';
import type { WidgetName } from '../types';
import Widget from '../internal/widget';
import FileContent from './fileContent';

const CLASS = {
input: 'dx-fileuploader-input',
filesContainer: 'dx-fileuploader-files-container',
};

export default class FileUploader extends Widget {
public static className = 'dx-fileuploader';

public readonly input: Locator;

public readonly files: Locator;

constructor(page: Page, selector: Locator | string) {
super(page, selector);

this.input = this.element.locator(`.${CLASS.input}`);
this.files = this.element.locator(`.${CLASS.filesContainer} .${FileContent.className}`);
}

// eslint-disable-next-line class-methods-use-this
public getName(): WidgetName { return 'dxFileUploader'; }

public getFile(index = 0): FileContent {
return new FileContent(this.page, this.files.nth(index));
}
}
48 changes: 48 additions & 0 deletions e2e/playwright/models/htmlEditor/aiDialog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type { Page } from '@playwright/test';
import Button from '../button';
import Popup from '../popup';
import TextArea from '../textArea';

const CLASS = {
wrapper: 'dx-aidialog',
bottomToolbar: 'dx-popup-bottom',
button: 'dx-button',
menuButton: 'dx-dropdownmenu-button',
textArea: 'dx-textarea',
};

export default class AIDialog extends Popup {
constructor(page: Page) {
super(page, `${Popup.className}.${CLASS.wrapper}`);
}

private getFooterButton(index: number): Button {
return new Button(
this.page,
this.element.locator(`.${CLASS.bottomToolbar} .${CLASS.button}`).nth(index),
);
}

public getGenerateButton(): Button {
return this.getFooterButton(0);
}

public getCancelButton(): Button {
return this.getFooterButton(0);
}

public getSplitButton(): Button {
return this.getFooterButton(3);
}

public getMenuButton(): Button {
return new Button(
this.page,
this.element.locator(`.${CLASS.bottomToolbar} .${CLASS.menuButton}`),
);
}

public getPromptTextArea(): TextArea {
return new TextArea(this.page, this.element.locator(`.${CLASS.textArea}`).first());
}
}
46 changes: 46 additions & 0 deletions e2e/playwright/models/htmlEditor/dialog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { Locator, Page } from '@playwright/test';
import Button from '../button';
import FileUploader from '../fileUploader';
import Popup from '../popup';
import TextBox from '../textBox';

const CLASS = {
wrapper: 'dx-formdialog',
tab: 'dx-tab',
bottomToolbar: 'dx-popup-bottom',
button: 'dx-button',
form: 'dx-formdialog-form',
textBox: 'dx-textbox',
buttonGroup: 'dx-buttongroup',
};

export default class Dialog extends Popup {
public readonly form: Locator;

public readonly addButton: Button;

public readonly cancelButton: Button;

public readonly fileUploader: FileUploader;

public readonly url: TextBox;

public readonly lockButton: Button;

constructor(page: Page) {
super(page, `${Popup.className}.${CLASS.wrapper}`);

const footerButtons = this.element.locator(`.${CLASS.bottomToolbar} .${CLASS.button}`);

this.form = this.element.locator(`.${CLASS.form}`);
this.addButton = new Button(page, footerButtons.nth(0));
this.cancelButton = new Button(page, footerButtons.nth(1));
this.fileUploader = new FileUploader(page, this.form.locator(`.${FileUploader.className}`));
this.url = new TextBox(page, this.form.locator(`.${CLASS.textBox}:has(input[name="src"])`));
this.lockButton = new Button(page, this.form.locator(`.${CLASS.buttonGroup} .${CLASS.button}`));
}

public getTab(index: number): Locator {
return this.element.locator(`.${CLASS.tab}`).nth(index);
}
}
49 changes: 49 additions & 0 deletions e2e/playwright/models/htmlEditor/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import type { Locator, Page } from '@playwright/test';
import { expect } from '@playwright/test';
import type { WidgetName } from '../types';
import Widget from '../internal/widget';
import Button from '../button';
import AIDialog from './aiDialog';
import Dialog from './dialog';

const CLASS = {
content: 'dx-htmleditor-content',
toolbar: 'dx-htmleditor-toolbar',
};

type ToolbarItemName = 'image' | 'color' | 'link' | 'ai' | 'bold';

export default class HtmlEditor extends Widget {
public readonly content: Locator;

public readonly dialog: Dialog;

public readonly aiDialog: AIDialog;

constructor(page: Page, selector: Locator | string) {
super(page, selector);

this.content = this.element.locator(`.${CLASS.content}`);
this.dialog = new Dialog(page);
this.aiDialog = new AIDialog(page);
}

// eslint-disable-next-line class-methods-use-this
public getName(): WidgetName { return 'dxHtmlEditor'; }

public async expectImageLoaded(src?: string): Promise<void> {
const image = this.content.locator('img');

if (src !== undefined) {
await expect(image).toHaveAttribute('src', src);
}

await expect.poll(() => image.evaluate(
(element: HTMLImageElement) => element.complete && element.naturalWidth > 0,
)).toBe(true);
}

public getToolbarItem(name: ToolbarItemName): Button {
return new Button(this.page, this.element.locator(`.${CLASS.toolbar} .dx-${name}-format`));
}
}
13 changes: 13 additions & 0 deletions e2e/playwright/models/internal/classMatcher.ts
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
import type { Locator } from '@playwright/test';
import { expect } from '@playwright/test';

export const classMatcher = (className: string): RegExp => new RegExp(`(^|\\s)${className}(\\s|$)`);

export const expectClass = async (
locator: Locator,
className: string,
present = true,
): Promise<void> => {
const assertion = expect(locator);

await (present ? assertion : assertion.not).toHaveClass(classMatcher(className));
};
Loading
Loading