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.