I have a hard time to get used to the WebDriver PageObject pattern. Please share your experience and ways of using PageObjects pattern and loadableComponents.
As PageObject represents usually a component or piece of functionality, it occurred to me at first that I should use it to actually do some things in load() and see if it does what it should in isLoaded().
Then I realized that it should be utilized only for "loading" objects (possibly initialization) as it is in case of moving around a website, each object with its own url. And using isLoaded() to test whether the object IS READY for testing.
But if you have a complex JavaScript order submitter to test, that is compound of JS file uploader, JS form that is based on 2 independent parts and there are three kinds of Orders, you don't move anywhere (regarding URL), just the state of elements is changing.
Consider the get() method. You get into the page with the interactive Form. It is loaded when the form exist on the page. Then you have form1 and form2 objects ... what should their load() and isLoaded() method look like, they are ready for action right away because they don't need any loading, just testing their services.
It's a mess, one doesn't know if the isLoaded() method is used for checking whether object loaded, or whether object loaded and was setup properly. But I guess the former way is correct and that validity of setting it up should be ensured within the tests.
Scenario:
Testing first part of html form - test that field client side validation works
Testing the second one that depends on the first one
Testing the following file uploader - upload, canceling, clearing, order, fileIDs
Testing the overall html form submission - ServerSide validation errors, results
The documentation says :
- LoadableComponent
-
The public methods represent the services that the page offers
Validate, upload, upload Multiple, cancel, clear
Try not to expose the internals of the page
The only thing that occurs to me is having Driver instance hidden to UnitTests and use Only PageObjects to keep all field names, css class names in PageObjects + supply PageObjects with input data and assert boolean result of the services/functionality
Methods return other PageObjects
This is the most difficult thing to get used to. Having 4 page objects for one interactive form kinda doesn't feel natural. They recommend Form1, Form2(Form1), Upload(Form2), Submit(Upload), although I find the chaining and handing over a reference to the preceding object very chaotic. Calling get() on all of them in a test method seems better. But I guess that the idea behind it is not to expose the Driver instance to the Tests, but use only PageObjects that are using Driver instance internally
Different results for the same action are modelled as different methods I suppose that this means that it shouldn't be decided about validity of that action on the Page object side, but on the Test side