Need help with POM Appium/Java framework - initializing elements

Working on automation framework and got stuck on not being able to find elements. Everything seems correct but my guess is i am not initializing elements correctly before finding them. Any help in the right direction appreciated!

I have Driver.java that configures session for device:

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;


public class DriverFactory {
    protected static AppiumDriver driver;

    /*public DriverFactory() throws MalformedURLException {
        initializeAppiumSession();
    }
    protected void initializeAppiumSession() throws MalformedURLException {
     configureSessionForDevice();
    //  configureSessionForEmulator();
    }*/

@BeforeClass
    // Android device details
    public void configureSessionForDevice() throws MalformedURLException {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("platformVersion", Device.platformVersion);
        capabilities.setCapability("deviceName", Device.deviceName);
        capabilities.setCapability("platformName", Device.platformName);
        capabilities.setCapability("udid", Device.udid);
        capabilities.setCapability("app", "/Users/artem/Documents/app-debug.apk");
        capabilities.setCapability("appPackage", "com.asperasoft.android.asperaoncloud.debug");
        capabilities.setCapability("appActivity", "com.asperasoft.android.files.presentation.ui.activity.SplashScreenActivity");
        capabilities.setCapability("automationName", "UiAutomator2");

    driver =  new AndroidDriver(new URL(Device.URL), capabilities);
    }

@AfterClass
    public void killAppiumSession(){
        driver.quit();
    }
}

I have AbstractScreen.java that supposed to initialize elements:

package AppPages;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import io.appium.java_client.remote.HideKeyboardStrategy;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.support.PageFactory;

import java.util.concurrent.TimeUnit;

public class AbstractScreen {

    protected AppiumDriver driver;

   /* public AbstractScreen(AndroidDriver driver) {
        this.driver = driver;
    }*/

    public AbstractScreen(AppiumDriver driver) {

        this.driver = driver;
        PageFactory.initElements(new AppiumFieldDecorator(driver, 5, TimeUnit.SECONDS), this);

    }
}

I have WelcomeScreen.java that will have all the buttons and methods for that page(only have 1 for now):

package AppPages;


import Driver.DriverFactory;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import org.openqa.selenium.By;
import io.appium.java_client.pagefactory.AndroidBy;
import io.appium.java_client.pagefactory.AndroidFindBy;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;

public class WelcomeScreen extends AbstractScreen {

 @AndroidFindBy(id = "button1")
 public AndroidElement loginToYourAccountButton;

    public WelcomeScreen (AppiumDriver driver) { super (driver);}

    public void clickLoginButtonMethod () {
        loginToYourAccountButton.click();
    }
}

And my test class:

package Tests;

import AppPages.AbstractScreen;
import AppPages.WelcomeScreen;
import Driver.DriverFactory;
import org.testng.annotations.Test;

import java.net.MalformedURLException;

public class ClickLoginButton extends DriverFactory {

    //public ClickLoginButton() throws MalformedURLException {
    //}

@Test
    public void ClickButton() throws Throwable {
        new WelcomeScreen(driver).clickLoginButtonMethod();
}
}

My pom.xml:


org.seleniumhq.selenium
selenium-server
3.14.0
provided


io.appium
java-client
6.0.0-BETA2
provided


org.testng
testng
6.9.13.5


org.apache.maven.surefire
surefire-testng
3.0.0-M1

Update java client to the most recent version

And exclude selenium from depndencies

Instead of investing time with framework creation, why don’t you use one of the best open source framework Serenity BDD, you will save lots of money for your company and lots of headaches.

If you’re really interested in coding, you can submit PR for this project

check out demo project with Appium + Cucumber + Serenity

Mykola, thank you for your advice. Updating java-client to 6.1.0 and removing selenium from dependencies made it all work.

Could you please share how to remove selenium from dependencies