Skip to content

Commit bc4a6a6

Browse files
committed
PRO-15160 feat: add test options viewportHeight and viewportWidth
fix: action `resizeWindow`
1 parent 66ede52 commit bc4a6a6

4 files changed

Lines changed: 77 additions & 58 deletions

File tree

autotests/tests/e2edReportExample/browserData.ts

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,56 @@ import {
1010
waitForInterfaceStabilization,
1111
} from 'e2ed/actions';
1212

13-
test('correctly read data from browser', {meta: {testId: '14'}}, async () => {
14-
await navigateToPage(E2edReportExample);
15-
16-
await createClientFunction(() => {
17-
console.error('error');
18-
console.info('info');
19-
console.log('log');
20-
console.warn('warning');
21-
22-
setTimeout(() => {
23-
throw new Error('foo');
24-
}, 100);
25-
})();
26-
27-
const consoleMessages = getBrowserConsoleMessages();
28-
const columnNumber = 12;
29-
const url = '';
30-
31-
const consoleMessagesWithoutDate = consoleMessages.map(
32-
({dateTimeInIso: _, ...messageWithoutDate}) => messageWithoutDate,
33-
);
34-
35-
await expect(consoleMessagesWithoutDate, 'getBrowserConsoleMessages read all of messages').eql([
36-
{args: ['error'], location: {columnNumber, lineNumber: 3, url}, text: 'error', type: 'error'},
37-
{args: ['info'], location: {columnNumber, lineNumber: 4, url}, text: 'info', type: 'info'},
38-
{args: ['log'], location: {columnNumber, lineNumber: 5, url}, text: 'log', type: 'log'},
39-
{
40-
args: ['warning'],
41-
location: {columnNumber, lineNumber: 6, url},
42-
text: 'warning',
43-
type: 'warning',
44-
},
45-
]);
46-
47-
const jsErrors = getBrowserJsErrors();
48-
49-
await expect(
50-
jsErrors.length,
51-
'getBrowserJsErrors read zero JS errors when there are no errors',
52-
).eql(0);
53-
54-
await waitForInterfaceStabilization(100);
55-
56-
await expect(jsErrors.length, 'getBrowserJsErrors read all JS errors').eql(1);
57-
58-
await expect(String(jsErrors[0]?.error), 'getBrowserJsErrors read all JS errors').contains('foo');
59-
});
13+
test(
14+
'correctly read data from browser',
15+
{meta: {testId: '14'}, viewportHeight: 1200, viewportWidth: 1600},
16+
async () => {
17+
await navigateToPage(E2edReportExample);
18+
19+
await createClientFunction(() => {
20+
console.error('error');
21+
console.info('info');
22+
console.log('log');
23+
console.warn('warning');
24+
25+
setTimeout(() => {
26+
throw new Error('foo');
27+
}, 100);
28+
})();
29+
30+
const consoleMessages = getBrowserConsoleMessages();
31+
const columnNumber = 12;
32+
const url = '';
33+
34+
const consoleMessagesWithoutDate = consoleMessages.map(
35+
({dateTimeInIso: _, ...messageWithoutDate}) => messageWithoutDate,
36+
);
37+
38+
await expect(consoleMessagesWithoutDate, 'getBrowserConsoleMessages read all of messages').eql([
39+
{args: ['error'], location: {columnNumber, lineNumber: 3, url}, text: 'error', type: 'error'},
40+
{args: ['info'], location: {columnNumber, lineNumber: 4, url}, text: 'info', type: 'info'},
41+
{args: ['log'], location: {columnNumber, lineNumber: 5, url}, text: 'log', type: 'log'},
42+
{
43+
args: ['warning'],
44+
location: {columnNumber, lineNumber: 6, url},
45+
text: 'warning',
46+
type: 'warning',
47+
},
48+
]);
49+
50+
const jsErrors = getBrowserJsErrors();
51+
52+
await expect(
53+
jsErrors.length,
54+
'getBrowserJsErrors read zero JS errors when there are no errors',
55+
).eql(0);
56+
57+
await waitForInterfaceStabilization(100);
58+
59+
await expect(jsErrors.length, 'getBrowserJsErrors read all JS errors').eql(1);
60+
61+
await expect(String(jsErrors[0]?.error), 'getBrowserJsErrors read all JS errors').contains(
62+
'foo',
63+
);
64+
},
65+
);

src/actions/resizeWindow.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import {LogEventType} from '../constants/internal';
2+
import {getPlaywrightPage} from '../useContext';
23
import {log} from '../utils/log';
34

45
/**
56
* Set the browser window size.
67
*/
7-
export const resizeWindow = (width: number, height: number): Promise<void> => {
8+
export const resizeWindow = async (width: number, height: number): Promise<void> => {
89
log(
910
`Set the browser window size to width ${width} and height ${height}`,
1011
LogEventType.InternalAction,
1112
);
1213

13-
// TODO
14-
return Promise.resolve();
14+
const page = getPlaywrightPage();
15+
16+
await page.setViewportSize({height, width});
1517
};

src/test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,11 @@ export const test: TestFunction = (name, options, testFn) => {
3232
playwrightTest.use({bypassCSP: !options.enableCsp});
3333
}
3434

35+
if (options.viewportHeight !== undefined && options.viewportWidth !== undefined) {
36+
playwrightTest.use({
37+
viewport: {height: options.viewportHeight, width: options.viewportWidth},
38+
});
39+
}
40+
3541
playwrightTest(playwrightTestName, runTest);
3642
};

src/types/testRun.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,19 @@ export type TestFn = (testController: PlaywrightTestArgs) => Promise<void>;
6969
/**
7070
* Test options with userland metadata.
7171
*/
72-
export type TestOptions<TestMeta = TestMetaPlaceholder> = DeepReadonly<{
73-
enableCsp?: boolean;
74-
meta: TestMeta;
75-
takeFullPageScreenshotOnError?: boolean;
76-
takeViewportScreenshotOnError?: boolean;
77-
testIdleTimeout?: number;
78-
testTimeout?: number;
79-
}>;
72+
export type TestOptions<TestMeta = TestMetaPlaceholder> = DeepReadonly<
73+
{
74+
enableCsp?: boolean;
75+
meta: TestMeta;
76+
takeFullPageScreenshotOnError?: boolean;
77+
takeViewportScreenshotOnError?: boolean;
78+
testIdleTimeout?: number;
79+
testTimeout?: number;
80+
} & (
81+
| {viewportHeight: number; viewportWidth: number}
82+
| {viewportHeight?: undefined; viewportWidth?: undefined}
83+
)
84+
>;
8085

8186
/**
8287
* The complete static test options, that is, the options

0 commit comments

Comments
 (0)