export class Common_Class{
Page1: Page1
//....
Page50: Page 50
constructor(pageClass1: Page1, page2: Page2 .... 50){
this.Page1= Page1
}
}
I have a need to import 50 60 PageClass for Playwright for Common services. How many constructor parameters can I accomodate maximum like that in Typescript
Tried adding a few constructor parameters and they were good.. how much can i add more . What will happen if I add too much .. Loading/perf problems? Limitations on parameters ?
Why because it represents a single point representation of all available Pages within the framework without searching here and there .. This is how I would use without importing because it extends teh basic playwright test class.
When method of playwriight-bdd basiscally is co extended with test class of playwright
When('I navigate to ', async function ({Login_Page}, parameters) {
Login_Page.anymethods();
});
Not an answer for the direct op question, but this does provide an alternative approach to what they are trying to do.
Create a pages class that has all the pages within:
// pages.ts
import { Page } from '@playwright/test';
import { Page1, Page2, Page3, Page4, Page5} from 'where they are...'
export class Pages {
page1 = new Page1(this.page);
page2 = new Page2(this.page);
page3 = new Page3(this.page);
page4 = new Page4(this.page);
page5 = new Page5(this.page);
constructor(private readonly page: Page) {}
}
Then have a fixture that uses the Pages collection:
// myFixture.ts
import { Page, test as base } from '@playwright/test';
import { Pages } from 'pages.ts';
type TestFixture = {
pages: Pages;
}
export const test = base.extend<TestFixtures>({
pages: async ({ page }, use) => {
const pages = new Pages(page);
await use(pages);
},
});
Then use that fixture in your test and the Pages collection you have exposed:
// myTest.spec.ts
import { test } from 'myFixture.ts';
test('Test something here', async ({ pages }) = > {
await pages.page1.doSomething();
await pages.page2.somethingElse();
});