Concepts like base lessons and util lessons are normally anti-patterns (see right here and right here).
One fundamental heuristic for good OO design is composition over inheritance, as a result of it offers extra flexibility in modifications and makes unit testing simpler.
As Alexey stated, you should use dependency injection to create your web page objects. You may see an instance challenge right here.
Usually talking, you are able to do like this:
Step file:
class Step {
constructor(Driver driver) { this.driver = driver; }
enjoyable openMainPage() {
this.mainPage = new MainPage(this.driver)
this.mainPage.open()
}
enjoyable login(username, password) {
this.loggedPage = this.mainPage.login(username, password)
}
}
Then on every web page object, you possibly can obtain the motive force within the constructor:
class MainPage {
constructor(Driver driver) { this.driver = driver; }
enjoyable login(username, password) {
fillUsername(username)
fillPassword(password)
clickOnLogin()
return new LoginPage(this.driver)
}
}
And in case you have a sub-component in a web page object, you possibly can move both a Driver or a WebElement within the constructor, so this object can use solely what you management.
And you may unit check the web page objects by passing a pretend Driver/WebElements, which you’ll be able to management within the exams.
Through the use of dependency injection, a change in a single web page object will not have an effect on others and it is possible for you to to make use of stack traces to simply monitor points.