Skip to content

Commit abd0f46

Browse files
committed
update RootPage and AppPage
1 parent 0f348c8 commit abd0f46

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { expect } from '@playwright/test';
22
import type { Page } from '@playwright/test';
33

4+
import type { NavigateArgs, RouteTo } from '../helpers/types';
5+
46
export abstract class RootPage {
57
readonly $ref: Page;
6-
protected abstract readonly defaultUrl: string;
78

89
constructor(page: Page) {
910
this.$ref = page;
@@ -13,8 +14,17 @@ export abstract class RootPage {
1314
return expect(this.$ref);
1415
}
1516

16-
async goto() {
17-
await this.$ref.goto(this.defaultUrl);
18-
await this.$ref.waitForURL(this.defaultUrl);
17+
protected getUrlWithParams<TPath extends RouteTo>(...args: NavigateArgs<TPath>) {
18+
let url: string = args[0];
19+
if (args[1]) {
20+
Object.entries(args[1]).forEach(([key, value]) => {
21+
url = url.replace('$' + key, String(value));
22+
});
23+
}
24+
return url;
25+
}
26+
27+
async goto<TPath extends RouteTo>(...args: NavigateArgs<TPath>): Promise<void> {
28+
await this.$ref.goto(this.getUrlWithParams(...args));
1929
}
2030
}

testing/e2e/src/pages/_app.page.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { Locator, Page } from '@playwright/test';
2+
3+
import { RootPage } from './__root.page';
4+
5+
export abstract class AppPage extends RootPage {
6+
readonly sidebar: Locator;
7+
8+
constructor(page: Page) {
9+
super(page);
10+
this.sidebar = page.getByTestId('sidebar');
11+
}
12+
}

0 commit comments

Comments
 (0)