소스 검색

Merged master, one test failing because of recordings

Emmanuel Peroumalnaik 11 년 전
부모
커밋
38c565f378

+ 12 - 11
.travis.yml

@@ -1,23 +1,24 @@
 language: perl
 perl:
-   - 5.19
-   - 5.18
-   - 5.16
-   - 5.14
-   - 5.12
-   - 5.10
-   - 5.8
+   - '5.20'
+   - '5.18'
+   - '5.16'
+   - '5.14'
+   - '5.12'
+   - '5.10'
 matrix:
-   allow_failures:
-      - perl: 5.8
    fast_finish: true
 before_install:
    - export AUTOMATED_TESTING=1 NONINTERACTIVE_TESTING=1 HARNESS_OPTIONS=j10:c HARNESS_TIMER=1
+   - git clone git://github.com/haarg/perl-travis-helper
+   - source perl-travis-helper/init
+   - build-perl
+   - perl -V
    - git config --global user.name "TravisCI"
    - git config --global user.email $HOSTNAME":not-for-mail@travis-ci.org"
 install:
    - cpanm --quiet --notest --skip-satisfied Dist::Zilla
-   - "dzil authordeps --missing | grep -vP '[^\\w:]' | xargs -n 5 -P 10 cpanm --quiet --notest"
-   - "dzil listdeps   --missing | grep -vP '[^\\w:]' | cpanm --verbose"
+   - "dzil authordeps          --missing | grep -vP '[^\\w:]' | xargs -n 5 -P 10 cpanm --quiet --notest"
+   - "dzil listdeps   --author --missing | grep -vP '[^\\w:]' | xargs -n 5 -P 10 cpanm --quiet --notest"
 script:
    - dzil smoke --release --author

+ 13 - 0
Changes

@@ -1,5 +1,18 @@
 Revision history for Selenium-Remote-Driver
 
+0.2150 10-10-2014
+        [NEW FEATURES]
+        - Improved error messaging for Saucelabs non-json cases
+        - Improved error messaging for incorrectly configured chromedrivers
+
+        [MAINTENAINCE]
+        - Specify minimum compatible version of Moo dep
+        - Make Driver.pm more easily subclassed ( ea68e06, 63e78e3 )
+        - Get TravisCI passing again
+
+        [BREAKING]
+        - get|set_speed subs are no-ops and will be removed in the upcoming release
+
 0.2102 7-16-2014
         [NEW FEATURES]
         - Add inner_window_size sub and hash key option to accomodate S-R-D-UserAgent use

+ 1 - 0
cpanfile

