Weasel

Logo

Perl web-app testing with PageObjects

View My GitHub Profile

Web-app testing in Perl

Bridging DOM and Page Objects

Weasel is a library to automate web application tests using Perl, much like Watir for Ruby and Mink for PHP.

Like Mink, it abstracts away differences between browser emulators and browser drivers. Unlike any other web testing library, it bridges the gap between page elements (DOM elements) as returned by the web drivers and page objects used in tests.

Weasel integrates with Perl’s BDD testing framework (‘pherkin’) through its pherkin-extension-weasel extension.

Weasel features an extensible architecture. There are currently two driver plugins to connect to a web app: the first wraps the “regular” Selenium::Remote::Driver module Weasel::Driver::Selenium2, the second implements a driver specific for development of Weasel itself and its plugins Weasel::Driver::Mock.

PageObjects

Page objects are a way to reduce the dependency between the exact layout of your pages and the implementation of your tests. Webapp testing drivers return DOM elements, but tests want page objects to access the page’s services.

Improving the PageObjects pattern

There are a number of issues with the standard pattern that Weasel solves:

Example code:

package PageObject::App::Login;

use Moo;
extends 'Weasel::Element';

sub login {
    my ($self, $user, $passwd) = @_;

    $self->find('*labeled', text => 'User')->send_keys($user);
    $self->find('*labeled', text => 'Password')->send_keys($passwd);
    $self->find('*button', text => 'Login')->click;
    
    return $self;
};

1;

The architecture page describes how Weasel improves on the generic ideas of PageObjects by providing even better encapsulation and abstraction.

Single-Page Applications

The fact that Weasel doesn’t require a PageObject to model an entire page and encourages multiple PageObjects on a single page (in a nested hierarchy), Weasel is very well suited to model interaction with single-page web applications.

Using Weasel without page objects

Although the biggest benefit in Weasel obviously is its support for the PageObject pattern, there’s no requirement to use its web driver abstraction and CSS/XPath alias support with PageObjects.

Community resources