3

I'm creating a test automation framework in C# .Net using Appium to automate IOS and Android and wanted to use Page Object Design Pattern. So I wanted to utilize the PageFactory extension.

By adding the DotNetSeleniumExtras.PageObjects.Core as NuGet package results in an error (red squiggly lines). 4 errors

CS7069: Reference to type 'IFindsById" claims it is defined in 'WebDriver', but it could not be found.

enter image description here

I needed this extension DotNetSeleniumExtras.PageObjects.Core in order for me to instantiate the Page objects and be able to implement the Page Object Design pattern.

Please let me know if I'm missing something here or if there are any workarounds. Thanks in advance!

Below is my code for added context:

using NUnit.Framework;
using OpenQA.Selenium.Appium.iOS;
using OpenQA.Selenium.Appium.PageObjects;
using SeleniumExtras.PageObjects;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;

namespace NativeApp_TestAutomation.Tests.Specs.IOS
{
[TestFixture]
public class LoginTest
{
    private IOSDriver<IOSElement> _driver;
    private HomeScreen _pageObject;

    [OneTimeSetUp]
    public void BeforeAll()
    {
        var capabilities = Capabilities.GetIOSCapabilities("");
        var serverUri = Env.ServerIsRemote() ? AppiumServer.RemoteServerUri : AppiumServer.LocalServiceUri;
        _driver = new IOSDriver<IOSElement>(serverUri, capabilities, Env.LaunchTimeoutSeconds);

        var timeSpan = new TimeOutDuration(new TimeSpan(0, 0, 0, 5, 0));
        _pageObject = new HomeScreen(_driver);

        PageFactory.InitElements(_driver, _pageObject, new AppiumPageObjectMemberDecorator(timeSpan));
    }

}

}

I'm getting the red squiggly lines here with all having the same errors. enter image description here

enter image description here

Harvey
  • 399
  • 4
  • 15
  • 31
  • Can you show your .csproj file? As your link shows, the NuGet package only supports certain frameworks. Your project might be using one of the unsupported ones. In that case you would also be seeing a build warning saying something like "This package may not be fully compatible with your project" – Matt Thomas Jul 11 '22 at 21:08
  • Hey @MattThomas sharing the gist link >> https://gist.github.com/veydecapia/a081667fdb20dc60fbea596c690bef36 – Harvey Jul 12 '22 at 00:01
  • I have tried building the solution it only have an errors in it. No warnings. – Harvey Jul 12 '22 at 00:01
  • What I notice is that 2 of the packages included in the solutions have dependency on the Selenium Webdriver? https://www.nuget.org/packages/Selenium.WebDriver/#usedby-body-tab – Harvey Jul 12 '22 at 01:51
  • That's Appium.WebDriver and DotNetSeleniumExtras.PageObjects. Do you think there are possible conflicts? – Harvey Jul 12 '22 at 01:52
  • I was able to reproduce your issue by referencing the NuGet packages you are and then writing something akin to your `PageFactory.InitElements` line, and then adding an assembly reference to "WebDriver". Without the assembly reference my IDE tells me it needs the assembly reference. With the assembly reference I get your error messages. So you need to find the "WebDriver" assembly and reference it. I'm not familiar enough to know if that should come from a NuGet package or if you have to download it separately from somewhere, but that's your issue – Matt Thomas Jul 12 '22 at 12:39
  • "Do you think there are possible conflicts?" I'm not sure. How did you arrive at your current code? If you don't understand exactly what it's doing then I'd recommend reading up on the documentation to see how all the pieces fit together – Matt Thomas Jul 12 '22 at 12:41
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/246374/discussion-between-harvey-and-matt-thomas). – Harvey Jul 12 '22 at 13:44

1 Answers1

1

One of the most common reasons for that is a mixture of version and assemblies because of different versions and their compatibility.

If you can try following steps the issues most likely would be solved:

  1. Appium.net latest come out with dependency on DotNetSeleniumExtras.PageObjects v3.11.0 and WebDriver 3.141.0
  2. DotNetSeleniumExtras.Core of v3.12.0 (do not use latest, target v3.12.0) come out with dependency on WebDriver 3.12.0
  3. DotNetSeleniumExtras.PageObjects v3.11.0 rely on WebDriver 3.11.0
  4. So by adding WebDriver 3.12.0 version conflict should be fixed.

This one is a simplest approach - if previous version have enough features then It's done and you can just wait for updates.

The second option that can help you is a binding redirects. The idea is pretty simple, you need to ensure that app know where your WebDriver and it is of correct version.

One good explanation is here (but believe me this is the last thing you want to do, fixed in one place become broken in another) Adding a bindingRedirect to a .Net Standard library

Maksym
  • 820
  • 1
  • 8