@@ -32,6 +32,7 @@ requires "warnings" => "0";
 on 'test' => sub {
   requires "File::Basename" => "0";
   requires "File::stat" => "0";
+  requires "IO::Socket::INET" => "0";
   requires "LWP::Protocol::PSGI" => "0.04";
   requires "LWP::Simple" => "0";
   requires "Test::Exception" => "0";

+ 6 - 4
dist.ini

@@ -1,5 +1,5 @@
 name = Selenium-Remote-Driver
-version = 0.2102
+version = 0.2150
 author = Aditya Ivaturi <ivaturi@gmail.com>
 author = Daniel Gempesaw <gempesaw@gmail.com>
 author = Luke Closs <cpan@5thplane.com>
@@ -9,7 +9,11 @@ copyright_holder = Daniel Gempesaw
 copyright_year = 2014
 
 [TravisYML]
-build_branch = cpan
+build_branch = /cpan|build/
+perl_version = 5.20 5.18 5.16 5.14 5.12 5.10
+dzil_branch =
+test_authordeps = 0
+test_deps = 0
 
 [Git::Check]
 [Git::Commit]
@@ -18,10 +22,8 @@ build_branch = cpan
 [Git::CommitBuild]
 release_branch = cpan
 release_message = v%v - Build results of %h (on %b)
-branch =
 
 [AutoPrereqs]
-
 [GatherDir]
 include_dotfiles = 1
 exclude_filename = cpanfile

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

@@ -300,7 +300,7 @@ has 'webelement_class' => (
 
 has 'default_finder' => (
     is      => 'rw',
-    coerce  => sub { FINDERS->{ $_[0] } },
+    coerce  => sub { __PACKAGE__->FINDERS->{ $_[0] } },
     default => sub {'xpath'},
 );
 
@@ -1501,48 +1501,31 @@ sub switch_to_window {
 =head2 get_speed
 
  Description:
-    Get the current user input speed. The actual input speed is still browser
-    specific and not covered by the Driver.
-
- Output:
-    STRING - One of these: SLOW, MEDIUM, FAST
-
- Usage:
-    print $driver->get_speed();
+    DEPRECATED - this function is a no-op in Webdriver, and will be
+    removed in the upcoming version of this module. See
+    https://groups.google.com/d/topic/selenium-users/oX0ZnYFPuSA/discussion
+    and
+    http://code.google.com/p/selenium/source/browse/trunk/java/client/src/org/openqa/selenium/WebDriverCommandProcessor.java
 
 =cut
 
 sub get_speed {
-    my ($self) = @_;
-    my $res = { 'command' => 'getSpeed' };
-    return $self->_execute_command($res);
+    carp 'get_speed is deprecated and will be removed in the upcoming version of this module';
 }
 
 =head2 set_speed
 
  Description:
-    Set the user input speed.
-
- Input:
-    STRING - One of these: SLOW, MEDIUM, FAST
-
- Usage:
-    $driver->set_speed('MEDIUM');
-
- Note: This function is a no-op in WebDriver (?). See
-       https://groups.google.com/d/topic/selenium-users/oX0ZnYFPuSA/discussion and
-       http://code.google.com/p/selenium/source/browse/trunk/java/client/src/org/openqa/selenium/WebDriverCommandProcessor.java
+    DEPRECATED - this function is a no-op in Webdriver, and will be
+    removed in the upcoming version of this module. See
+    https://groups.google.com/d/topic/selenium-users/oX0ZnYFPuSA/discussion
+    and
+    http://code.google.com/p/selenium/source/browse/trunk/java/client/src/org/openqa/selenium/WebDriverCommandProcessor.java
 
 =cut
 
 sub set_speed {
-    my ( $self, $speed ) = @_;
-    if ( not defined $speed ) {
-        return 'Speed not provided.';
-    }
-    my $res    = { 'command' => 'setSpeed' };
-    my $params = { 'speed'   => $speed };
-    return $self->_execute_command( $res, $params );
+    carp 'set_speed is deprecated and will be removed in the upcoming version of this module';
 }
 
 =head2 set_window_position
@@ -1768,7 +1751,7 @@ sub find_element {
         croak 'Search string to find element not provided.';
     }
     my $using =
-      ( defined $method ) ? FINDERS->{$method} : $self->default_finder;
+      ( defined $method ) ? $self->FINDERS->{$method} : $self->default_finder;
     if ( defined $using ) {
         my $res = { 'command' => 'findElement' };
         my $params = { 'using' => $using, 'value' => $query };
@@ -1827,7 +1810,7 @@ sub find_elements {
     }
 
     my $using =
-      ( defined $method ) ? FINDERS->{$method} : $self->default_finder;
+      ( defined $method ) ? $self->FINDERS->{$method} : $self->default_finder;
 
     if ( defined $using ) {
         my $res = { 'command' => 'findElements' };
@@ -1902,9 +1885,9 @@ sub find_child_element {
         croak "Missing parameters";
     }
     my $using = ( defined $method ) ? $method : $self->default_finder;
-    if ( exists FINDERS->{$using} ) {
+    if ( exists $self->FINDERS->{$using} ) {
         my $res = { 'command' => 'findChildElement', 'id' => $elem->{id} };
-        my $params = { 'using' => FINDERS->{$using}, 'value' => $query };
+        my $params = { 'using' => $self->FINDERS->{$using}, 'value' => $query };
         my $ret_data = eval { $self->_execute_command( $res, $params ); };
         if ($@) {
             if ( $@
@@ -1963,9 +1946,9 @@ sub find_child_elements {
         croak "Missing parameters";
     }
     my $using = ( defined $method ) ? $method : $self->default_finder;
-    if ( exists FINDERS->{$using} ) {
+    if ( exists $self->FINDERS->{$using} ) {
         my $res = { 'command' => 'findChildElements', 'id' => $elem->{id} };
-        my $params = { 'using' => FINDERS->{$using}, 'value' => $query };
+        my $params = { 'using' => $self->FINDERS->{$using}, 'value' => $query };
         my $ret_data = eval { $self->_execute_command( $res, $params ); };
         if ($@) {
             if ( $@
@@ -2259,6 +2242,23 @@ sub get_path {
     return $location;
 }
 
+=head2 get_user_agent
+
+ Description:
+    Convenience method to get the user agent string, according to the
+    browser's value for window.navigator.userAgent.
+
+ Usage:
+    $user_agent = $driver->get_user_agent()
+
+=cut
+
+sub get_user_agent {
+    my $self = shift;
+    return $self->execute_script('return window.navigator.userAgent;');
+}
+
+
 =head2 set_inner_window_size
 
  Description:

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

@@ -246,7 +246,7 @@ The JSON file looks like this :
         ...
     }
 
-The reason why we store array of responses is that the exact same request can be make more than once during a session, so we have to store every response to the same requests.
+The reason why we store array of responses is that the exact same request can be made more than once during a session, so we have to store every response to the same requests.
 
 =head2 Replay interactions
 

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

@@ -31,6 +31,13 @@ has 'ua' => (
     builder => sub { return LWP::UserAgent->new; }
 );
 
+has 'error_handler' => (
+    is => 'lazy',
+    builder => sub { return Selenium::Remote::ErrorHandler->new; }
+);
+
+
+
 sub check_status { 
     my $self = shift;
     my $status;
@@ -119,7 +126,7 @@ sub _process_response {
         if (($response->message ne 'No Content') && ($response->content ne '')) {
             if ($response->content_type !~ m/json/i) {
                 $data->{'cmd_status'} = 'NOTOK';
-                $data->{'cmd_return'} = 'Server returned error message '.$response->content.' instead of data';
+                $data->{'cmd_return'}->{message} = 'Server returned error message '.$response->content.' instead of data';
                 return $data;
             }
             $decoded_json = $json->allow_nonref(1)->utf8(1)->decode($response->content);
@@ -127,10 +134,9 @@ sub _process_response {
         }
 
         if ($response->is_error) {
-            my $error_handler = Selenium::Remote::ErrorHandler->new;
             $data->{'cmd_status'} = 'NOTOK';
             if (defined $decoded_json) {
-                $data->{'cmd_return'} = $error_handler->process_error($decoded_json);
+                $data->{'cmd_return'} = $self->error_handler->process_error($decoded_json);
             }
             else {
                 $data->{'cmd_return'} = 'Server returned error code '.$response->code.' and no data';

+ 19 - 8
t/01-driver.t

@@ -9,8 +9,8 @@ use LWP::Protocol::PSGI;
 use LWP::UserAgent;
 use Test::LWP::UserAgent;
 use Selenium::Remote::Driver;
-use Selenium::Remote::Mock::Commands; 
-use Selenium::Remote::Mock::RemoteConnection; 
+use Selenium::Remote::Mock::Commands;
+use Selenium::Remote::Mock::RemoteConnection;
 
 BEGIN {
     if (defined $ENV{'WD_MOCKING_RECORD'} && ($ENV{'WD_MOCKING_RECORD'}==1)) {
@@ -165,7 +165,7 @@ IME: {
         if ($@) {
             skip "ime not available on this system",3;
         }
-    };
+    }
 }
 
 LOAD_PAGE: {
@@ -255,10 +255,10 @@ FIND: {
     $ret = $driver->find_child_elements($elem, "//option[\@selected='selected']");
     is(@{$ret}, 4, 'Got 4 WebElements');
     my $expected_err = "An element could not be located on the page using the "
-    . "given search parameters: "
-    . "element_that_doesnt_exist,id"
-    # the following needs to always be right before the eval
-    . " at " . __FILE__ . " line " . (__LINE__+1);
+      . "given search parameters: "
+      . "element_that_doesnt_exist,id"
+      # the following needs to always be right before the eval
+      . " at " . __FILE__ . " line " . (__LINE__+1);
     eval { $driver->find_element("element_that_doesnt_exist","id"); };
     chomp $@;
     is($@,$expected_err.".","find_element croaks properly");
@@ -409,7 +409,13 @@ BASE_URL: {
         my $base_url_driver = MySeleniumRemoteDriver->new(
             browser_name => 'firefox',
             base_url     => $test->{base_url},
-            remote_conn => Selenium::Remote::Mock::RemoteConnection->new(spec => {}, mock_cmds => $mock_commands),
+            remote_conn => Selenium::Remote::Mock::RemoteConnection->new(
+                spec => {
+                    get =>
+                      sub { my ( undef, $params ) = @_; return $params->{url} }
+                },
+                mock_cmds => $mock_commands
+              ),
             commands => $mock_commands,
         );
         my $got = $base_url_driver->get($test->{url});
@@ -417,6 +423,11 @@ BASE_URL: {
     }
 }
 
+USER_AGENT: {
+    my $ua = $driver->get_user_agent;
+    ok($ua =~ /Firefox/, 'we can get a user agent');
+}
+
 STORAGE: {
     my $chrome;
 

+ 76 - 0
t/error.t

@@ -0,0 +1,76 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+use Test::LWP::UserAgent;
+use IO::Socket::INET;
+
+
+BEGIN: {
+    unless (use_ok('Selenium::Remote::Driver')) {
+        BAIL_OUT("Couldn't load Selenium::Remote::Driver");
+        exit;
+    }
+}
+
+UNAVAILABLE_BROWSER: {
+    my $tua = Test::LWP::UserAgent->new;
+
+    $tua->map_response(qr{status}, HTTP::Response->new(200, 'OK'));
+    $tua->map_response(qr{session}, HTTP::Response->new(
+        500,
+        'Internal Server Error',
+        ['Content-Type' => 'application/json'],
+        '{"status":13,"sessionId":null,"value":{"message":"The path to..."} }'
+    ));
+
+    throws_ok(
+        sub {
+            Selenium::Remote::Driver->new_from_caps(
+                ua => $tua,
+                desired_capabilities => {
+                    browserName => 'chrome'
+                }
+            );
+        }, qr/Could not create new session.*path to/,
+        'Errors in browser configuration are passed to user'
+    );
+}
+
+LOCAL: {
+    throws_ok(
+        sub {
+            Selenium::Remote::Driver->new_from_caps( port => 80 );
+        }, qr/Selenium server did not return proper status/,
+        'Error message for not finding a selenium server is helpful'
+    );
+}
+
+SAUCE: {
+  SKIP: {
+        my $host = 'ondemand.saucelabs.com';
+        my $port = 80;
+        my $sock = IO::Socket::INET->new(
+            PeerAddr => $host,
+            PeerPort => $port,
+        );
+
+        skip 'Cannot reach saucelabs for Sauce error case ', 1
+          unless $sock;
+
+        throws_ok(
+            sub {
+                Selenium::Remote::Driver->new_from_caps(
+                    remote_server_addr => $host,
+                    port => $port,
+                    desired_capabilities => {
+                        browserName => 'invalid'
+                    }
+                );
+            }, qr/Sauce Labs/, 'Saucelabs errors are passed to user');
+
+    }
+}
+done_testing;

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
t/mock-recordings/01-driver-mock-darwin.json


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
t/mock-recordings/01-driver-mock-linux.json


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
t/mock-recordings/02-webelement-mock-darwin.json


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
t/mock-recordings/02-webelement-mock-linux.json


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
t/mock-recordings/firefox-profile-mock-darwin.json


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
t/mock-recordings/firefox-profile-mock-linux.json


이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.