Hello, Jason.

The Programming Ruby 1.9 book, found at pragprog.com is great and has
a quite extensive chapter on classes and modules. I highly recommend
you to buy it (I can send you a 40% discount code if you want :)

I won't reproduce the entire chapter here, but the main difference is
that modules cannot be instantiated.

This FAQ [1] defines both as follows:

8.8 What is the difference between a class and a module?

Modules are collections of methods and constants. They cannot generate
instances. Classes may generate instances (objects), and have
per-instance state (instance variables).

Modules may be mixed in to classes and other modules. The mixed-in
module's constants and methods blend into that class's own, augmenting
the class's functionality. Classes, however, cannot be mixed in to
anything.

A class may inherit from another class, but not from a module.

A module may not inherit from anything.

--

So, applying these concepts to your framework, I would create modules
as helper "classes", providing commonly used methods like file
operations, logging, etc that are not part of the application
business.

Navigation functions should be placed in classes representing your
application pages, for example:

Class MainPage is instantiated with a @ie.attach(:title, /Home Page/)
object, should have a login(username, password) method and so on.

This might leave you with something like the Page Object Model [2],
which is a very interesting way to model your tests.

Was it helpful?

[1] http://www.rootr.net/rubyfaq-8.html
[2] http://code.google.com/p/selenium/wiki/PageObjects


On Tue, Jul 27, 2010 at 5:48 PM, Jason <freezingki...@gmail.com> wrote:
>
> Hey team,
>
> I might post a few discussions here over the coming days trying to
> better improve my framework, and to start I want to make sense of
> Modules and Classes.
>
> Previously I've just written a whole lot of methods, loaded every
> script and called each method as required, with little or no concept
> of placing these within Modules or Classes. it works fine, but surely
> I can do better.
>
> I just don't quite understand them and how to effectively use them
> well enough, so I'm wondering if anyone can point me in the direction
> of some good tutorials, or even better, some Watir-specific examples
> that use them well.
>
>
> Thanks,
>
> Jason
>
> --
> Before posting, please read http://watir.com/support. In short: search before 
> you ask, be nice.
>
> You received this message because you are subscribed to 
> http://groups.google.com/group/watir-general
> To post: watir-general@googlegroups.com
> To unsubscribe: watir-general+unsubscr...@googlegroups.com

-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

You received this message because you are subscribed to 
http://groups.google.com/group/watir-general
To post: watir-general@googlegroups.com
To unsubscribe: watir-general+unsubscr...@googlegroups.com

Reply via email to