test through webdriver

agranig/1_0_subfix
Lars Dieckow 12 years ago
parent da8f7b9ba0
commit 3c2946026d

@ -0,0 +1,111 @@
use lib 'inc';
use Local::Module::Build qw();
my $builder = Local::Module::Build->new(
module_name => 'NGCP::Panel',
license => 'restrictive',
dist_version_from => 'lib/NGCP/Panel.pm',
configure_requires => {
'lib' => 0,
'Module::Build' => '0.4004',
'Moose' => 2,
'Sipwise::Base' => 0,
},
requires => {
'base' => 0,
'Catalyst::Plugin::ConfigLoader' => 0,
'Catalyst::Plugin::Static::Simple' => 0,
'Catalyst::Plugin::Authentication' => 0,
'Catalyst::Plugin::Authorization::Roles' => 0,
'Catalyst::Plugin::Session' => 0,
'Catalyst::Plugin::Session::Store::FastMmap' => 0,
'Catalyst::Plugin::Session::State::Cookie' => 0,
'Catalyst::Runtime' => '5.90014',
'Catalyst::View::JSON' => 0,
'Catalyst::View::TT' => 0,
'HTML::FormHandler' => 0,
'HTML::FormHandler::Field' => 0,
'HTML::FormHandler::Field::Compound' => 0,
'HTML::FormHandler::Field::Select' => 0,
'HTML::FormHandler::Moose' => 0,
'HTML::FormHandler::Widget::Block::Bootstrap' => 0,
'Log::Log4perl::Catalyst' => 0,
'Moose' => 2,
'Moose::Role' => 0,
'Moose::Util::TypeConstraints' => 0,
'MooseX::Object::Pluggable' => 0,
'namespace::autoclean' => 0,
'strict' => 0,
'Template' => 0,
'warnings' => 0,
},
test_requires => {
'Catalyst::Test' => 0,
'File::Which' => 0,
'Getopt::Long' => 0,
'IO::Socket::IP' => 0,
'JSON' => 0,
'JSON::Parse' => 0,
'lib' => 0,
'Plack::Runner' => 0,
# actually, the `plackup` external bin. this will break if the Plack distro is split into pieces
'Sipwise::Base' => 0,
'Test::More' => 0,
'Test::WebDriver' => 0,
'strict' => 0,
'Sys::Sig' => 0,
'URI' => 0,
'warnings' => 0,
},
recommends => {
# for the testcover target
'Devel::Cover' => 0,
'sigtrap' => 0,
},
add_to_cleanup => [ 'NGCP-Panel-*' ],
);
$builder->create_build_script;
__END__
=encoding UTF-8
=head1 NAME
Build.PL - NGCP-Panel build system including test fixtures
=head1 SYNOPSIS
perl ./Build
./Build test --webdriver='phantomjs --webdriver=4444'
./Build test --webdriver='java -jar selenium-server-standalone.jar'
./Build test --webdriver='chromedriver --port=4444'
./Build test --webdriver=selenium-rc # from CPAN distro Alien-SeleniumRC
./Build testcover --webdriver='phantomjs --webdriver=4444'
=head2 Options
--webdriver (required) external webdriver command
--server URI for socket test server
--help brief help message
--man full documentation
=head1 OPTIONS
=head2 C<--webdriver>
(required) command to launch a webdriver
=head2 C<--server>
URI for the HTTP::Server::PSGI socket server run for testing,
default C<http://localhost:5000>
=head2 C<--help>
Print a brief help message and exits.
=head2 C<--man>
Prints the manual page and exits.

@ -1,27 +0,0 @@
#!/usr/bin/env perl
# IMPORTANT: if you delete this file your app will not work as
# expected. You have been warned.
use inc::Module::Install 1.02;
use Module::Install::Catalyst; # Complain loudly if you don't have
# Catalyst::Devel installed or haven't said
# 'make dist' to create a standalone tarball.
name 'NGCP-Panel';
all_from 'lib/NGCP/Panel.pm';
requires 'Catalyst::Runtime' => '5.90014';
requires 'Catalyst::Plugin::ConfigLoader';
requires 'Catalyst::Plugin::Static::Simple';
requires 'Catalyst::Action::RenderView';
requires 'Moose';
requires 'namespace::autoclean';
requires 'Config::General'; # This should reflect the config file format you've chosen
requires 'Catalyst::Helper::View::JSON';
# See Catalyst::Plugin::ConfigLoader for supported formats
requires 'Log::Log4perl::Catalyst';
test_requires 'Test::More' => '0.88';
catalyst;
install_script glob('script/*.pl');
auto_install;
WriteAll;

