Hello everyone,
Makes it sense to define an abstract class into Keyword folder?
public abstract class Parser {
def commonMethod(String) {
...
} @Keyword
abstract def method1(); @Keyword
abstract def method2();
}
public class Parser1 extends Parser {
def method1() {
...
}
def method2() {
...
}
}
public class Parser2 extends Parser {
def method1() {
...
}
def method2() {
...
}
}
Because I get this error
Groovy:You cannot create an instance from the abstract class ‘Parser’.
I call the Keyword like that:
CustomKeywords.'Parser1.method1'()
Thank’s a lot for your help!
Can I question your need for abstract classes? Why not just define your base class(es) and extend them in your outer class(es)?
In addition, if you dispense with the @Keyword decorator, make your methods static, import them statically, you can call your methods without all the stringified noise from CustomKeywords.‘blah-blah’.
import my_package.my_class.*
method1()
Of course you can.
I use an abstract class because I have several parser which use method1(), method2(), … But each methods have a different content. Can I only use “extend” ?
Thank’s!
That’s fair.
The approach I took was to create a hierarchy where, “somewhere in the middle” I have a basePage class. Each page in my (huge) app (eg homePage) extends basePage and overrides (if it needs to) the methods/properties in basePage.
I guess it’s a matter of opinion and personal choice but, I dearly wanted to avoid the gorilla/banana problem (which I think I’ve managed to do).
On the methods-I-need-everywhere front, I created a couple of “tools” classes with short, useful static methods which I import on every “page”.
I’ll be interested to hear how you get along with your plan. Feel free to PM me, anytime.
Thanks for posting!