Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/packages/devextreme-scss/scss/widgets/** @DevExpress/devextreme-components
/apps/demos/Demos/** @DevExpress/devextreme-components
/e2e/testcafe-devextreme/tests/*/** @DevExpress/devextreme-components
/e2e/playwright/tests/editors/** @DevExpress/devextreme-components
/packages/devextreme/testing/tests/DevExpress.serverSide*/** @DevExpress/devextreme-components

## ui
Expand All @@ -19,6 +20,7 @@
/packages/devextreme/js/__internal/pagination/** @DevExpress/devextreme-components

/packages/testcafe-models/** @DevExpress/devextreme-components
/e2e/playwright/models/** @DevExpress/devextreme-components
/packages/devextreme/testing/tests/DevExpress.ui/** @DevExpress/devextreme-components
/packages/devextreme/testing/tests/DevExpress.ui.widgets*/** @DevExpress/devextreme-components
/packages/devextreme/testing/tests/DevExpress.knockout/** @DevExpress/devextreme-components
Expand Down
35 changes: 35 additions & 0 deletions e2e/playwright/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,38 @@ viewport is 1200×800 and the widgets of the previous test are disposed.
| `RequestMock` | `mockApi` on top of `page.route` |
| `mockdate` | `mockDate` on top of `page.clock` |
| machine timezone on the agent | `TIMEZONE` → the browser context |
| `t.typeText` | `locator.pressSequentially` |
| `t.pressKey('ctrl+a')` | `page.keyboard.press('Control+a')` |
| `t.expect(selector.value)` | `expect(locator).toHaveValue` |
| `t.expect(widget.option('x'))` | `expect.poll(() => widget.option('x'))` |
| `.before(...)` of a test | the first lines of the test |
| `meta({ browserSize })` | `test.use({ browserSize })` |
| `meta({ runInTheme })` | `test.use({ theme })` |
| `meta({ themes })` | `{ tag: ['@generic.light'] }` |

## Porting a TestCafe test

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.

**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`.

**Checks.** TestCafe retried `t.expect(selector.value)`; here only `expect(locator)` and
`expect.poll` retry. `expect(await locator.inputValue()).toBe(x)` reads the value once and fails
whenever the page is a moment late.

**Waiting.** A step waits for the state it needs, never for time. `helpers/`, `models/` and the
test folders migrated under this rule (see `eslint.config.mjs`) may not use `waitForTimeout`,
`setTimeout`, `force: true`, `toPass`, a `timeout` option or a call that raises a timeout
(`test.setTimeout`, `page.setDefaultTimeout`). When a widget reacts to a change
through an observer and leaves nothing to assert on, `waitForNextFrame` waits for the frame in which
the observer runs.

**Clicks.** A click is a real one: it lands on the topmost element at that point and fails when
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.

**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.
21 changes: 21 additions & 0 deletions e2e/playwright/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,25 @@ export default [
'@stylistic/no-extra-parens': 'off',
},
},
{
files: ['helpers/**/*.ts', 'models/**/*.ts', 'tests/editors/**/*.ts'],
rules: {
'no-restricted-syntax': ['error', {
selector: "CallExpression[callee.property.name='waitForTimeout'], CallExpression[callee.name='setTimeout'], CallExpression[callee.object.name=/^(window|globalThis)$/][callee.property.name='setTimeout']",
message: 'Wait for the state the next step needs, not for time.',
}, {
selector: "Property[key.name='force'][value.value=true]",
message: 'A forced action skips the checks a user action would pass. Make the target reachable.',
}, {
selector: "CallExpression[callee.property.name='toPass']",
message: 'Use a retrying assertion on the value itself (expect(locator), expect.poll).',
}, {
selector: "CallExpression[callee.object.name!=/^(window|globalThis)$/][callee.property.name=/^(setTimeout|setDefaultTimeout|setDefaultNavigationTimeout)$/], CallExpression[callee.object.name='test'][callee.property.name='slow']",
message: 'Do not raise a timeout. Find what the test is waiting for.',
}, {
selector: "Property[key.name='timeout']",
message: 'Do not raise a timeout. If this is a widget option, disable the rule on this line and say so.',
}],
},
},
];
37 changes: 37 additions & 0 deletions e2e/playwright/helpers/domUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,40 @@ export const removeStylesheetRulesFromPage = async (page: Page): Promise<void> =
(stylesheetId) => { document.getElementById(stylesheetId)?.remove(); },
STYLESHEET_RULES_ID,
);

export const addFocusableElementBefore = async (
page: Page,
targetSelector: string,
elementId = 'focusable-start',
): 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 = 'Start';
Object.assign(button.style, {
position: 'fixed',
top: '0',
left: '0',
width: '1px',
height: '1px',
padding: '0',
border: '0',
overflow: 'hidden',
opacity: '0',
});
target?.parentElement?.insertBefore(button, target);

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

