PageFactory Deprecated in Java or only C#? What Framework to use?

755 views
Skip to first unread message

PopVerifyPete

unread,
Jan 20, 2021, 1:49:38 AM1/20/21
to Selenium Users
I've been learning C# (Nunit) enough to create (what I believe to be is) a pretty good framework and now I'm starting to learn Java TestNG using Java in Eclipse.   Is PageFactory deprecated for Java or only in C#?  What method/model should I be looing into to learn elements using Java?  Any links to where I can see examples?

I did various model in C#. One that I like uses a Json file as a repository for all the page/elements.  I created a single user defined "EnterField" method that does actions on the elements no matter what class of an object it is (button, text, list, link...).  Any thoughts on this - good? bad? just ok? Thinking to use this in my Selenium Java but if there is a better one I'll go for that.

Thanks in advance!

PVP

PopVerifyPete

unread,
Jan 26, 2021, 3:01:20 PM1/26/21
to Selenium Users
bump

⇜Krishnan Mahadevan⇝

unread,
Jan 27, 2021, 2:03:09 AM1/27/21
to Selenium Users
Sometime back I spent time building a couple of things that provide the concept of Page Objects but without using PageFactory. 

This library abstracts out the page objects and lets you define them as JSON files.


This maven code generator takes in JSON files (generated by SimpleSe) and then spurts out actual PageObject java classes which can be used to interact with web pages without having to write code for the page objects.

Sometime back Vimal completed the eco system by building a chrome plugin that makes the process of creating the JSON files (which SimpleSe needs) easier by letting you point and click at elements on the web page and building the json file.

If you combine all these 3 things together you should be able to work with Page Objects as a concept.

which lets you express browser management (create browser and clean browser for both local and remote executions via an annotation) on your tests via custom annotations.

Hope this should help you get started.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/0bd70b98-20ea-428b-80db-ccd21c16f197n%40googlegroups.com.

David

unread,
Jan 30, 2021, 4:19:33 PM1/30/21
to Selenium Users
I like the concept of storing elements identifiers/locators outside of code, to be referenced by the page object etc. It's a design choice you can certainly make. I would consider whether you might want to use YAML as another alternative to JSON. I like YAML in that it's more compact than JSON and also supports comments.

You page object then can be all the page methods/actions only with utility method to import the locator definitions into actual objects on page instantiation if you went that route.

I like your EnterField method design. It provides abstractions to the user, but I may use something like that more as a utility method or internal private method for the framework developer. Following page object modeling and abstracted design, you want methods more like these for a page object:

SelectListItem(int index)
SelectListItem(string itemName)
SelectProductColor(string colorName)
SelectProductSize(SizeEnumType size) //where enum values SMALL, MEDIUM, LARGE, etc.

these in turn call lower level utility methods like EnterField and others to perform the appropriate action. The test writer only needs to know & think about high level aspects of the test scenario to implement w/o worrying about low level details about the actual element locators & how to work with them, only maybe just how to identify the page elements locators if need be.

But note that taking this strategy to the max benefit sometimes requires use of XPath, since CSS selectors and locating by name, ID, class, do not provide you the granularity to locate an item specifically by a particular index or text string (i.e. color name, item name, product size) anchored to some easier to find base parent element. If you forgo XPath in such cases, then you loose the ability to abstractly on higher level handle an element by specific string or index that a user normally would expect.


On Tuesday, January 19, 2021 at 10:49:38 PM UTC-8 PopVerifyPete wrote:
Reply all
Reply to author
Forward
0 new messages