1

i am running a serenity bdd framework (cucumber) using selenium java for web automation

The driver object is successfully loaded along with the page object for PageFactory.initElements but still i am getting InvocationTargetException

The selenium java version is 3.141.59

serenity version is 2.4.24

running on java8

code snippet Base class

public abstract class BasePageHelper {

public static WebDriver webDriver;

public static SeleniumWait seleniumWait;
public static WebDriverWait wait;
private T pageObject;


@SuppressWarnings("unchecked")
public BasePageHelper(WebDriver driver) {
    pageObject = (T) PageFactory.initElements(driver, getPageObjectClass());
    this.webDriver = driver;
    this.wait = wait;
    seleniumWait = new SeleniumWait(webDriver);
}


private Class<?> getPageObjectClass() {
    if (!getClass().isAnnotationPresent(PageObject.class)) {
        throw new RuntimeException("PageObject annotation must be present on a test helper class");
    } else {            
        return getClass().getAnnotation(PageObject.class).pageObjectClass();
        
    }
}

PageObject class

@Retention(RetentionPolicy.RUNTIME)

@Target(ElementType.TYPE)
public @interface PageObject {

    Class<?> pageObjectClass();

}

traceback of error TracebackOfError

lucas-nguyen-17
  • 5,516
  • 2
  • 9
  • 20
bharatraj shetty
  • 33
  • 1
  • 1
  • 6
  • this doesn't look right: Class> pageObjectClass(); and why a generic type/class in an interface? What implements the interface? In general when I see getClass() used I assume there's a big architecture problem. (Not your fault, it's probably cucumber or some other framework you are using...) As for the exception, it's an exception wrapped inside another exception... and so on... hard to trace that back but I'd look at parentrunner... and try to untangle all the reflections here. – pcalkins Aug 26 '21 at 17:00
  • actually it used to work sometime back and i got it from some other resource who left the company. It traces back to instantiatePage(driver, pageClassToProxy) which fails even when there is driver object (ChromeDriver: chrome on WINDOWS (7af6355024eefab3327da0f0ecc8d2d1)) and pageClassToProxy class (class com.gis.pageobject.CWMPageObject) – bharatraj shetty Aug 26 '21 at 18:05
  • Post the code of `getPageObjectClass` and where the method `BasePageHelper` is being used. – Nandan A Aug 26 '21 at 18:56

0 Answers0