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

Stabilise sliding sync playwright test #28879

Merged
merged 3 commits into from
Jan 8, 2025
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
55 changes: 30 additions & 25 deletions playwright/e2e/sliding-sync/sliding-sync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,37 +371,42 @@ test.describe("Sliding Sync", () => {
roomIds.push(id);
await expect(page.getByRole("treeitem", { name: fruit })).toBeVisible();
}
const [roomAId, roomPId] = roomIds;
const [roomAId, roomPId, roomOId] = roomIds;

const assertUnsubExists = (request: Request, subRoomId: string, unsubRoomId: string) => {
const matchRoomSubRequest = (subRoomId: string) => (request: Request) => {
if (!request.url().includes("/sync")) return false;
const body = request.postDataJSON();
// There may be a request without a txn_id, ignore it, as there won't be any subscription changes
if (body.txn_id === undefined) {
return;
}
expect(body.unsubscribe_rooms).toEqual([unsubRoomId]);
expect(body.room_subscriptions).not.toHaveProperty(unsubRoomId);
expect(body.room_subscriptions).toHaveProperty(subRoomId);
return body.txn_id && body.room_subscriptions?.[subRoomId];
};
const matchRoomUnsubRequest = (unsubRoomId: string) => (request: Request) => {
if (!request.url().includes("/sync")) return false;
const body = request.postDataJSON();
return (
body.txn_id && body.unsubscribe_rooms?.includes(unsubRoomId) && !body.room_subscriptions?.[unsubRoomId]
);
};

let promise = page.waitForRequest(/sync/);

// Select the Test Room
await page.getByRole("treeitem", { name: "Apple", exact: true }).click();

// and wait for playwright to get the request
const roomSubscriptions = (await promise).postDataJSON().room_subscriptions;
// Select the Test Room and wait for playwright to get the request
const [request] = await Promise.all([
page.waitForRequest(matchRoomSubRequest(roomAId)),
page.getByRole("treeitem", { name: "Apple", exact: true }).click(),
]);
const roomSubscriptions = request.postDataJSON().room_subscriptions;
expect(roomSubscriptions, "room_subscriptions is object").toBeDefined();

// Switch to another room
promise = page.waitForRequest(/sync/);
await page.getByRole("treeitem", { name: "Pineapple", exact: true }).click();
assertUnsubExists(await promise, roomPId, roomAId);

// And switch to even another room
promise = page.waitForRequest(/sync/);
await page.getByRole("treeitem", { name: "Apple", exact: true }).click();
assertUnsubExists(await promise, roomPId, roomAId);
// Switch to another room and wait for playwright to get the request
await Promise.all([
page.waitForRequest(matchRoomSubRequest(roomPId)),
page.waitForRequest(matchRoomUnsubRequest(roomAId)),
page.getByRole("treeitem", { name: "Pineapple", exact: true }).click(),
]);

// And switch to even another room and wait for playwright to get the request
await Promise.all([
page.waitForRequest(matchRoomSubRequest(roomOId)),
page.waitForRequest(matchRoomUnsubRequest(roomPId)),
page.getByRole("treeitem", { name: "Orange", exact: true }).click(),
]);

// TODO: Add tests for encrypted rooms
});
Expand Down
1 change: 1 addition & 0 deletions playwright/element-web-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
window.localStorage.setItem(
"mx_local_settings",
JSON.stringify({
// Retain any other settings which may have already been set
...JSON.parse(window.localStorage.getItem("mx_local_settings") || "{}"),
// Ensure the language is set to a consistent value
language: "en",
Expand Down Expand Up @@ -310,7 +311,7 @@
})) as ElementHandle<Element>;

const screenshotName = sanitizeFilePathBeforeExtension(name);
await baseExpect(receiver).toHaveScreenshot(screenshotName, options);

Check failure on line 314 in playwright/element-web-test.ts

View workflow job for this annotation

GitHub Actions / Run Tests [Chrome] 5/6

[Chrome] › share-dialog/share-dialog.spec.ts:19:9 › Share dialog › should share a room @screenshot

1) [Chrome] › share-dialog/share-dialog.spec.ts:19:9 › Share dialog › should share a room @screenshot Error: expect.toHaveScreenshot(share-dialog-room.png): Target page, context or browser has been closed at ../element-web-test.ts:314 312 | 313 | const screenshotName = sanitizeFilePathBeforeExtension(name); > 314 | await baseExpect(receiver).toHaveScreenshot(screenshotName, options); | ^ 315 | 316 | await style.evaluate((tag) => tag.remove()); 317 | at Object.toMatchScreenshot (/home/runner/work/element-web/element-web/playwright/element-web-test.ts:314:9)

Check failure on line 314 in playwright/element-web-test.ts

View workflow job for this annotation

GitHub Actions / Run Tests [Chrome] 5/6

[Chrome] › share-dialog/share-dialog.spec.ts:32:9 › Share dialog › should share a room member @screenshot

2) [Chrome] › share-dialog/share-dialog.spec.ts:32:9 › Share dialog › should share a room member @screenshot Error: expect.toHaveScreenshot(share-dialog-user.png): Test ended. Call log: - expect.toHaveScreenshot(share-dialog-user.png) with timeout 5000ms - verifying given screenshot expectation - waiting for getByRole('dialog', { name: 'Share User' }) at ../element-web-test.ts:314 312 | 313 | const screenshotName = sanitizeFilePathBeforeExtension(name); > 314 | await baseExpect(receiver).toHaveScreenshot(screenshotName, options); | ^ 315 | 316 | await style.evaluate((tag) => tag.remove()); 317 | at Object.toMatchScreenshot (/home/runner/work/element-web/element-web/playwright/element-web-test.ts:314:9)

Check failure on line 314 in playwright/element-web-test.ts

View workflow job for this annotation

GitHub Actions / Run Tests [Chrome] 5/6

[Chrome] › share-dialog/share-dialog.spec.ts:49:9 › Share dialog › should share an event @screenshot

3) [Chrome] › share-dialog/share-dialog.spec.ts:49:9 › Share dialog › should share an event @screenshot Error: expect.toHaveScreenshot(share-dialog-event.png): Test ended. Call log: - expect.toHaveScreenshot(share-dialog-event.png) with timeout 5000ms - verifying given screenshot expectation - waiting for getByRole('dialog', { name: 'Share Room Message' }) - locator resolved to <div role="dialog" class="mx_ShareDialog" data-focus-lock-disabled="false" aria-describedby="mx_Dialog_content" aria-labelledby="mx_BaseDialog_title">…</div> - taking element screenshot - disabled all CSS animations - waiting for fonts to load... - fonts loaded - attempting scroll into view action - waiting for element to be stable at ../element-web-test.ts:314 312 | 313 | const screenshotName = sanitizeFilePathBeforeExtension(name); > 314 | await baseExpect(receiver).toHaveScreenshot(screenshotName, options); | ^ 315 | 316 | await style.evaluate((tag) => tag.remove()); 317 | at Object.toMatchScreenshot (/home/runner/work/element-web/element-web/playwright/element-web-test.ts:314:9)

await style.evaluate((tag) => tag.remove());

Expand Down
Loading