1

I was using for a long time PageFactory (in Java). Now writing tests in .NET I found out it's deprecated.

Right now I just initialize all page objects when application starts using [BeforeScenario] SpecFlow annotation.

So it looks like this:

[BeforeScenario]
public void Setup()
{
    // initialize driver and some other stuff code
    _session = new WebDriver();
    // initialize PageObjects
    MainView = new MainView(_session);
    OtherView = new OtherView(_session);
    // and so on...
}

It works fine, up to the moment where framework grows to hundreds of Page Objects. I feel that there should be better way to do that.

Can you provide here your solutions to handle a lot of PageObjects withouth PageFactory in .NET?

2

Here is the post where Jim Evans (the maintainer of C# Selenium binding) explains the issue you mentioned. In short:

Its only now that I have started to write Selenium tests in C# that I understand why the implementation was described as deeply flawed. The reason for dropping support now is due to it using proxies that have been deprecated from dotnet, but the reality is that they probably should never have existed in the first place. Let me explain…

When I was trying to get my defined rootElement PageBlocks working in Java I had problems at first with trying to instantiate the Page Objects when the Page was not displayed in the browser. You need to have lazy instantiation and as far as I am aware, you need the proxies as used in the Java PageFactory in order to do this. This is not however true in C# as properties allow you to define a call that is not made on instantiation. This is explained very clearly by Jim Evans in the issue where the deprecation of the .net proxies was raised. Whilst Liraz Shay was correct that this is more verbose, I totally understand that using complex proxies and reflection is an unjustifiable maintenance problem (and probably slower performing too.)

There you will also find the approach to use without PageFactory class.

  • >"Here is the post where Jim Evans" That post is not from Jim Evans, it's from some guy named Alexander quoting the release notes. >"There you will also find the approach to use" All I see is that 15 months after the initial post he's no closer to having a replacement for PageFactory. I'll keep searching... – Joel Aug 26 at 18:35
  • There is a link in OP (I refer to) leading to github.com/SeleniumHQ/selenium/issues/4387 where you can find some clue. There you can find the idea that Jim puts into those changes – Alexey R. Aug 26 at 18:55
  • Thanks Alexey, I had seen that thread previously and was trying to find it. If anyone's interested here's the original (I assume) post from Jim Evans: jimevansmusic.blogspot.com/2018/03/… – Joel Aug 26 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.