Skip to content

Commit 2cf7744

Browse files
author
lukec
committed
Add unit tests for functions no longer in Selenium-RC
git-svn-id: http://svn.openqa.org/svn/selenium-rc/trunk/clients/perl-cpan@1580 0891141a-5dea-0310-ad27-ebc607f31677
1 parent 1a334b3 commit 2cf7744

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

t/WWW/Selenium.pm

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package t::WWW::Selenium;
2+
use strict;
3+
use warnings;
4+
use Test::More;
5+
use Test::Exception;
6+
use base 'WWW::Selenium';
7+
8+
sub new {
9+
my $class = shift;
10+
my %opts = (
11+
host => 'localhost',
12+
port => 4444,
13+
browser => '*firefox',
14+
browser_url => 'http://example.com',
15+
@_,
16+
);
17+
my $self = $class->SUPER::new( %opts );
18+
19+
# Store mock www user agent and startup a session
20+
$self->{__ua} = LWP::UserAgent->new; # singleton
21+
$self->_set_mock_response_content('FAKE_SESSION_ID');
22+
$self->start;
23+
(my $enc_url = $opts{browser_url}) =~ s#://#%3A%2F%2F#; # simple
24+
is $self->{__ua}->{req}, "http://$opts{host}:$opts{port}/selenium-server/driver/"
25+
. "?cmd=getNewBrowserSession&1=$opts{browser}&2=$enc_url";
26+
27+
return $self;
28+
}
29+
30+
sub _set_mock_response_content {
31+
my ($self, $content) = @_;
32+
$self->{__ua}{res} = HTTP::Response->new(content => join(',', 'OK', $content));
33+
}
34+
35+
sub _method_exists {
36+
my ($self, $method, $return_type) = @_;
37+
my $response = 'Something';
38+
$response = 'true' if $method =~ m/^(?:is_|get_whether)/i;
39+
$self->_set_mock_response_content($response);
40+
lives_ok { $self->$method() } "$method lives";
41+
}
42+
1;

t/selenium-compat.t

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/perl
2+
use strict;
3+
use warnings;
4+
use Test::More qw/no_plan/;
5+
use t::Utils qw/method_exists/;
6+
use Test::Exception;
7+
8+
# The purpose of these tests are to ensure that WWW::Selenium does not
9+
# break backwards compatibility with previously released versions.
10+
11+
BEGIN {
12+
use lib 't/lib';
13+
use_ok 'LWP::UserAgent'; # mocked
14+
use_ok 'HTTP::Response'; # mocked
15+
use lib 'lib';
16+
use_ok 't::WWW::Selenium'; # subclass for testing
17+
}
18+
19+
my $sel = t::WWW::Selenium->new;
20+
isa_ok $sel, 't::WWW::Selenium';
21+
22+
Simple_check: {
23+
$sel->_method_exists("is_location");
24+
$sel->_method_exists("get_checked");
25+
$sel->_method_exists("is_selected");
26+
$sel->_method_exists("get_selected_options");
27+
}
28+
29+
Is_location: {
30+
True: {
31+
$sel->_set_mock_response_content('true');
32+
ok $sel->is_location('example.com');
33+
}
34+
35+
False: {
36+
$sel->_set_mock_response_content('false');
37+
ok !$sel->is_location('monkey.com');
38+
}
39+
}
40+
41+
Get_checked: {
42+
# XXX - Not sure what SeleniumServer actually returns here.
43+
True: {
44+
$sel->_set_mock_response_content('checked');
45+
is $sel->get_checked('id=foo'), 'checked';
46+
}
47+
48+
False: {
49+
$sel->_set_mock_response_content('unchecked');
50+
is $sel->get_checked('id=foo'), 'unchecked';
51+
}
52+
}

util/test_function.pl

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/perl
2+
use strict;
3+
use warnings;
4+
use lib 'lib';
5+
use WWW::Selenium;
6+
7+
my ($function, @args) = @ARGV;
8+
die 'no function' unless $function;
9+
10+
my $sel = WWW::Selenium->new(browser_url => 'http://www.csc.uvic.ca', browser => '*chrome');
11+
$sel->start;
12+
$sel->open('/~labspg/Reference/javascript/script4.4.html');
13+
my $content = $sel->get_body_text;
14+
die "No happy: ($content)" unless $content =~ /Happiness/;

0 commit comments

Comments
 (0)