2

I want to write page object for a page that has a dynamic section which toggles on button click. Since the view is not same, logically there are three sections, of which only one can be seen at a time.

<Div id=view1/> or
<Div id=view2/> or
<Div id=view3/>


MyPage < SitePrism::Page 
    [Other elements and sections]
    [Dynamic section or element]
End

I thought of programming the page object in several ways.

1) Create 3 page objects for each view it can handle. This is not scalable because number of view might increase. Also number of such dynamic section may increase total number of different page objexts exponentially. That is:

MyPage1 with section pointing to view1. Like wise for view 2 and 3.

2) have all sections possible in the same object. This works fine but the page object does not look intuitive.

MyPage < SitePrism::Page
    Section :view1, Section::View1, "#view1"
    Section :view2, Section::View2, "#view2"
    Section :view3, Section::View3, "#view3" 
End

3) define method that takes care of creating the section at runtime. This way my page does not have the section at load time but once thr page is loaded I call appropriate method that loads the section in the page. ( this is not implemented but I think it might work, although it would require as many methods in page object as number of such dynamic sections)

Sample:

MyPage < SitePrism::Page
    Def self.createView(type)
        If type == view1
            Section :view1, Section::View1, "#view1"
        Elsif type == view2
            (Like above for view 2)
        Else
            (Like above for view 3)
        End
    End
End

If you have come across similar problem, I would love to know if there is any other approach that can be taken, Or let me know if you foresee any problem with third approach.

3
  • That sounds like you have an accordion on your page that reveals different information depending on a button click (and users can switch between them). The best choice then (in my opinion) is #2, have a Section for each section. You may also want to add helper methods to trigger and verify that the correct section is open. Hopefully other engineers are aware of the page design but you can always use the naming or comments to clarify: Section :ShippingAccordion, Section :PricingAccordion, etc
    – tgf
    Apr 24, 2015 at 19:03
  • Thanks tmg for the comment ! My page makes ajax call to change the layout of a particular div. Only problem that I see with this approach is that If the page has multiple such views. In that case PageObject will be cluttered with unnecessary information. All that is changing in this particular case is the layout, not the information. Apr 27, 2015 at 9:45
  • Sorry I didn't reply back to this. It occurred to me that you might also be able to do something like this: stackoverflow.com/questions/32207659/… and dynamically add the section on to the page object when you need it. I think for your case though I'd still choose #2
    – tgf
    Aug 28, 2015 at 23:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.