Frage

I'm implementing a project where I'm testing my UI. So, each part of my UI is a separate class(Seleniums page object pattern). Now, since it's just a single web page I'm testing, according to me, theres just gotta be one instance of my UI components, while they do change state, I don't see the benefits of multiple instance of these components floating around.

So, I'm tempted to make all of them singletons, is that a bad practice?

For example -

|-------------------------------------------------------------|
|                                                                            |
|                                                                            |
|-------------------------------------------------------------|
|                                      |                                     |
|                                      |                                     |
|                                      |                                     |
|                                      |                                     |
|                                      |                                     |
|                                      |                                     |
|                                      |                                     |
|                                      |                                     |
|                                      |                                     |
|                                      |                                     |
|                                      |                                     |
|                                      |                                     |
|-------------------------------------------------------------|

All of these sections will stay on my page throughout the users session, but they may change state, like toggle, resize, change the data within them, etc.

Any thoughts?

War es hilfreich?

Lösung

One of the ideas implemented by the page object gem (via Ruby) is to encapsulate the instantiation of your page classes using a page factory type of object. In particular, this is the 'on_page' method, the usage is like

on_page(MyPageClass) do |page|
  page.do_actions
end

Where the block provided should have a single argument to which the instance created in the factory is passed to.

Perhaps you can employ a similar idea. It's better to have instances of page classes in my opinion; my reasoning is that your page class actions should be 'memoryless'.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top