I was wondering if anyone uses a design pattern where there is an object (similar to a page object) which has fields for each input in an HTML form.

I guess the fields would be nullable and then the page object would have a method FillOutForm() which takes in the form mapping object. It would fill out the form based on the object, and ignore any fields that are null.

Does that make any sense? Anyone else use a similar design pattern?


Yes, it makes sense. To quote Martin Fowler in http://martinfowler.com/bliki/PageObject.html,

Despite the term "page" object, these objects shouldn't usually be built for each page, but rather for the significant elements on a page. So a page showing multiple albums would have an album list page object containing several album page objects. There would probably also be a header page object and a footer page object. That said, some of the hierarchy of a complex UI is only there in order to structure the UI - such composite structures shouldn't be revealed by the page objects. The rule of thumb is to model the structure in the page that makes sense to the user of the application.

If you need to write automated UI tests, I recommend reading Fowler's article.

|improve this answer|||||
  • I guess I'm asking about a "mapping" object that stores the data you will pass into the page object to actually interact with HTML. The mapping object only stores info, it has nothing about entering it. Does that make sense? – GKS1 Aug 6 '15 at 18:36

I do. I use Python.

In page object, I use dictionary to map locator names to locator values. So even if locator value changes, its name stays same.

To fill the form, I create good old Dictionary, mapping locator names to values to be filled. Sometimes page fields needs to be filled in exact order, in that case I use Ordered Dictionary.

Base page (from which all pages inherit) have fill() method which gets dictionary (possibly ordered), replaces locator names to real locators which page defines, and locates widgets using these locators and fills them using provided values.

It was quite obvious, once I realized I need Ordered Dict, to keep form fields filled in required order. All was inspired Fowler's post on pageobject pattern linked in @user246 answer.

|improve this answer|||||
  • Cool! Not exactly what I meant but that is a nice idea. I was talking about a mapping object that contains the data you want to input, which you would pass in to the page object. – GKS1 Aug 7 '15 at 18:43
  • That is exactly that I do. But instead of mapping object, I use (ordered) dictionary because I don't need anything else beyond mapping, and it is easy to create as dict literal, which is trivial in Python and enough for most cases. – Peter M. - stands for Monica Aug 7 '15 at 19:31

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.