Appium with Page Object Factory

I have this these test and it opens up appium but fail to perform the test in getStartedPage . I would appreciate if someone could help out with this.

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

public class baseSetup {

public static void main (String [] args) throws MalformedURLException {

    DesiredCapabilities cap=new DesiredCapabilities();
    cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
    cap.setCapability(MobileCapabilityType.DEVICE_NAME,"d8528de2");
    cap.setCapability("app", "C:\\Users\\Tutu\\Downloads\\tutuApps\\base.apk");
    AndroidDriver driver = new<WebElement> AndroidDriver (new URL("http://127.0.0.1:4723/wd/hub"),cap);
    driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);

}

}

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.pagefactory.AndroidFindBy;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.PageFactory;

import java.util.concurrent.TimeUnit;

public class getStarted extends testPage
{

AndroidDriver<WebElement>driver;

public getStarted (AppiumDriver<WebElement>driver)
{
    PageFactory.initElements(new AppiumFieldDecorator(driver, 100, TimeUnit.SECONDS), this);
}


@AndroidFindBy(id = "phone_number_edit_text")
public MobileElement enterPhone;

@AndroidFindBy(uiAutomator = "new UiSelector().text(\"Submit\")")
public WebElement submitPhone;



public WebElement enterPhone (){
    return enterPhone;
}

public WebElement submitPhone() {
    return submitPhone;
}

}

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import org.junit.After;
import org.junit.BeforeClass;
import org.openqa.selenium.WebElement;

public class testPage extends baseSetup {

AndroidDriver<WebElement> driver;

@BeforeClass
public static void baseSetup ()
{
        baseSetup();
}


    public void getStartedPage (AppiumDriver driver) {

        getStarted getStarted = new getStarted(driver);
        getStarted.enterPhone().click();
        getStarted.submitPhone().sendKeys("078000000000");
    }

    @After
public void quitDriver ()
{
    driver.quit();
}

}

@Test() annotation is missing in your test method

Try the below code
@Test()
public void getStartedPage (AppiumDriver driver) {

    getStarted getStarted = new getStarted(driver);
    getStarted.enterPhone().click();
    getStarted.submitPhone().sendKeys("078000000000");
}

@Venkatesh I have tried it and here is what i get - java.lang.Exception: Method getStartedPage should have no parameters. Thanks

you can get the driver in class scope instead of passing in the @Test. I don’t see the need of passing driver as an argument.

@Venkatesh how do i get to do this please ?

you are initialising you driver in the main(), put a getter method in the same class and make it public and then call it in your getStartedPage. That would be possibly the easiest way to do. Hope this helps.

AndroidDriver driver = new AndroidDriver (new URL(“http://127.0.0.1:4723/wd/hub”),cap);
driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);

Modified code

@Test()
public void getStartedPage () {

getStarted getStarted = new getStarted(**getAndroidDriver()**);
getStarted.enterPhone().click();
getStarted.submitPhone().sendKeys("078000000000");

}