E2E/Playwright: Instantiate page in pw (#29765)

* instantiate page in pw

* update spec

* fix storage key and require user when logging in via API

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Saturnino Abril
2025-01-14 12:30:42 +08:00
коммит произвёл GitHub
родитель 20e9c6aa3e
Коммит 90e3d2833e
35 изменённых файлов: 554 добавлений и 591 удалений

Просмотреть файл

@@ -1,5 +1,6 @@
import {Page} from '@playwright/test';
import {expect, test} from '@e2e-support/test_fixture';
import {duration} from '@e2e-support/util';
// Helper function to intercept API request and modify the response
async function interceptConfigWithLandingPage(page: Page, enabled: boolean) {
@@ -16,9 +17,7 @@ async function interceptConfigWithLandingPage(page: Page, enabled: boolean) {
});
}
test('MM-T5640_1 should not see landing page ', async ({pw, pages, page}) => {
const {adminClient} = await pw.getAdminClient();
const adminConfig = await adminClient.getConfig();
test('MM-T5640_1 should not see landing page ', async ({pw, page}) => {
await interceptConfigWithLandingPage(page, false);
// Navigate to your starting URL
@@ -31,25 +30,19 @@ test('MM-T5640_1 should not see landing page ', async ({pw, pages, page}) => {
expect(page.url()).toContain('/login');
// Verify the login page is visible
const loginPage = new pages.LoginPage(page, adminConfig);
await loginPage.toBeVisible();
await pw.loginPage.toBeVisible();
});
test('MM-T5640_2 should see landing page', async ({pages, isMobile, page}) => {
test('MM-T5640_2 should see landing page', async ({pw, page}) => {
// Navigate to your starting URL
await page.goto('/');
await page.evaluate(() => localStorage.clear());
await page.goto('/');
// Wait until the URL contains '/landing'
await page.waitForURL(/.*\/landing.*/);
await page.waitForURL(/.*\/landing.*/, {timeout: duration.ten_sec});
// At this point, the URL should contain '/landing'
expect(page.url()).toContain('/landing');
// Verify the landing page is visible
const landingLoginPage = new pages.LandingLoginPage(page, isMobile);
await landingLoginPage.toBeVisible();
await pw.landingLoginPage.toBeVisible();
});

Просмотреть файл

@@ -4,8 +4,6 @@
import {TestBrowser} from '@e2e-support//browser_context';
import {Client, createRandomTeam, createRandomUser} from '@e2e-support/server';
import {expect, test} from '@e2e-support/test_fixture';
import {components} from '@e2e-support/ui/components';
import {SystemConsolePage} from '@e2e-support/ui/pages/system_console';
import {getRandomId} from '@e2e-support/util';
import {UserProfile} from '@mattermost/types/users';
@@ -15,10 +13,10 @@ import {UserProfile} from '@mattermost/types/users';
* @param pages
* @returns A function to get the refreshed user, and the System Console page for navigation
*/
async function setupAndGetRandomUser(
pw: {testBrowser: TestBrowser; initSetup: () => Promise<{adminUser: UserProfile | null; adminClient: Client}>},
pages: {SystemConsolePage: typeof SystemConsolePage},
) {
async function setupAndGetRandomUser(pw: {
testBrowser: TestBrowser;
initSetup: () => Promise<{adminUser: UserProfile | null; adminClient: Client}>;
}) {
const {adminUser, adminClient} = await pw.initSetup();
if (!adminUser) {
@@ -26,7 +24,7 @@ async function setupAndGetRandomUser(
}
// # Log in as admin
const {page} = await pw.testBrowser.login(adminUser);
const {systemConsolePage} = await pw.testBrowser.login(adminUser);
// # Create a random user to edit for
const user = await adminClient.createUser(createRandomUser(), '', '');
@@ -34,7 +32,6 @@ async function setupAndGetRandomUser(
await adminClient.addToTeam(team.id, user.id);
// # Visit system console
const systemConsolePage = new pages.SystemConsolePage(page);
await systemConsolePage.goto();
await systemConsolePage.toBeVisible();
@@ -52,8 +49,8 @@ async function setupAndGetRandomUser(
return {getUser: () => adminClient.getUser(user.id), systemConsolePage};
}
test('MM-T5520-1 should activate and deactivate users', async ({pw, pages}) => {
const {getUser, systemConsolePage} = await setupAndGetRandomUser(pw, pages);
test('MM-T5520-1 should activate and deactivate users', async ({pw}) => {
const {getUser, systemConsolePage} = await setupAndGetRandomUser(pw);
// # Open menu and deactivate the user
await systemConsolePage.systemUsers.actionMenuButtons[0].click();
@@ -61,8 +58,7 @@ test('MM-T5520-1 should activate and deactivate users', async ({pw, pages}) => {
await deactivate.click();
// # Press confirm on the modal
const confirmModal = new components.GenericConfirmModal(systemConsolePage.page);
await confirmModal.confirm();
await systemConsolePage.confirmModal.confirm();
// * Verify user is deactivated
const firstRow = await systemConsolePage.systemUsers.getNthRow(1);
@@ -80,8 +76,8 @@ test('MM-T5520-1 should activate and deactivate users', async ({pw, pages}) => {
expect(await firstRow.innerText()).toContain('Member');
});
test('MM-T5520-2 should change user roles', async ({pw, pages}) => {
const {getUser, systemConsolePage} = await setupAndGetRandomUser(pw, pages);
test('MM-T5520-2 should change user roles', async ({pw}) => {
const {getUser, systemConsolePage} = await setupAndGetRandomUser(pw);
// # Open menu and click Manage roles
await systemConsolePage.systemUsers.actionMenuButtons[0].click();
@@ -121,8 +117,8 @@ test('MM-T5520-2 should change user roles', async ({pw, pages}) => {
expect((await getUser()).roles).toContain('system_user');
});
test('MM-T5520-3 should be able to manage teams', async ({pw, pages}) => {
const {systemConsolePage} = await setupAndGetRandomUser(pw, pages);
test('MM-T5520-3 should be able to manage teams', async ({pw}) => {
const {systemConsolePage} = await setupAndGetRandomUser(pw);
// # Open menu and click Manage teams
await systemConsolePage.systemUsers.actionMenuButtons[0].click();
@@ -157,8 +153,8 @@ test('MM-T5520-3 should be able to manage teams', async ({pw, pages}) => {
expect(team).not.toBeVisible();
});
test('MM-T5520-4 should reset the users password', async ({pw, pages}) => {
const {systemConsolePage} = await setupAndGetRandomUser(pw, pages);
test('MM-T5520-4 should reset the users password', async ({pw}) => {
const {systemConsolePage} = await setupAndGetRandomUser(pw);
// # Open menu and click Reset Password
await systemConsolePage.systemUsers.actionMenuButtons[0].click();
@@ -174,8 +170,8 @@ test('MM-T5520-4 should reset the users password', async ({pw, pages}) => {
await passwordInput.waitFor({state: 'detached'});
});
test('MM-T5520-5 should change the users email', async ({pw, pages}) => {
const {getUser, systemConsolePage} = await setupAndGetRandomUser(pw, pages);
test('MM-T5520-5 should change the users email', async ({pw}) => {
const {getUser, systemConsolePage} = await setupAndGetRandomUser(pw);
const newEmail = `${getRandomId()}@example.com`;
// # Open menu and click Update Email
@@ -197,8 +193,8 @@ test('MM-T5520-5 should change the users email', async ({pw, pages}) => {
expect((await getUser()).email).toEqual(newEmail);
});
test('MM-T5520-6 should revoke sessions', async ({pw, pages}) => {
const {systemConsolePage} = await setupAndGetRandomUser(pw, pages);
test('MM-T5520-6 should revoke sessions', async ({pw}) => {
const {systemConsolePage} = await setupAndGetRandomUser(pw);
// # Open menu and revoke sessions
await systemConsolePage.systemUsers.actionMenuButtons[0].click();
@@ -206,8 +202,7 @@ test('MM-T5520-6 should revoke sessions', async ({pw, pages}) => {
await removeSessions.click();
// # Press confirm on the modal
const confirmModal = new components.GenericConfirmModal(systemConsolePage.page);
await confirmModal.confirm();
await systemConsolePage.confirmModal.confirm();
const firstRow = await systemConsolePage.systemUsers.getNthRow(1);
expect(await firstRow.innerHTML()).not.toContain('class="error"');

Просмотреть файл

@@ -7,7 +7,7 @@ import {test} from '@e2e-support/test_fixture';
import {createRandomUser} from '@e2e-support/server';
import {simpleEmailRe} from '@e2e-support/util';
test('MM-T5523-1 Sortable columns should sort the list when clicked', async ({pw, pages}) => {
test('MM-T5523-1 Sortable columns should sort the list when clicked', async ({pw}) => {
const {adminUser, adminClient} = await pw.initSetup();
if (!adminUser) {
@@ -15,7 +15,7 @@ test('MM-T5523-1 Sortable columns should sort the list when clicked', async ({pw
}
// # Log in as admin
const {page} = await pw.testBrowser.login(adminUser);
const {systemConsolePage} = await pw.testBrowser.login(adminUser);
// # Create 10 random users
for (let i = 0; i < 10; i++) {
@@ -23,7 +23,6 @@ test('MM-T5523-1 Sortable columns should sort the list when clicked', async ({pw
}
// # Visit system console
const systemConsolePage = new pages.SystemConsolePage(page);
await systemConsolePage.goto();
await systemConsolePage.toBeVisible();
@@ -52,7 +51,7 @@ test('MM-T5523-1 Sortable columns should sort the list when clicked', async ({pw
expect(firstRowEmailWithoutSort).not.toBe(firstRowEmailWithSort);
});
test('MM-T5523-2 Non sortable columns should not sort the list when clicked', async ({pw, pages}) => {
test('MM-T5523-2 Non sortable columns should not sort the list when clicked', async ({pw}) => {
const {adminUser, adminClient} = await pw.initSetup();
if (!adminUser) {
@@ -60,7 +59,7 @@ test('MM-T5523-2 Non sortable columns should not sort the list when clicked', as
}
// # Log in as admin
const {page} = await pw.testBrowser.login(adminUser);
const {systemConsolePage} = await pw.testBrowser.login(adminUser);
// # Create 10 random users
for (let i = 0; i < 10; i++) {
@@ -68,7 +67,6 @@ test('MM-T5523-2 Non sortable columns should not sort the list when clicked', as
}
// # Visit system console
const systemConsolePage = new pages.SystemConsolePage(page);
await systemConsolePage.goto();
await systemConsolePage.toBeVisible();

Просмотреть файл

@@ -5,7 +5,7 @@ import {expect} from '@playwright/test';
import {test} from '@e2e-support/test_fixture';
test('MM-T5523-3 Should list the column names with checkboxes in the correct order', async ({pw, pages}) => {
test('MM-T5523-3 Should list the column names with checkboxes in the correct order', async ({pw}) => {
const {adminUser} = await pw.initSetup();
if (!adminUser) {
@@ -13,10 +13,9 @@ test('MM-T5523-3 Should list the column names with checkboxes in the correct ord
}
// # Log in as admin
const {page} = await pw.testBrowser.login(adminUser);
const {systemConsolePage} = await pw.testBrowser.login(adminUser);
// # Visit system console
const systemConsolePage = new pages.SystemConsolePage(page);
await systemConsolePage.goto();
await systemConsolePage.toBeVisible();
@@ -47,7 +46,7 @@ test('MM-T5523-3 Should list the column names with checkboxes in the correct ord
]);
});
test('MM-T5523-4 Should allow certain columns to be checked and others to be disabled', async ({pw, pages}) => {
test('MM-T5523-4 Should allow certain columns to be checked and others to be disabled', async ({pw}) => {
const {adminUser} = await pw.initSetup();
if (!adminUser) {
@@ -55,10 +54,9 @@ test('MM-T5523-4 Should allow certain columns to be checked and others to be dis
}
// # Log in as admin
const {page} = await pw.testBrowser.login(adminUser);
const {systemConsolePage} = await pw.testBrowser.login(adminUser);
// # Visit system console
const systemConsolePage = new pages.SystemConsolePage(page);
await systemConsolePage.goto();
await systemConsolePage.toBeVisible();
@@ -83,7 +81,7 @@ test('MM-T5523-4 Should allow certain columns to be checked and others to be dis
expect(emailMenuItem).not.toBeDisabled();
});
test('MM-T5523-5 Should show/hide the columns which are toggled on/off', async ({pw, pages}) => {
test('MM-T5523-5 Should show/hide the columns which are toggled on/off', async ({pw}) => {
const {adminUser} = await pw.initSetup();
if (!adminUser) {
@@ -91,10 +89,9 @@ test('MM-T5523-5 Should show/hide the columns which are toggled on/off', async (
}
// # Log in as admin
const {page} = await pw.testBrowser.login(adminUser);
const {systemConsolePage} = await pw.testBrowser.login(adminUser);
// # Visit system console
const systemConsolePage = new pages.SystemConsolePage(page);
await systemConsolePage.goto();
await systemConsolePage.toBeVisible();

Просмотреть файл

@@ -5,9 +5,8 @@ import {expect} from '@playwright/test';
import {test} from '@e2e-support/test_fixture';
import {duration} from '@e2e-support/util';
import {components} from '@e2e-support/ui/components';
test.fixme('MM-T5522 Should begin export of data when export button is pressed', async ({pw, pages}) => {
test.fixme('MM-T5522 Should begin export of data when export button is pressed', async ({pw}) => {
test.slow();
// # Skip test if no license
@@ -19,10 +18,9 @@ test.fixme('MM-T5522 Should begin export of data when export button is pressed',
}
// # Log in as admin
const {page} = await pw.testBrowser.login(adminUser);
const {page, channelsPage, systemConsolePage} = await pw.testBrowser.login(adminUser);
// # Visit system console
const systemConsolePage = new pages.SystemConsolePage(page);
await systemConsolePage.goto();
await systemConsolePage.toBeVisible();
@@ -36,8 +34,7 @@ test.fixme('MM-T5522 Should begin export of data when export button is pressed',
// # Click Export button and confirm the modal
await systemConsolePage.systemUsers.exportButton.click();
const confirmModal = new components.GenericConfirmModal(page, 'exportUserDataModal');
await confirmModal.confirm();
await systemConsolePage.exportModal.confirm();
// # Change the export duration to all time
await systemConsolePage.systemUsers.dateRangeSelectorMenuButton.click();
@@ -45,17 +42,16 @@ test.fixme('MM-T5522 Should begin export of data when export button is pressed',
// # Click Export button and confirm the modal
await systemConsolePage.systemUsers.exportButton.click();
await confirmModal.confirm();
await systemConsolePage.exportModal.confirm();
// # Click Export again button and confirm the modal
await systemConsolePage.systemUsers.exportButton.click();
await confirmModal.confirm();
await systemConsolePage.exportModal.confirm();
// * Verify that we are told that one is already running
expect(page.getByText('Export is in progress')).toBeVisible();
// # Go back to Channels and open the system bot DM
const channelsPage = new pages.ChannelsPage(page);
channelsPage.goto('ad-1/messages', '@system-bot');
await channelsPage.centerView.toBeVisible();

Просмотреть файл

@@ -4,7 +4,7 @@
import {test} from '@e2e-support/test_fixture';
import {createRandomTeam, createRandomUser} from '@e2e-support/server';
test('MM-T5521-7 Should be able to filter users with team filter', async ({pw, pages}) => {
test('MM-T5521-7 Should be able to filter users with team filter', async ({pw}) => {
const {adminUser, adminClient} = await pw.initSetup();
if (!adminUser) {
@@ -12,7 +12,7 @@ test('MM-T5521-7 Should be able to filter users with team filter', async ({pw, p
}
// # Log in as admin
const {page} = await pw.testBrowser.login(adminUser);
const {systemConsolePage} = await pw.testBrowser.login(adminUser);
// # Create a team with a user
const team1 = await adminClient.createTeam(createRandomTeam());
@@ -25,7 +25,6 @@ test('MM-T5521-7 Should be able to filter users with team filter', async ({pw, p
await adminClient.addToTeam(team2.id, user2.id);
// # Visit system console
const systemConsolePage = new pages.SystemConsolePage(page);
await systemConsolePage.goto();
await systemConsolePage.toBeVisible();
@@ -53,7 +52,7 @@ test('MM-T5521-7 Should be able to filter users with team filter', async ({pw, p
await systemConsolePage.systemUsers.verifyRowWithTextIsNotFound(user2.email);
});
test('MM-T5521-8 Should be able to filter users with role filter', async ({pw, pages}) => {
test('MM-T5521-8 Should be able to filter users with role filter', async ({pw}) => {
const {adminUser, adminClient} = await pw.initSetup();
if (!adminUser) {
@@ -61,7 +60,7 @@ test('MM-T5521-8 Should be able to filter users with role filter', async ({pw, p
}
// # Log in as admin
const {page} = await pw.testBrowser.login(adminUser);
const {systemConsolePage} = await pw.testBrowser.login(adminUser);
// # Create a guest user
const guestUser = await adminClient.createUser(createRandomUser(), '', '');
@@ -71,7 +70,6 @@ test('MM-T5521-8 Should be able to filter users with role filter', async ({pw, p
const regularUser = await adminClient.createUser(createRandomUser(), '', '');
// # Visit system console
const systemConsolePage = new pages.SystemConsolePage(page);
await systemConsolePage.goto();
await systemConsolePage.toBeVisible();
@@ -109,7 +107,7 @@ test('MM-T5521-8 Should be able to filter users with role filter', async ({pw, p
await systemConsolePage.systemUsers.verifyRowWithTextIsFound('No data');
});
test('MM-T5521-9 Should be able to filter users with status filter', async ({pw, pages}) => {
test('MM-T5521-9 Should be able to filter users with status filter', async ({pw}) => {
const {adminUser, adminClient} = await pw.initSetup();
if (!adminUser) {
@@ -117,7 +115,7 @@ test('MM-T5521-9 Should be able to filter users with status filter', async ({pw,
}
// # Log in as admin
const {page} = await pw.testBrowser.login(adminUser);
const {systemConsolePage} = await pw.testBrowser.login(adminUser);
// # Create a user and then deactivate it
const deactivatedUser = await adminClient.createUser(createRandomUser(), '', '');
@@ -127,7 +125,6 @@ test('MM-T5521-9 Should be able to filter users with status filter', async ({pw,
const regularUser = await adminClient.createUser(createRandomUser(), '', '');
// # Visit system console
const systemConsolePage = new pages.SystemConsolePage(page);
await systemConsolePage.goto();
await systemConsolePage.toBeVisible();

Просмотреть файл

@@ -5,7 +5,7 @@ import {test} from '@e2e-support/test_fixture';
import {createRandomUser} from '@e2e-support/server';
import {getRandomId} from '@e2e-support/util';
test('MM-T5521-1 Should be able to search users with their first names', async ({pw, pages}) => {
test('MM-T5521-1 Should be able to search users with their first names', async ({pw}) => {
const {adminUser, adminClient} = await pw.initSetup();
if (!adminUser) {
@@ -13,14 +13,13 @@ test('MM-T5521-1 Should be able to search users with their first names', async (
}
// # Log in as admin
const {page} = await pw.testBrowser.login(adminUser);
const {systemConsolePage} = await pw.testBrowser.login(adminUser);
// # Create 2 users
const user1 = await adminClient.createUser(createRandomUser(), '', '');
const user2 = await adminClient.createUser(createRandomUser(), '', '');
// # Visit system console
const systemConsolePage = new pages.SystemConsolePage(page);
await systemConsolePage.goto();
await systemConsolePage.toBeVisible();
@@ -38,7 +37,7 @@ test('MM-T5521-1 Should be able to search users with their first names', async (
await systemConsolePage.systemUsers.verifyRowWithTextIsNotFound(user2.email);
});
test('MM-T5521-2 Should be able to search users with their last names', async ({pw, pages}) => {
test('MM-T5521-2 Should be able to search users with their last names', async ({pw}) => {
const {adminUser, adminClient} = await pw.initSetup();
if (!adminUser) {
@@ -46,14 +45,13 @@ test('MM-T5521-2 Should be able to search users with their last names', async ({
}
// # Log in as admin
const {page} = await pw.testBrowser.login(adminUser);
const {systemConsolePage} = await pw.testBrowser.login(adminUser);
// # Create 2 users
const user1 = await adminClient.createUser(createRandomUser(), '', '');
const user2 = await adminClient.createUser(createRandomUser(), '', '');
// # Visit system console
const systemConsolePage = new pages.SystemConsolePage(page);
await systemConsolePage.goto();
await systemConsolePage.toBeVisible();
@@ -71,7 +69,7 @@ test('MM-T5521-2 Should be able to search users with their last names', async ({
await systemConsolePage.systemUsers.verifyRowWithTextIsNotFound(user2.email);
});
test('MM-T5521-3 Should be able to search users with their emails', async ({pw, pages}) => {
test('MM-T5521-3 Should be able to search users with their emails', async ({pw}) => {
const {adminUser, adminClient} = await pw.initSetup();
if (!adminUser) {
@@ -79,14 +77,13 @@ test('MM-T5521-3 Should be able to search users with their emails', async ({pw,
}
// # Log in as admin
const {page} = await pw.testBrowser.login(adminUser);
const {systemConsolePage} = await pw.testBrowser.login(adminUser);
// # Create 2 users
const user1 = await adminClient.createUser(createRandomUser(), '', '');
const user2 = await adminClient.createUser(createRandomUser(), '', '');
// # Visit system console
const systemConsolePage = new pages.SystemConsolePage(page);
await systemConsolePage.goto();
await systemConsolePage.toBeVisible();
@@ -104,7 +101,7 @@ test('MM-T5521-3 Should be able to search users with their emails', async ({pw,
await systemConsolePage.systemUsers.verifyRowWithTextIsNotFound(user2.email);
});
test('MM-T5521-4 Should be able to search users with their usernames', async ({pw, pages}) => {
test('MM-T5521-4 Should be able to search users with their usernames', async ({pw}) => {
const {adminUser, adminClient} = await pw.initSetup();
if (!adminUser) {
@@ -112,14 +109,13 @@ test('MM-T5521-4 Should be able to search users with their usernames', async ({p
}
// # Log in as admin
const {page} = await pw.testBrowser.login(adminUser);
const {systemConsolePage} = await pw.testBrowser.login(adminUser);
// # Create 2 users
const user1 = await adminClient.createUser(createRandomUser(), '', '');
const user2 = await adminClient.createUser(createRandomUser(), '', '');
// # Visit system console
const systemConsolePage = new pages.SystemConsolePage(page);
await systemConsolePage.goto();
await systemConsolePage.toBeVisible();
@@ -137,7 +133,7 @@ test('MM-T5521-4 Should be able to search users with their usernames', async ({p
await systemConsolePage.systemUsers.verifyRowWithTextIsNotFound(user2.email);
});
test('MM-T5521-5 Should be able to search users with their nick names', async ({pw, pages}) => {
test('MM-T5521-5 Should be able to search users with their nick names', async ({pw}) => {
const {adminUser, adminClient} = await pw.initSetup();
if (!adminUser) {
@@ -145,14 +141,13 @@ test('MM-T5521-5 Should be able to search users with their nick names', async ({
}
// # Log in as admin
const {page} = await pw.testBrowser.login(adminUser);
const {systemConsolePage} = await pw.testBrowser.login(adminUser);
// # Create 2 users
const user1 = await adminClient.createUser(createRandomUser(), '', '');
const user2 = await adminClient.createUser(createRandomUser(), '', '');
// # Visit system console
const systemConsolePage = new pages.SystemConsolePage(page);
await systemConsolePage.goto();
await systemConsolePage.toBeVisible();
@@ -169,7 +164,7 @@ test('MM-T5521-5 Should be able to search users with their nick names', async ({
await systemConsolePage.systemUsers.verifyRowWithTextIsNotFound(user2.email);
});
test('MM-T5521-6 Should show no user is found when user doesnt exists', async ({pw, pages}) => {
test('MM-T5521-6 Should show no user is found when user doesnt exists', async ({pw}) => {
const {adminUser} = await pw.initSetup();
if (!adminUser) {
@@ -177,10 +172,9 @@ test('MM-T5521-6 Should show no user is found when user doesnt exists', async ({
}
// # Log in as admin
const {page} = await pw.testBrowser.login(adminUser);
const {systemConsolePage} = await pw.testBrowser.login(adminUser);
// # Visit system console
const systemConsolePage = new pages.SystemConsolePage(page);
await systemConsolePage.goto();
await systemConsolePage.toBeVisible();