Phil Lawrence on 28 Jul 2004 14:04:43 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Web page testing


Phil Lawrence wrote:

... references to Test::Builder, whose constructor returns singletons. I think this may help, but I'm not sure about implementation.

OK, I checked out how Andy Lester did it in Test::WWW::Mechanize, and went from there. Basically, it hinges on the builder() method of Test::More.


This works, but only exposes Test::Builder methods to my used modules. Subclassing Test::More correctly might yet expose it's functions to my used modules.

./t/test_driver.pl
------------------
#!/usr/local/bin/perl
use warnings;
use strict;
use diagnostics;

use lib './t';

use Test::More qw( no_plan );

BEGIN:
{
        # a subclass of Test::WWW::Mechanize (with @ISA, Dieter!)
        use_ok( 'T::Mechanize' );
        use_ok( 'T::GoToApp' );
}
# get Test::Builder object that underlies Test::More
my $Test = Test::More->builder;

my $mech = T::Mechanize->new( autocheck => 1 );
isa_ok( $mech, 'T::Mechanize', 'Get T::Mechanize object' );

# here we use the functionality (and tests) I
# split out into another file
T::GoToApp::test( $mech, $Test );

ok( defined $mech->find_link(text => 'EXIT'), 'Find EXIT link' ),
$mech->follow_link( text => 'EXIT' );
$mech->title_is( 'User Logout', 'Exit/Logout' );
------------------

./t/T/GoToApp.pm
------------------
package T::GoToApp;

sub test
{
  my $mech = shift;
  my $Test = shift;

  $mech->get( 'https://foo.com:999/' );
  $Test->ok( defined $mech->find_link(
                       text=>'Enter Secure Area'
                                     )
           , 'Find Login link'
           );

  $mech->follow_link( text => 'Enter Secure Area' );
  $mech->title_is( 'User Login', 'Get Login Page' );

  $mech->submit_form
  (
    form_name   => 'loginform',
    fields      =>
                   {
                     sid      => '999999999',
                     PIN      => '999999999',
                   }
  );
  $Test->ok( $mech->title eq 'Main Menu', 'Login' );
  $Test->ok( defined $mech->find_link(
                       text=>'Personal Information'
                                     )
           , 'Find Personal Information link'
           );

  $mech->follow_link( text => 'Personal Information' );
  $mech->title_is( 'Personal Information'
                 , 'Get Personal Information page'
                 );
  $Test->ok( defined $mech->find_link(
                       text=>'International Travel Registration'
                                     )
           , 'Find International Travel Registration link'
           );

  $mech->follow_link( text=>'International Travel Registration' );
  $mech->title_is( 'International Travel Registration'
                 , 'Get International Travel Registration page'
                 );
}

1;
------------------
-
**Majordomo list services provided by PANIX <URL:http://www.panix.com>**
**To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**