-
-
Notifications
You must be signed in to change notification settings - Fork 513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extending PageObject using PageFactory for WebElementFacade #2971
Comments
Try removing the constructor. |
If I remove the constructor and the call to "open()" method, the browser doesn't start at all. I removed the constructor and moved the |
You can call the open() method but don't do it in the constructor - that will interfere with the Serenity lifecycle. |
I found my error: I was calling LoginPage constructor on the Cucumber Step. Removed the constructor and the call to it, then directly used Thank you very much! |
I'm trying to use PageFactory within a PageObject extending class, but I get a NullPointerException when trying to access a WebElementFacade. Is there any example with PageObjets that you can refer with the complete code of a working PageObject child class?
Here is mine:
`package pageobjects;
import exceptions.InvalidCredentialsLoginException;
import javafx.util.Duration;
import net.serenitybdd.core.annotations.findby.FindBy;
import net.serenitybdd.core.pages.PageObject;
import net.serenitybdd.core.pages.WebElementFacade;
import net.thucydides.core.annotations.At;
import net.thucydides.core.annotations.DefaultUrl;
import net.thucydides.core.annotations.WhenPageOpens;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.support.PageFactory;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalUnit;
import java.util.concurrent.TimeUnit;
@DefaultUrl("http://automation.sgh-os.10.125.125.74.nip.io/auth/login")
@at(urls={"#HOST/auth/login"})
public class LoginPage extends PageObject {
}
`
The error I get is:
net.serenitybdd.core.pages.UnableToInvokeWhenPageOpensMethods: Could not execute @WhenPageOpens annotated method: null at net.serenitybdd.core.pages.PageObject.callWhenPageOpensMethods(PageObject.java:954) at net.serenitybdd.core.pages.PageObject.initializePage(PageObject.java:888) at net.serenitybdd.core.pages.PageObject.open(PageObject.java:883) at net.serenitybdd.core.pages.PageObject.open(PageObject.java:869) at pageobjects.LoginPage.<init>(LoginPage.java:34) at starter.cucumber.steps.LoginSteps.iLoginAs(LoginSteps.java:21) at ✽.I login as 'AUTOAdmin'(file:///C:/Users/baque/Documents/Trabajo/Lamansys/Proyectos/serenity-cucumber-poc/src/test/resources/features/Login.feature:4) Caused by: java.lang.NullPointerException at pageobjects.LoginPage.waitUntilPageLoads(LoginPage.java:40) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498)
The text was updated successfully, but these errors were encountered: