Browse Source

Cleanup trailing whitespace in a few places

Daniel Gempesaw 11 years ago
parent
commit
6bbdf3fbb5

+ 2 - 2
lib/Selenium/Remote/Driver.pm

@@ -541,14 +541,14 @@ sub _request_new_session {
     $self->remote_conn->check_status();
     # command => 'newSession' to fool the tests of commands implemented
     # TODO: rewrite the testing better, this is so fragile.
-    my $resource_new_session = { 
+    my $resource_new_session = {
         method => $self->commands->get_method('newSession'),
         url => $self->commands->get_url('newSession'),
         no_content_success => $self->commands->get_no_content_success('newSession'),
     };
     my $rc = $self->remote_conn;
     my $resp = $rc->request(
-        $resource_new_session, 
+        $resource_new_session,
         $args,
     );
     if ( ( defined $resp->{'sessionId'} ) && $resp->{'sessionId'} ne '' ) {

+ 10 - 10
lib/Selenium/Remote/Mock/Commands.pm

@@ -1,14 +1,14 @@
-package Selenium::Remote::Mock::Commands; 
+package Selenium::Remote::Mock::Commands;
 
-# ABSTRACT: utility class to mock Selenium::Remote::Commands 
+# ABSTRACT: utility class to mock Selenium::Remote::Commands
 #
-use Moo; 
+use Moo;
 extends 'Selenium::Remote::Commands';
 
 
 # override get_params so we do not rewrite the parameters
 
-sub get_params { 
+sub get_params {
     my $self = shift;
     my $args = shift;
     my $data = {};
@@ -17,17 +17,17 @@ sub get_params {
     $data->{'method'} = $self->get_method($command);
     $data->{'no_content_success'} = $self->get_no_content_success($command);
     $data->{'url_params'}  = $args;
-    return $data; 
+    return $data;
 }
 
-sub get_method_name_from_parameters { 
-    my $self = shift; 
+sub get_method_name_from_parameters {
+    my $self = shift;
     my $params = shift;
     my $method_name = '';
     my $cmds = $self->get_cmds();
-    foreach my $cmd (keys %{$cmds}) { 
-        if (($cmds->{$cmd}->{method} eq $params->{method}) && ($cmds->{$cmd}->{url} eq $params->{url})) { 
-            $method_name = $cmd; 
+    foreach my $cmd (keys %{$cmds}) {
+        if (($cmds->{$cmd}->{method} eq $params->{method}) && ($cmds->{$cmd}->{url} eq $params->{url})) {
+            $method_name = $cmd;
             last;
         }
     }

+ 58 - 58
lib/Selenium/Remote/Mock/RemoteConnection.pm

@@ -2,12 +2,12 @@ package Selenium::Remote::Mock::RemoteConnection;
 
 # ABSTRACT: utility class to mock the responses from Selenium server
 
-use Moo; 
-use JSON; 
+use Moo;
+use JSON;
 use Carp;
 use Try::Tiny;
-use HTTP::Response; 
-use Data::Dumper; 
+use HTTP::Response;
+use Data::Dumper;
 
 extends 'Selenium::Remote::RemoteConnection';
 
@@ -16,66 +16,66 @@ has 'spec' => (
     default => sub {{}},
 );
 
-has 'mock_cmds' => ( 
-    is => 'ro', 
+has 'mock_cmds' => (
+    is => 'ro',
 );
 
-has 'fake_session_id' => ( 
-    is => 'lazy', 
-    builder => sub { 
+has 'fake_session_id' => (
+    is => 'lazy',
+    builder => sub {
         my $id = join '',
         map +( 0 .. 9, 'a' .. 'z', 'A' .. 'Z' )[ rand( 10 + 26 * 2 ) ], 1 .. 50;
         return $id;
     },
 );
 
-has 'record' => ( 
-    is => 'ro', 
-    default => sub { 0 } 
+has 'record' => (
+    is => 'ro',
+    default => sub { 0 }
 );
 
-has 'replay' => ( 
+has 'replay' => (
     is => 'ro',
 );
 
-has 'replay_file' => ( 
+has 'replay_file' => (
     is => 'ro',
 );
 
 has 'session_store' => (
-    is => 'rw', 
+    is => 'rw',
     default => sub { {} }
 );
 
-has 'session_id' => ( 
+has 'session_id' => (
     is => 'rw',
     default => sub { undef },
 );
 
 sub BUILD {
-    my $self = shift; 
-    croak 'Cannot define replay and record attributes at the same time' if (($self->replay) && ($self->record)); 
-    croak 'replay_file attribute needs to be defined' if (($self->replay) && !($self->replay_file)); 
-    croak 'replay attribute needs to be defined' if (!($self->replay) && ($self->replay_file)); 
+    my $self = shift;
+    croak 'Cannot define replay and record attributes at the same time' if (($self->replay) && ($self->record));
+    croak 'replay_file attribute needs to be defined' if (($self->replay) && !($self->replay_file));
+    croak 'replay attribute needs to be defined' if (!($self->replay) && ($self->replay_file));
     $self->remote_server_addr('localhost');
     $self->port('4444');
-    if ($self->replay) { 
+    if ($self->replay) {
         $self->load_session_store($self->replay_file);
     }
 }
 
-sub check_status { 
+sub check_status {
     return;
 }
 
-sub load_session_store { 
-    my $self = shift; 
-    my $file = shift; 
+sub load_session_store {
+    my $self = shift;
+    my $file = shift;
     croak "'$file' is not a valid file" unless (-f $file);
     open (my $fh, '<', $file) or croak  "Opening '$file' failed";
     # here we use a fake session id since we have no way of figuring out
     # which session is good or not
-    local $/ = undef; 
+    local $/ = undef;
 
     my $json = JSON->new;
     $json->allow_blessed;
@@ -84,19 +84,19 @@ sub load_session_store {
     $self->session_store($decoded_json);
 }
 
-sub dump_session_store { 
-    my $self = shift; 
+sub dump_session_store {
+    my $self = shift;
     my ($file) = @_;
     open (my $fh, '>', $file) or croak "Opening '$file' failed";
     my $session_store = $self->session_store;
     my $dump = {};
-    foreach my $path (keys %{$session_store}) { 
+    foreach my $path (keys %{$session_store}) {
         $dump->{$path} = $session_store->{$path};
     }
     my $json = JSON->new;
     $json->allow_blessed;
     my $json_session = $json->allow_nonref->utf8->pretty->encode($dump);
-    print $fh $json_session; 
+    print $fh $json_session;
     close ($fh);
 }
 
@@ -109,7 +109,7 @@ sub request {
     my $content            = '';
     my $json               = JSON->new;
     $json->allow_blessed;
-    if ($params) { 
+    if ($params) {
         $content = $json->allow_nonref->utf8->canonical(1)->encode($params);
     }
     my $url_params = $resource->{url_params};
@@ -169,26 +169,26 @@ __END__
 
 =head1 DESCRIPTION
 
-Selenium::Remote::Mock::RemoteConnection is a class to act as a short-circuit or a pass through to the connection to a Selenium Server. 
-Using this class in place of L<Selenium::Remote::RemoteConnection> allows to: 
+Selenium::Remote::Mock::RemoteConnection is a class to act as a short-circuit or a pass through to the connection to a Selenium Server.
+Using this class in place of L<Selenium::Remote::RemoteConnection> allows to:
 
 =over
 
 =item *
-record interactions with the Selenium Server into a JSON file 
+record interactions with the Selenium Server into a JSON file
 
-=item * 
+=item *
 replay recorded interactions from a JSON file to mock answers from the Selenium Server
 
-=item * 
-mock responses to specific functions 
+=item *
+mock responses to specific functions
 
 =back
 
 =head1 SYNOPSIS
 
-=head2 Record interactions 
-    
+=head2 Record interactions
+
     #!perl
     use strict;
     use warnings;
@@ -204,7 +204,7 @@ mock responses to specific functions
     my $driver = Selenium::Remote::Driver->new( remote_conn => $mock_connection );
 
     # always store the session id, as it will become undef once
-    # $driver->quit is called  
+    # $driver->quit is called
     my $session_id = $driver->session_id;
 
     # do all the selenium things and quit
@@ -216,10 +216,10 @@ mock responses to specific functions
     $mock_connection->dump_session_store( 'my_record.json' );
 
 
-This code, above doing some basic Selenium interactions, will end up generating a JSON file containing all the requests and their responses for your Selenium session. 
-The JSON file looks like this : 
+This code, above doing some basic Selenium interactions, will end up generating a JSON file containing all the requests and their responses for your Selenium session.
+The JSON file looks like this :
 
-    { 
+    {
         "HTTP_REQUEST URL {request_parameters}":[ARRAY_OF_RESPONSES]
         ...
     }
@@ -233,11 +233,11 @@ The reason why we store array of responses is that the exact same request can be
     use warnings;
     use Test::More;
     use Test::Selenium::Remote::Driver;
-    use Selenium::Remote::Mock::RemoteConnection; 
+    use Selenium::Remote::Mock::RemoteConnection;
     my $mock_connection_2 =
       Selenium::Remote::Mock::RemoteConnection->new( replay => 1,
         replay_file => 'my_record.json' );
-    # javascript + version parameters added or else it will not work 
+    # javascript + version parameters added or else it will not work
     my $driver =
       Test::Selenium::Remote::Driver->new( remote_conn => $mock_connection_2, javascript => 1, version => '' );
     $driver->get_ok('http://www.google.com');
@@ -245,15 +245,15 @@ The reason why we store array of responses is that the exact same request can be
     $driver->quit;
     done_testing;
 
-Using the file generated with the recording snippet from the section before, we are able to mock the responses. 
+Using the file generated with the recording snippet from the section before, we are able to mock the responses.
 
 Note that there is one small limitation (that I hope to remove in future versions), is that a record generated with L<Selenium::Remote::Driver> is not directly useable with L<Test::Selenium::Remote::Driver>.
-This is mainly because the way the two instances are created are a bit different, which leads to different requests made, for creating a session for instance. 
+This is mainly because the way the two instances are created are a bit different, which leads to different requests made, for creating a session for instance.
 For now, what works for sure is recording and replaying from the same class.
 
 =head2 Mock responses
 
-    
+
     #!perl
     use Test::More;
     use Test::Selenium::Remote::Driver;
@@ -285,26 +285,26 @@ For now, what works for sure is recording and replaying from the same class.
 
     done_testing();
 
-Mocking responses by hand requires a more advanced knowledge of the underlying implementation of L<Selenium::Remote::Driver>. 
+Mocking responses by hand requires a more advanced knowledge of the underlying implementation of L<Selenium::Remote::Driver>.
 What we mock here is the processed response that will be returned by L<Selenium::Remote::RemoteConnection> to '_execute_command' call.
-To accomplish this we need : 
+To accomplish this we need :
 
 =over
 
 =item *
 a spec: a HASHREF which keys are the name of the methods we want to mock. Note that those keys should also be valid keys from the _cmds attribute in L<Selenium::Remote::Command>.
-The value of each key is a sub which will be given two parameters: 
+The value of each key is a sub which will be given two parameters:
 
-=over 
+=over
 
-=item * 
-$url_params : the values that should have been replaced in the URL 
+=item *
+$url_params : the values that should have been replaced in the URL
 For instance, on the example above, it would have been:
     { session_id => 'some_session_id'}
 
-=item * 
+=item *
 $params : the original parameters of the request.
-On the example above it would have been: 
+On the example above it would have been:
     { value => 'q', using => 'xpath'}
 
 
@@ -312,12 +312,12 @@ On the example above it would have been:
 
 The sub used as a value in the spec is not expected to return anything, so you have to craft very carefully what you return so that it will produce the expected result.
 
-=item * 
+=item *
 a mock_cmd: a L<Selenium::Remote::Mock::Commands> object. This is used mainly to hijack the normal commands so that placeholders do not get replaced in the URLs.
 
 =back
 
-=head1 BUGS 
+=head1 BUGS
 
 This code is really early alpha, so its API might change. Use with caution !
 

+ 2 - 3
lib/Selenium/Remote/RemoteConnection.pm

@@ -38,7 +38,7 @@ has 'error_handler' => (
 
 
 
-sub check_status { 
+sub check_status {
     my $self = shift;
     my $status;
     try {
@@ -57,7 +57,6 @@ sub check_status {
     unless ($status->{cmd_status} eq 'OK') {
         croak "Selenium server did not return proper status";
     }
-    
 }
 
 
@@ -105,7 +104,7 @@ sub request {
     $header->header('Accept' => 'application/json');
     my $request = HTTP::Request->new($method, $fullurl, $header, $content);
     my $response = $self->ua->request($request);
-    if ($dont_process_response) { 
+    if ($dont_process_response) {
         return $response;
     }
     return $self->_process_response($response, $no_content_success);

+ 5 - 5
t/01-driver.t

@@ -16,7 +16,7 @@ my $os  = $^O;
 if ($os =~ m/(aix|freebsd|openbsd|sunos|solaris)/) {
     $os = 'linux';
 }
-my %selenium_args = ( 
+my %selenium_args = (
     browser_name => 'firefox'
 );
 
@@ -26,10 +26,10 @@ if (!$record && !(-e "t/mock-recordings/$mock_file")) {
     plan skip_all => "Mocking of tests is not been enabled for this platform";
 }
 
-if ($record) { 
+if ($record) {
     $selenium_args{remote_conn} = Selenium::Remote::Mock::RemoteConnection->new(record => 1);
 }
-else { 
+else {
     $selenium_args{remote_conn} =
       Selenium::Remote::Mock::RemoteConnection->new( replay => 1,
         replay_file => "t/mock-recordings/$mock_file" );
@@ -340,7 +340,7 @@ PAUSE: {
 }
 
 AUTO_CLOSE: {
-    my %stay_open_selenium_args = %selenium_args; 
+    my %stay_open_selenium_args = %selenium_args;
     $stay_open_selenium_args{auto_close} = 0;
     my $stayOpen = Selenium::Remote::Driver->new(
         %stay_open_selenium_args
@@ -477,7 +477,7 @@ NO_SERVER_ERROR_MESSAGE: {
     };
     unlike($@, qr/Use of uninitialized value/, "Error message for no server at host/port combination is helpful");
 }
-if ($record) { 
+if ($record) {
     $driver->remote_conn->dump_session_store("t/mock-recordings/$mock_file");
 }
 

+ 4 - 4
t/02-webelement.t

@@ -16,13 +16,13 @@ my $mock_file = "02-webelement-mock-$os.json";
 if (!$record && !(-e "t/mock-recordings/$mock_file")) {
     plan skip_all => "Mocking of tests is not been enabled for this platform";
 }
-my %selenium_args = ( 
+my %selenium_args = (
     browser_name => 'firefox'
 );
-if ($record) { 
+if ($record) {
     $selenium_args{remote_conn} = Selenium::Remote::Mock::RemoteConnection->new(record => 1);
 }
-else { 
+else {
     $selenium_args{remote_conn} =
       Selenium::Remote::Mock::RemoteConnection->new( replay => 1,
         replay_file => "t/mock-recordings/$mock_file" );
@@ -128,7 +128,7 @@ QUIT: {
     ok((not defined $driver->{'session_id'}), 'Killed the remote session');
 }
 
-if ($record) { 
+if ($record) {
     $driver->remote_conn->dump_session_store("t/mock-recordings/$mock_file");
 }
 

+ 4 - 4
t/10-switch-to-window.t

@@ -12,7 +12,7 @@ if ($os =~ m/(aix|freebsd|openbsd|sunos|solaris)/) {
     $os = 'linux';
 }
 
-my %selenium_args = ( 
+my %selenium_args = (
     browser_name => 'firefox',
     default_finder => 'css',
     javascript     => 1,
@@ -23,10 +23,10 @@ if (!$record && !(-e "t/mock-recordings/$mock_file")) {
     plan skip_all => "Mocking of tests is not been enabled for this platform";
 }
 
-if ($record) { 
+if ($record) {
     $selenium_args{remote_conn} = Selenium::Remote::Mock::RemoteConnection->new(record => 1);
 }
-else { 
+else {
     $selenium_args{remote_conn} =
       Selenium::Remote::Mock::RemoteConnection->new( replay => 1,
         replay_file => "t/mock-recordings/$mock_file" );
@@ -72,6 +72,6 @@ $s->title_is($cpan_title);
 $s->switch_to_window('perlorg');
 $s->title_is($perl_title);
 
-if ($record) { 
+if ($record) {
     $s->remote_conn->dump_session_store("t/mock-recordings/$mock_file");
 }

+ 5 - 5
t/Firefox-Profile.t

@@ -24,13 +24,13 @@ if (!$record && !(-e "t/mock-recordings/$mock_file")) {
     plan skip_all => "Mocking of tests is not been enabled for this platform";
 }
 
-my %selenium_args = ( 
+my %selenium_args = (
     browser_name => 'firefox'
 );
-if ($record) { 
+if ($record) {
     $selenium_args{remote_conn} = Selenium::Remote::Mock::RemoteConnection->new(record => 1);
 }
-else { 
+else {
     $selenium_args{remote_conn} =
       Selenium::Remote::Mock::RemoteConnection->new( replay => 1,
         replay_file => "t/mock-recordings/$mock_file" );
@@ -74,7 +74,7 @@ CUSTOM_EXTENSION_LOADED: {
         $encoded = do {local $/ = undef; <$fh>};
         close ($fh);
     }
-    my %driver_args = %selenium_args; 
+    my %driver_args = %selenium_args;
     $driver_args{extra_capabilities} = { firefox_profile => $encoded };
     my $driver = Selenium::Remote::Driver->new(%driver_args);
 
@@ -193,7 +193,7 @@ CROAKING: {
         ok ($@ =~ /coercion.*failed/, "caught invalid extension in driver constructor");
     }
 }
-if ($record) { 
+if ($record) {
     $selenium_args{remote_conn}->dump_session_store("t/mock-recordings/$mock_file");
 }
 done_testing;

+ 4 - 4
t/Test-Selenium-Remote-Driver-google.t

@@ -11,7 +11,7 @@ if ($os =~ m/(aix|freebsd|openbsd|sunos|solaris)/) {
     $os = 'linux';
 }
 
-my %selenium_args = ( 
+my %selenium_args = (
     browser_name => 'firefox',
     javascript => 1
 );
@@ -21,10 +21,10 @@ if (!$record && !(-e "t/mock-recordings/$mock_file")) {
     plan skip_all => "Mocking of tests is not been enabled for this platform";
 }
 
-if ($record) { 
+if ($record) {
     $selenium_args{remote_conn} = Selenium::Remote::Mock::RemoteConnection->new(record => 1);
 }
-else { 
+else {
     $selenium_args{remote_conn} =
       Selenium::Remote::Mock::RemoteConnection->new( replay => 1,
         replay_file => "t/mock-recordings/$mock_file" );
@@ -38,7 +38,7 @@ $t->get_ok('http://www.google.com');
 $t->title_like(qr/Google/);
 $t->body_like(qr/Google/);
 
-if ($record) { 
+if ($record) {
     $t->remote_conn->dump_session_store("t/mock-recordings/$mock_file");
 }
 

+ 2 - 2
t/Test-Selenium-Remote-WebElement.t

@@ -15,7 +15,7 @@ foreach my $k (
       $spec->{$k} = sub { return { status => 'OK', return => 1 }};
 }
 
-$spec->{getElementTagName} = sub { return { status => 'OK', return => 'iframe' }}; 
+$spec->{getElementTagName} = sub { return { status => 'OK', return => 'iframe' }};
 $spec->{getElementValue} = sub { return { status => 'OK', return => 'my_value' }};
 $spec->{getElementText} = sub { return { status => 'OK', return => "my_text\nis fantastic" }};
 $spec->{getElementAttribute}  = sub { my @args = @_; my $name = $args[0]->{name};  return { status => 'OK', return => "my_$name" }};
@@ -36,7 +36,7 @@ $successful_element->is_enabled_ok;
 $successful_element->is_displayed_ok;
 $successful_element->send_keys_ok('Hello World');
 $successful_element->tag_name_is( 'iframe', 'we got an iframe tag' );
-$successful_element->tag_name_isnt( 'BOOM', 'tag name is not boom' ); 
+$successful_element->tag_name_isnt( 'BOOM', 'tag name is not boom' );
 $successful_element->tag_name_unlike( qr/BOOM/, "tag_name doesn't match BOOM" );
 $successful_element->value_is( 'my_value', 'Got an my_value value?' );
 $successful_element->value_isnt( 'BOOM', 'Not BOOM.' );