I'm using typescript for test automation and I have a tons of classes like this:
class Something {
//properties
constructor(page:Page){}
//methods
}
class Account {
//properties
constructor(page:Page, accountNumber: string){}
//methods
}
class Navigation {
//properties
constructor(page:Page, navigation: NavigationStrategy){}
//methods
}
same page:Page
object I should pass to all my constructors e.g
it("some test" async => {
const page = await browser.newPage();
const searchPage = new SearchPage(page);
const account = new Account(page, "2135");
const navigation = new Navigation(page, new LHSNavigation(page));
})
How can I automaticaly inject this page
object to all constructors? For examaple I want to get next result
it("some test" async => {
const page = await browser.newPage();
const pageProvider = new PageProvider(page)
const searchPage = pageProvider.create(SearchPage);
// OR
const account = pageProvider.create(Account)("2135");
// OR maybe
const navigation = pageProvider.create(Navigation, LHSNavigation);
})
//Or maybe without page provider
const navigation = Navigation(LHSNavigation);
And all types should be resolved in compile time
Aucun commentaire:
Enregistrer un commentaire