r28260 - in /branches/upstream/libtest-www-selenium-perl/current: Changes lib/Test/WWW/Selenium.pm lib/WWW/Selenium.pm t/WWW/Selenium.pm t/selenium-compat.t t/selenium-dwim.t t/selenium-rc.t t/test-selenium.t
bricas-guest at users.alioth.debian.org
bricas-guest at users.alioth.debian.org
Mon Dec 15 18:20:58 UTC 2008
Author: bricas-guest
Date: Mon Dec 15 18:20:55 2008
New Revision: 28260
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=28260
Log:
[svn-upgrade] Integrating new upstream version, libtest-www-selenium-perl (1.16)
Modified:
branches/upstream/libtest-www-selenium-perl/current/Changes
branches/upstream/libtest-www-selenium-perl/current/lib/Test/WWW/Selenium.pm
branches/upstream/libtest-www-selenium-perl/current/lib/WWW/Selenium.pm
branches/upstream/libtest-www-selenium-perl/current/t/WWW/Selenium.pm
branches/upstream/libtest-www-selenium-perl/current/t/selenium-compat.t
branches/upstream/libtest-www-selenium-perl/current/t/selenium-dwim.t
branches/upstream/libtest-www-selenium-perl/current/t/selenium-rc.t
branches/upstream/libtest-www-selenium-perl/current/t/test-selenium.t
Modified: branches/upstream/libtest-www-selenium-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-www-selenium-perl/current/Changes?rev=28260&op=diff
==============================================================================
--- branches/upstream/libtest-www-selenium-perl/current/Changes (original)
+++ branches/upstream/libtest-www-selenium-perl/current/Changes Mon Dec 15 18:20:55 2008
@@ -1,4 +1,9 @@
Revision history for Perl extension Test::WWW::Selenium.
+
+1.16 - Sun 14 Dec 2008 15:28:38 PST
+ - use POST instead of GET to selenium server (gyrm)
+ - add support for per-session javascript (gyrm)
+ - add unit tests and docs for re-using session_ids
1.15 - Sun 23 Mar 2008 14:02:25 PDT
- allow set_timeout() to be called before open()
Modified: branches/upstream/libtest-www-selenium-perl/current/lib/Test/WWW/Selenium.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-www-selenium-perl/current/lib/Test/WWW/Selenium.pm?rev=28260&op=diff
==============================================================================
--- branches/upstream/libtest-www-selenium-perl/current/lib/Test/WWW/Selenium.pm (original)
+++ branches/upstream/libtest-www-selenium-perl/current/lib/Test/WWW/Selenium.pm Mon Dec 15 18:20:55 2008
@@ -4,7 +4,7 @@
use base qw(WWW::Selenium);
use Carp qw(croak);
-our $VERSION = '1.15';
+our $VERSION = '1.16';
=head1 NAME
Modified: branches/upstream/libtest-www-selenium-perl/current/lib/WWW/Selenium.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-www-selenium-perl/current/lib/WWW/Selenium.pm?rev=28260&op=diff
==============================================================================
--- branches/upstream/libtest-www-selenium-perl/current/lib/WWW/Selenium.pm (original)
+++ branches/upstream/libtest-www-selenium-perl/current/lib/WWW/Selenium.pm Mon Dec 15 18:20:55 2008
@@ -16,6 +16,7 @@
package WWW::Selenium;
use LWP::UserAgent;
+use HTTP::Headers;
use HTTP::Request;
use URI::Escape;
use Carp qw(croak);
@@ -373,30 +374,43 @@
Defaults to true, and will attempt to close the browser if the object
goes out of scope and stop hasn't been called.
+=item * C<session_id>
+
+Optional argument that can be used to reuse session_ids between test
+runs. This can make for faster testing.
+
=back
=cut
sub new {
my ($class, %args) = @_;
- my $self = { # default args:
- host => 'localhost',
- port => 4444,
- auto_stop => 1,
- browser_start_command => delete $args{browser} || '*firefox',
- %args,
- };
+ my $self = { # default args:
+ host => 'localhost',
+ port => 4444,
+ auto_stop => 1,
+ browser_start_command => delete $args{browser} || '*firefox',
+ extension_js => "",
+ session_id => undef,
+ %args,
+ };
croak 'browser_url is mandatory!' unless $self->{browser_url};
bless $self, $class or die "Can't bless $class: $!";
return $self;
}
+sub set_extension_js {
+ my $self = shift;
+ $self->{extension_js} = shift;
+}
+
sub start {
my $self = shift;
return if $self->{session_id};
$self->{session_id} = $self->get_string("getNewBrowserSession",
$self->{browser_start_command},
- $self->{browser_url});
+ $self->{browser_url},
+ $self->{extension_js});
}
sub stop {
@@ -422,23 +436,24 @@
}
$command = uri_escape($command);
- my $fullurl = "http://$self->{host}:$self->{port}/selenium-server/driver/"
- . "\?cmd=$command";
+ my $fullurl = "http://$self->{host}:$self->{port}/selenium-server/driver/";
+ my $content = "cmd=$command";
my $i = 1;
@args = grep defined, @args;
while (@args) {
- $fullurl .= "&$i=" . URI::Escape::uri_escape_utf8(shift @args);
+ $content .= "&$i=" . URI::Escape::uri_escape_utf8(shift @args);
$i++;
}
if (defined $self->{session_id}) {
- $fullurl .= "&sessionId=$self->{session_id}";
+ $content .= "&sessionId=$self->{session_id}";
}
print "---> Requesting $fullurl\n" if $self->{verbose};
# We use the full version of LWP to make sure we issue an
# HTTP 1.1 request (SRC-25)
my $ua = LWP::UserAgent->new;
- my $response = $ua->request( HTTP::Request->new(GET => $fullurl) );
+ my $header = HTTP::Headers->new( Content_Type => 'application/x-www-form-urlencoded; charset=utf-8' );
+ my $response = $ua->request( HTTP::Request->new( 'POST', $fullurl, $header, $content ) );
my $result;
if ($response->is_success) {
$result = $response->content;
Modified: branches/upstream/libtest-www-selenium-perl/current/t/WWW/Selenium.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-www-selenium-perl/current/t/WWW/Selenium.pm?rev=28260&op=diff
==============================================================================
--- branches/upstream/libtest-www-selenium-perl/current/t/WWW/Selenium.pm (original)
+++ branches/upstream/libtest-www-selenium-perl/current/t/WWW/Selenium.pm Mon Dec 15 18:20:55 2008
@@ -21,10 +21,14 @@
# Store mock www user agent and startup a session
$self->_set_mock_response_content('FAKE_SESSION_ID');
$self->start;
- (my $enc_url = $opts{browser_url}) =~ s#://#%3A%2F%2F#; # simple
- my $url = "http://$opts{host}:$opts{port}/selenium-server/driver/"
- . "?cmd=getNewBrowserSession&1=$opts{browser}&2=$enc_url";
- is_deeply $Mock_req->new_args, [ 'HTTP::Request', 'GET', $url ];
+
+ # Test that the session was started as we expect
+ my $req_args = $Mock_req->new_args;
+ my $content = pop @$req_args;
+ is $content, 'cmd=getNewBrowserSession&1=*firefox&2=http%3A%2F%2Fexample.com&3=';
+ my $headers = pop @$req_args;
+ my $url = "http://$opts{host}:$opts{port}/selenium-server/driver/";
+ is_deeply $req_args, [ 'HTTP::Request', 'POST', $url ];
return $self;
}
Modified: branches/upstream/libtest-www-selenium-perl/current/t/selenium-compat.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-www-selenium-perl/current/t/selenium-compat.t?rev=28260&op=diff
==============================================================================
--- branches/upstream/libtest-www-selenium-perl/current/t/selenium-compat.t (original)
+++ branches/upstream/libtest-www-selenium-perl/current/t/selenium-compat.t Mon Dec 15 18:20:55 2008
@@ -1,7 +1,7 @@
#!/usr/bin/perl
use strict;
use warnings;
-use Test::More tests => 25;
+use Test::More tests => 26;
use Test::Exception;
# The purpose of these tests are to ensure that WWW::Selenium does not
Modified: branches/upstream/libtest-www-selenium-perl/current/t/selenium-dwim.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-www-selenium-perl/current/t/selenium-dwim.t?rev=28260&op=diff
==============================================================================
--- branches/upstream/libtest-www-selenium-perl/current/t/selenium-dwim.t (original)
+++ branches/upstream/libtest-www-selenium-perl/current/t/selenium-dwim.t Mon Dec 15 18:20:55 2008
@@ -1,7 +1,7 @@
#!/usr/bin/perl
use strict;
use warnings;
-use Test::More tests => 16;
+use Test::More tests => 23;
use Test::Exception;
use Test::Mock::LWP;
@@ -21,7 +21,7 @@
Open_default: {
my $sel = t::WWW::Selenium->new;
lives_ok { $sel->open };
- like $Mock_req->new_args->[2], qr/\Q1=%2F\E/, 'open specified /';
+ like $Mock_req->new_args->[4], qr/\Qcmd=open&1=%2F\E/, 'open specified /';
}
Double_start: {
@@ -36,7 +36,7 @@
$sel->_set_mock_response_content('http://example.com');
$sel->get_location;
$sel = undef;
- like $Mock_req->new_args->[2], qr/cmd=testComplete/, 'auto-stop';
+ like $Mock_req->new_args->[4], qr/cmd=testComplete/, 'auto-stop';
}
Auto_stop_off: {
@@ -45,7 +45,7 @@
$sel->_set_mock_response_content('http://example.com');
$sel->get_location;
$sel = undef;
- unlike $Mock_req->new_args->[2], qr/cmd=testComplete/, 'not auto-stop';
+ unlike $Mock_req->new_args->[4], qr/cmd=testComplete/, 'not auto-stop';
}
Do_command_open: {
Modified: branches/upstream/libtest-www-selenium-perl/current/t/selenium-rc.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-www-selenium-perl/current/t/selenium-rc.t?rev=28260&op=diff
==============================================================================
--- branches/upstream/libtest-www-selenium-perl/current/t/selenium-rc.t (original)
+++ branches/upstream/libtest-www-selenium-perl/current/t/selenium-rc.t Mon Dec 15 18:20:55 2008
@@ -1,13 +1,14 @@
#!/usr/bin/perl
use strict;
use warnings;
-use Test::More tests => 28;
+use Test::More tests => 50;
use Test::Exception;
use Test::Mock::LWP;
BEGIN {
use lib 'lib';
use_ok 'WWW::Selenium';
+ use_ok 'Test::WWW::Selenium';
}
Good_usage: {
@@ -26,9 +27,8 @@
Start_up_selenium: {
$Mock_resp->mock( content => sub {'OK,SESSION_ID'} );
$sel->start;
- my $url = 'http://localhost:4444/selenium-server/driver/?'
- . 'cmd=getNewBrowserSession&1=*firefox&2=http%3A%2F%2Ffoo.com';
- is_deeply $Mock_req->new_args, [ 'HTTP::Request', 'GET', $url ];
+ is $sel->{session_id}, 'SESSION_ID';
+ req_ok('cmd=getNewBrowserSession&1=*firefox&2=http%3A%2F%2Ffoo.com&3=');
$Mock_resp->mock( content => sub { 'OK' } );
$sel->open;
}
@@ -36,18 +36,14 @@
Execute_command: {
$Mock_resp->mock( content => sub { 'OK,Some Title' } );
is $sel->get_title, 'Some Title';
- my $url = 'http://localhost:4444/selenium-server/driver/?cmd=getTitle'
- . '&sessionId=SESSION_ID';
- is_deeply $Mock_req->new_args, ['HTTP::Request', 'GET', $url];
+ req_ok('cmd=getTitle&sessionId=SESSION_ID');
}
Close_down_selenium: {
$Mock_resp->mock( content => sub { 'OK' } );
$sel->stop;
is $sel->{session_id}, undef;
- my $url = 'http://localhost:4444/selenium-server/driver/?'
- . 'cmd=testComplete&sessionId=SESSION_ID';
- is_deeply $Mock_req->new_args, ['HTTP::Request', 'GET', $url];
+ req_ok('cmd=testComplete&sessionId=SESSION_ID');
}
}
@@ -118,12 +114,40 @@
my $sel = WWW::Selenium->new( browser_url => 'http://foo.com' );
$Mock_resp->mock( content => sub { 'OK,SESSION_ID' } );
$sel->start;
+ is $sel->{session_id}, 'SESSION_ID';
$Mock_resp->mock( content => sub { 'OK' } );
$sel->stop;
is $sel->{session_id}, undef;
- my $url = 'http://localhost:4444/selenium-server/driver/'
- . '?cmd=testComplete&sessionId=SESSION_ID';
- is_deeply $Mock_req->new_args, [ 'HTTP::Request', 'GET', $url ];
+ req_ok('cmd=testComplete&sessionId=SESSION_ID');
$sel->stop;
is_deeply $Mock_req->new_args, undef;
}
+
+With_session_id: {
+ my $sel = Test::WWW::Selenium->new(
+ browser_url => 'http://foo.com',
+ session_id => 'MY_ID',
+ );
+ $Mock_resp->mock( content => sub { die "Should never be called!" } );
+ $sel->start;
+ is $sel->{session_id}, 'MY_ID';
+ $Mock_resp->mock( content => sub { 'OK' } );
+ $sel->stop;
+ is $sel->{session_id}, undef;
+ req_ok('cmd=testComplete&sessionId=MY_ID');
+ $sel->stop;
+ is_deeply $Mock_req->new_args, undef;
+}
+
+exit;
+
+
+sub req_ok {
+ my $content = shift;
+ my $args = $Mock_req->new_args;
+ is $args->[0], 'HTTP::Request';
+ is $args->[1], 'POST';
+ is $args->[2], 'http://localhost:4444/selenium-server/driver/';
+ is $args->[4], $content;
+}
+
Modified: branches/upstream/libtest-www-selenium-perl/current/t/test-selenium.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-www-selenium-perl/current/t/test-selenium.t?rev=28260&op=diff
==============================================================================
--- branches/upstream/libtest-www-selenium-perl/current/t/test-selenium.t (original)
+++ branches/upstream/libtest-www-selenium-perl/current/t/test-selenium.t Mon Dec 15 18:20:55 2008
@@ -4,7 +4,7 @@
use Test::More;
use Test::Exception;
use Test::Mock::LWP;
-use Test::Builder::Tester tests => 42;
+use Test::Builder::Tester tests => 48;
Test::Builder::Tester::color(1);
BEGIN {
@@ -27,19 +27,13 @@
test_out("ok 1 - get_title, 'Some Title'");
$sel->title_is('Some Title');
test_test('title_is passes');
- my $url = 'http://localhost:4444/selenium-server/driver/'
- . '?cmd=getTitle&sessionId=SESSION_ID';
- is_deeply $Mock_req->new_args, [ 'HTTP::Request', 'GET', $url ],
- 'correct page title url';
+ req_ok('cmd=getTitle&sessionId=SESSION_ID');
}
Browser_gets_closed: {
$Mock_resp->mock('content' => sub { 'OK' });
$sel = undef;
- my $url = 'http://localhost:4444/selenium-server/driver/'
- . '?cmd=testComplete&sessionId=SESSION_ID';
- is_deeply $Mock_req->new_args, [ 'HTTP::Request', 'GET', $url ],
- 'testComplete request sent on DESTROY';
+ req_ok('cmd=testComplete&sessionId=SESSION_ID');
}
}
@@ -228,3 +222,16 @@
test_test('default names on with test name');
}
}
+
+exit;
+
+
+sub req_ok {
+ my $content = shift;
+ my $args = $Mock_req->new_args;
+ is $args->[0], 'HTTP::Request';
+ is $args->[1], 'POST';
+ is $args->[2], 'http://localhost:4444/selenium-server/driver/';
+ is $args->[4], $content;
+}
+
More information about the Pkg-perl-cvs-commits
mailing list