lisak
lisak

Reputation: 21981

How to use WebDriver / Selenium 2 LoadComponents in PageObjects pattern?

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 :

Upvotes: 5

Views: 3879

Answers (2)

Khyati Sehgal
Khyati Sehgal

Reputation: 385

The loadable component is an extension to the Page Object pattern. The LoadableComponent class in the WebDriver library will help test case developers make sure that the page or a component of teh page is loaded successfully. It tremendously reduces the efforts to debug your test cases. The page object should extend this Loadable Component abstract class and as a result, it is bound to provide implementation for the following two methods:

protected abstract void load()

protected abstract void isLoaded() throws java.lang.Error

The page or component that has to be loaded in the load() and isLoaded() methods determines whether or not the page is fully loaded. If it is not fully loaded, it throws an error.

https://code.google.com/p/selenium/wiki/LoadableComponent

Upvotes: 0

Rostislav Matl
Rostislav Matl

Reputation: 4543

I have a bit different approach when writing page objects. Translated to your terms load() method ends with conditional wait ensuring the page contains what you desire. Then I do not need any isLoaded() - either I'm there or Exception is thrown.

Components in page are properties of the page containing them and I set two-way relationship between a component and the page. They are not fully functional page objects. Maybe your forms can be modeled this way too.

Upvotes: 0

Related Questions