Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
playwright: add new pageWithCredentials fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Jan 5, 2024
1 parent 645ccb1 commit 6657f56
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions playwright/element-web-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { test as base, expect as baseExpect, Locator, Page, ExpectMatcherState, ElementHandle } from "@playwright/test";
import {
test as base,
expect as baseExpect,
Locator,
Page,
ExpectMatcherState,
ElementHandle,
PlaywrightTestArgs,
} from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";
import _ from "lodash";
import { basename } from "node:path";
Expand Down Expand Up @@ -73,6 +81,15 @@ export const test = base.extend<
homeserver: HomeserverInstance;
oAuthServer: { port: number };
credentials: CredentialsWithDisplayName;

/**
* The same as {@link PlaywrightTestArgs#page}, but adds an initScript which will populate localStorage
* with the user's details from {@link #credentials} and {@link #homeserver}.
*
* Similar to {@link #user}, but doesn't load the app.
*/
pageWithCredentials: Page;

user: CredentialsWithDisplayName;
displayName?: string;
app: ElementAppPage;
Expand Down Expand Up @@ -163,7 +180,8 @@ export const test = base.extend<
});
},
labsFlags: [],
user: async ({ page, homeserver, credentials }, use) => {

pageWithCredentials: async ({ page, homeserver, credentials }, use) => {
await page.addInitScript(
({ baseUrl, credentials }) => {
// Seed the localStorage with the required credentials
Expand All @@ -180,9 +198,12 @@ export const test = base.extend<
},
{ baseUrl: homeserver.config.baseUrl, credentials },
);
await use(page);
},

user: async ({ pageWithCredentials: page, credentials }, use) => {
await page.goto("/");
await page.waitForSelector(".mx_MatrixChat", { timeout: 30000 });

await use(credentials);
},

Expand Down

0 comments on commit 6657f56

Please sign in to comment.