@ -0,0 +1,95 @@
package Local::Module::Build;
use Sipwise::Base;
use Moose qw(around);
extends 'Module::Build';
our ($plackup, $webdriver, @cover_opt);
method wait_socket($host, $port) {
require IO::Socket::IP;
my $timer = 0;
while (1) {
my $sock = IO::Socket::IP->new(
PeerHost => $host,
PeerPort => $port,
Type => IO::Socket::IP::SOCK_STREAM(),
);
last if $sock;
sleep 1;
$timer++;
die sprintf('socket %s:%s is not accessible within 30 seconds after start', $host, $port)
if $timer > 30;
};
}
sub shutdown_servers {
for my $proc ($webdriver, $plackup) {
if ($proc) {
require Sys::Sig;
$proc->kill(Sys::Sig->TERM);
}
}
}
around('ACTION_test', sub {
my $super = shift;
my $self = shift;
require Getopt::Long;
my %opt = (server => 'http://localhost:5000');
Getopt::Long::GetOptions(\%opt, 'webdriver=s', 'server:s', 'help|?', 'man')
or die 'could not process command-line options';
require Pod::Usage;
Pod::Usage::pod2usage(-exitval => 1, -input => 'Build.PL') if $opt{help};
Pod::Usage::pod2usage(-exitval => 0, -input => 'Build.PL', -verbose => 2) if $opt{man};
Pod::Usage::pod2usage("$0: --webdriver option required.\nRun `perldoc Build.PL`") unless $opt{webdriver};
$webdriver = child { exec $opt{webdriver} };
$self->wait_socket(qw(localhost 4444));
require URI;
my $uri = URI->new($opt{server});
require File::Which;
$plackup = child {
exec $^X,
'-Ilib',
@cover_opt,
File::Which::which('plackup'),
sprintf('--listen=%s:%s', $uri->host, $uri->port),
'ngcp_panel.psgi';
};
$self->wait_socket($uri->host, $uri->port);
$ENV{CATALYST_SERVER} = $opt{server};
try {
$self->$super(@_);
};
});
method ACTION_testcover {
{
my @missing;
for my $module (qw(Devel::Cover sigtrap)) {
push @missing, $module
unless Module::Build::ModuleInfo->find_module_by_name($module);
}
if (@missing) {
warn "modules required for testcover action: @missing\n";
return;
}
}
$self->add_to_cleanup('coverage', 'cover_db');
$self->depends_on('code');
$self->do_system(qw(cover -delete));
@cover_opt = (
'-Msigtrap "handler", sub { exit }, "normal-signals"',
'-MDevel::Cover=+ignore,ngcp_panel.psgi,+ignore,plackup',
);
$self->depends_on('test');
shutdown_servers;
sleep 5;
$self->do_system(qw(cover));
}
END { shutdown_servers }

@ -0,0 +1,17 @@
use Sipwise::Base;
use lib 't/lib';
use Test::More import => [qw(done_testing is)];
use Test::WebDriver::Sipwise qw();
my $d = Test::WebDriver::Sipwise->new;
$d->get($ENV{CATALYST_SERVER});
$d->find(link_text => 'Admin')->click;
$d->find(name => 'username')->send_keys('administrator');
$d->find(name => 'password')->send_keys('administrator');
$d->find(name => 'submit')->click;
is($d->get_text('//title'), 'Dashboard');
done_testing;

@ -0,0 +1,7 @@
package Test::WebDriver::Sipwise;
use Sipwise::Base;
extends 'Test::WebDriver';
method find(Str $scheme, Str $query) {
$self->find_element($query, $scheme);
}
Loading…
Cancel
Save