1

Im trying to set up cucumber over my page object. I currently have as my login page object:

@FindBy (id  = cF.username)           public WebElement username;
@FindBy (id  = cF.password)           public WebElement password;
@FindBy (id  = cF.loginButton)        public WebElement loginButton;


@Test
public websiteProspector_beta doLogin(String myUsername, String myPassword) throws IOException {
    logs.InfoDetails("Logging Into Tomcat8- 2092");

    try {
        username.sendKeys(myUsername);
        password.sendKeys(myPassword);
        loginButton.click();
        {...}

and my step description as:

    @And("^I log into ao$")
public void i_log_into_ao() throws Throwable {
    actonLogin = new actonLogin(driver);
    actonLogin.doLogin(cF.loginUsername, cF.loginPassword);
    throw new PendingException();
}

When i run it, it successfully runs the first two steps, however when it comes to an object with @findby, I get this error:

java.lang.NullPointerException
at com.acton.PageObjects.loginPage.actonLogin.doLogin(actonLogin.java:41)
at com.acton.cucumber.cucumberSteps.i_log_into_ao(cucumberSteps.java:41)
at ✽.And I log into ao(com/acton/cucumber/login.feature:6)

The reason why I know it's due to the @Findby is because when I change the login page object to use "driver.findelement(By...." it's successful with no errors. is there something im missing?

I am new to cucumber and automation all together, any help i can get is appreciated.

4

Did you run PageFactory.initElements? The PageFactory magic won't actually parse the annotations until you do so. I usually put into the constructor a line like:

PageFactory.initElements(driver, this);

So that it runs when I construct the page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.