appium / dotnet-client

Extension to the official Selenium dotnet webdriver
Apache License 2.0
381 stars 188 forks source link

Error - The name 'PageFactory' does not exist in the current context #222

Closed sunilpatro1985 closed 6 years ago

sunilpatro1985 commented 6 years ago

Mac OS .net core Appium.webdriver - 4.0.0.1 - beta Supported selenium webdriver - 3.8.0 Nunit3 Visual Studio for Mac

Running appium C# for UICatalog.app on Ios simulator, getting error Error - The name 'PageFactory' does not exist in the current context

Here is the code -

using System;
using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Appium.Interfaces;
using OpenQA.Selenium.Appium.iOS;
using OpenQA.Selenium.Appium.PageObjects.Attributes;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.PageObjects;

namespace OnBalanceMobile
{
    public class Testing
    {
        public static AppiumDriver<AppiumWebElement> driver;
        public static DesiredCapabilities cap;

        [FindsByIOSUIAutomation(XPath = "//XCUIElementTypeStaticText[@name='Action Sheets']")]
        public IWebElement TopOption;

        [Test]
        public void Testing1()
        {
            iOS_LaunchApp();
            PageFactory.InitElements(driver, this);
            Thread.Sleep(3000);
            TopOption.Click();
        }

        public static void iOS_LaunchApp()
        {
            cap = new DesiredCapabilities();
            cap.SetCapability("platformName", "iOS");
            cap.SetCapability("deviceName", "iPhone 7 Plus");
            cap.SetCapability("platformVersion", "11.2");
            cap.SetCapability("automationName", "XCUITest");
            cap.SetCapability("bundleId", "com.example.apple - samplecode.UICatalog");
            cap.SetCapability("noReset", true);
            driver = new IOSDriver<AppiumWebElement>(new Uri("http://127.0.0.1:4723/wd/hub"), cap);
            Assert.IsNotNull(driver);
        }
    }
}
bicarbon8 commented 6 years ago

@sunilpatro1985 the latest Selenium Support package has removed the PageFactory as per: https://github.com/SeleniumHQ/selenium/issues/4387 is this your issue?

jimevans commented 6 years ago

PageFactory has not yet been completely removed from the Selenium repository. However, it does not exist, and never has existed for .NET Core projects. This is one reason PageFactory is marked deprecated in Selenium, has been moved to a new repository, and the new repo looking for an owner and maintainer.