export const waitForNextFrame = async (page: Page): Promise<void> => page.evaluate(
() => new Promise<void>((resolve) => {
requestAnimationFrame(() => requestAnimationFrame(() => resolve()));
}),
);
7 changes: 7 additions & 0 deletions e2e/playwright/models/autocomplete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { WidgetName } from './types';
import TextBox from './textBox';

export default class Autocomplete extends TextBox {
// eslint-disable-next-line class-methods-use-this
public getName(): WidgetName { return 'dxAutocomplete'; }
}
7 changes: 7 additions & 0 deletions e2e/playwright/models/colorBox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { WidgetName } from './types';
import TextBox from './textBox';

export default class ColorBox extends TextBox {
// eslint-disable-next-line class-methods-use-this
public getName(): WidgetName { return 'dxColorBox'; }
}
13 changes: 13 additions & 0 deletions e2e/playwright/models/form.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { WidgetName } from './types';
import Widget from './internal/widget';

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

public async validate(): Promise<void> {
await this.element.evaluate((element) => {
($(element) as any).dxForm('instance').validate();
});
}
}
26 changes: 26 additions & 0 deletions e2e/playwright/models/radioGroup/button.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { Locator } from '@playwright/test';
import { expect } from '@playwright/test';
import { classMatcher } from '../internal/classMatcher';

const CLASS = {
valueContainer: 'dx-radio-value-container',
icon: 'dx-radiobutton-icon',
checked: 'dx-radiobutton-checked',
};

export default class RadioButton {
public readonly element: Locator;

private readonly item: Locator;

constructor(item: Locator) {
this.item = item;
this.element = item.locator(`:scope > .${CLASS.valueContainer} > .${CLASS.icon}`);
}

public async expectChecked(present = true): Promise<void> {
const assertion = expect(this.item);

await (present ? assertion : assertion.not).toHaveClass(classMatcher(CLASS.checked));
}
}
26 changes: 26 additions & 0 deletions e2e/playwright/models/radioGroup/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { Locator, Page } from '@playwright/test';
import type { WidgetName } from '../types';
import Widget from '../internal/widget';
import RadioGroupItem from './item';

const CLASS = {
collection: 'dx-collection',
item: 'dx-item',
};

export default class RadioGroup extends Widget {
public readonly items: Locator;

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

this.items = this.element.locator(`:scope > .${CLASS.collection} > .${CLASS.item}`);
}

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

public getItem(index = 0): RadioGroupItem {
return new RadioGroupItem(this.items.nth(index));
}
}
20 changes: 20 additions & 0 deletions e2e/playwright/models/radioGroup/item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Locator } from '@playwright/test';
import RadioButton from './button';

const CLASS = {
itemContent: 'dx-item-content',
};

export default class RadioGroupItem {
public readonly element: Locator;

public readonly content: Locator;

public readonly radioButton: RadioButton;

constructor(element: Locator) {
this.element = element;
this.content = element.locator(`:scope > .${CLASS.itemContent}`);
this.radioButton = new RadioButton(element);
}
}
7 changes: 7 additions & 0 deletions e2e/playwright/models/textArea.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { WidgetName } from './types';
import TextBox from './textBox';

export default class TextArea extends TextBox {
// eslint-disable-next-line class-methods-use-this
public getName(): WidgetName { return 'dxTextArea'; }
}
29 changes: 29 additions & 0 deletions e2e/playwright/models/textBox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { Locator, Page } from '@playwright/test';
import type { WidgetName } from './types';
import Widget from './internal/widget';

const CLASS = {
input: 'dx-texteditor-input',
label: 'dx-label',
};

export default class TextBox extends Widget {
public readonly input: Locator;

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

this.input = this.element.locator(`.${CLASS.input}`);
}

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

public getLabel(): Locator {
return this.element.locator(`.${CLASS.label}`);
}

public getLabelSpan(): Locator {
return this.getLabel().locator('span');
}
}
22 changes: 22 additions & 0 deletions e2e/playwright/tests/editors/autocomplete/common.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { test } from '../../../fixtures';
import { createWidget } from '../../../helpers/createWidget';
import { appendElementTo, setStyleAttribute } from '../../../helpers/domUtils';
import { testScreenshot } from '../../../helpers/screenshots';
import Autocomplete from '../../../models/autocomplete';

test.describe('Autocomplete_placeholder', () => {
test('Placeholder is visible after items option change when value is not chosen (T1099804)', async ({ page }) => {
await appendElementTo(page, '#container', 'div', 'autocomplete');
await setStyleAttribute(page, '#container', 'box-sizing: border-box; width: 300px; height: 100px; padding: 8px;');
await createWidget(page, 'dxAutocomplete', {
width: '100%',
placeholder: 'Choose a value',
}, '#autocomplete');

const autocomplete = new Autocomplete(page, '#autocomplete');

await autocomplete.option('items', [1, 2, 3]);

await testScreenshot(page, 'Autocomplete placeholder if value is not choosen.png', { element: '#container' });
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading