Appium Page Elements are Null - Does Appium page object model work with C#?

Hey guys, first time poster here! I’m currently trying to learn test automation, so I have created a C#/POM/NUnit solution using Saucelabs.

I’ve managed to get my Selenium tests running successfully on my web-app, however I’m having problems getting Appium to work on my hybrid mobile app. Currently my page elements are null.

I’m still getting new to C#/test automation, so any improvements would be appreciated :). So far I have the following:

BaseTests class. GetDriver method is in the setup of all my tests:

[TestFixture("Android Emulator","portrait","Android","4.4")]
class BKGoBaseTests : DynamicObject
{
    public string _deviceName;
    public string _deviceOrientation;
    public string _platformName;
    public string _platformVersion;

    public AppiumDriver<AppiumWebElement> GetDriver()
    {
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.SetCapability("username", "####");
        caps.SetCapability("accessKey", "#####");
        //Appium Capabilities
        caps.SetCapability("appiumVersion", "1.5.3");
        caps.SetCapability("deviceName", _deviceName);
        caps.SetCapability("deviceOrientation", _deviceOrientation);
        caps.SetCapability("browserName", "");
        caps.SetCapability("platformName", _platformName);
        caps.SetCapability("platformVersion", _platformVersion);
        caps.SetCapability("app", "sauce-storage:basekit.apk");



        AndroidDriver<AppiumWebElement> _driver = new AndroidDriver<AppiumWebElement>(
        new Uri("http://ondemand.saucelabs.com:80/wd/hub"),
            caps, TimeSpan.FromSeconds(600));

        return _driver;
    }

Test Class:

[Parallelizable]
class BKGoLoginTests : BKGoBaseTests 
{
    public AppiumDriver<AppiumWebElement> _driver;
    private LoginPageFactory _loginPageFactory;

    public BKGoLoginTests(string deviceName, string deviceOrientation, string platformName, string platformVersion)
    {
        _deviceName = deviceName;
        _deviceOrientation = deviceOrientation;
        _platformName = platformName;
        _platformVersion = platformVersion;
    }


    [SetUp]
    public void LoginSetup()
    {
        _driver = GetDriver();
        _loginPageFactory = new LoginPageFactory(_driver);
    }

    [Test]
    public void BKGoLoginTest()
    {
        _loginPageFactory.LoginAs("[email protected]", "bentest");
        Assert.AreEqual("Editor", _driver.Title);
    }
}

Page Factory:

    public LoginPage _loginPage;
    public DashboardPage _dashboardPage;
    public AppiumDriver<AppiumWebElement> _driver;
    public LoginPageFactory(AppiumDriver<AppiumWebElement> driver)
    {
        _driver = driver;
        _loginPage = new LoginPage(_driver);
    }

    public void LoginAs(string email, string password)
    {
        var LoginEmail = _loginPage.EmailTxt;
        var LoginPassword = _loginPage.PasswordTxt;
        var LoginBtn = _loginPage.SignInBtn;


        LoginEmail.SendKeys(email);
        LoginPassword.SendKeys(password);
}

Page Class - From my debugging, I think the issue is something related to this class, perhaps the way I’m initialising the elements?

public LoginPage(AppiumDriver<AppiumWebElement> driver)
    {
        AppiumPageObjectMemberDecorator decorator = new AppiumPageObjectMemberDecorator(new TimeOutDuration(System.TimeSpan.FromSeconds(15)));
        PageFactory.InitElements(driver, this, decorator);
    }

    [FindsByAndroidUIAutomator(AndroidUIAutomator = "new UiSelector().resourceId(\"android:id/username\")")]
    public AppiumWebElement EmailTxt { get; set; }

    [FindsByAndroidUIAutomator(AndroidUIAutomator = "//android.widget.EditText[contains(@resource-id,'password')]")]
    public AppiumWebElement PasswordTxt { get; set; }

If you need anymore info, let me know!

Many thanks in advance!