Thoughts and Opinions on Page Object Model style? (I use C# . . I know . .)
I KNOW THIS IS A LONG POST. I would like to get overall feedback on the Page Object Model and maybe what you like/dislike about my example. Do you see any potential issues arising? Is there anything you've employed in your framework that might be different from the norm? Or just open discussion on POM and style.
So, I've been developing a "Base" framework that I like to use to just load up as a blank slate for any new project/task. I've also been working as an automation tester for at least 2 years now.
I have come up with a style for my Page Objects that the more junior members of the team have an easy time picking up. By the way, my Page Objects do not use the PageFactory.
My reasoning for this mainly stem from the need to use WebDriverWait at times. (Now in SeleniumExtras.WaitHelpers) And certain ExpectedConditions are only available for the By while some are only available for the IWebElement - or both!
With that said, I've noticed that when using the PageFactory, the FindsBy/FindsByAll attributes are for getting IWebElements, thus a By locator need not be declared or instantiated. Well, if I wanted to use an explicit wait using a By object - I would have to define a separate By object. So therein lies a slight maintenance issue, I now have 2 duplicated strings for the locator that slightly increases maintenance.
I also do not like the PageFactory style since the FindsBy style adds extra clutter/verbosity.
As an example of my Page Object style is attached as ToolsQA_PracticeForm.cs which is for the site http://toolsqa.com/automation-practice-form/
I have also included a couple Extension classes I utilize for Waits, etc. You can see in the attached file that I am using one of my Wait extensions on a By in the constructor.
Below (and attached) is an example of 3 Tests that complete the same task on the http://demoqa.com/ and http://demoqa.com/registration/ sites, respectively.
These Tests all utilize my POM format but in different syntax. Each one is actually showing a bit of progression on how I learned and taught myself Selenium.
The last test is showing my preferred style of scripting tests. Note the usage of a the static method "Initialize" - this method instantiates a Page Object allowing you to fluently script your steps (seen in my attached page object example).
I find this style a bit more appealing because you can clearly see the jumps (using the IDE's style/colors) to different Pages. My team enjoys this as well since it is pretty easy to follow along while attempting things manually or matching to a written test case.