Переглянути джерело

Merge remote-tracking branch 'refs/remotes/origin/#113-add-endpoints'

Conflicts:
	t/03-spec-coverage.t
Daniel Gempesaw 11 роки тому
батько
коміт
9462cb064d
4 змінених файлів з 250 додано та 9 видалено
  1. 36 1
      lib/Selenium/Remote/Commands.pm
  2. 161 0
      lib/Selenium/Remote/Driver.pm
  3. 52 5
      t/01-driver.t
  4. 1 3
      t/03-spec-coverage.t

+ 36 - 1
lib/Selenium/Remote/Commands.pm

@@ -358,7 +358,42 @@ has '_cmds' => (
                 'method'             => 'DELETE',
                 'url'                => '/session/:sessionId/local_storage/key/:key',
                 'no_content_success' => 1
-            }
+            },
+            'cacheStatus' => {
+                'method'             => 'GET',
+                'url'                => 'session/:sessionId/application_cache/status',
+                'no_content_success' => 0
+            },
+            'setGeolocation' => {
+                'method'             => 'POST',
+                'url'                => 'session/:sessionId/location',
+                'no_content_success' => 1
+            },
+            'getGeolocation'   => {
+                'method'             => 'GET',
+                'url'                => 'session/:sessionId/location',
+                'no_content_success' => 0
+            },
+            'getLog' => {
+                'method'             => 'POST',
+                'url'                => 'session/:sessionId/log',
+                'no_content_success' => 0
+            },
+            'getLogTypes'   => {
+                'method'             => 'GET',
+                'url'                => 'session/:sessionId/log/types',
+                'no_content_success' => 0
+            },
+            'setOrientation' => {
+                'method'             => 'POST',
+                'url'                => 'session/:sessionId/orientation',
+                'no_content_success' => 1
+            },
+            'getOrientation'   => {
+                'method'             => 'GET',
+                'url'                => 'session/:sessionId/orientation',
+                'no_content_success' => 0
+            },
 
             # /session/:sessionId/local_storage
             # /session/:sessionId/local_storage/key/:key

+ 161 - 0
lib/Selenium/Remote/Driver.pm

@@ -2027,6 +2027,167 @@ sub get_active_element {
     }
 }
 
+=head2 cache_status
+
+ Description:
+    Get the status of the html5 application cache.
+
+ Usage:
+    print $driver->cache_status;
+
+ Output:
+    <number> - Status code for application cache: {UNCACHED = 0, IDLE = 1, CHECKING = 2, DOWNLOADING = 3, UPDATE_READY = 4, OBSOLETE = 5}
+
+=cut
+
+sub cache_status {
+    my ($self) = @_;
+    my $res = { 'command' => 'cacheStatus' };
+    return $self->_execute_command($res);
+}
+
+=head2 set_geolocation
+
+ Description:
+    Set the current geographic location - note that your driver must
+    implement this endpoint, or else it will crash your session. At the
+    very least, it works in v2.12 of Chromedriver.
+
+ Input:
+    Required:
+        HASH: A hash with key C<location> whose value is a Location hashref. See
+        usage section for example.
+
+ Usage:
+    $driver->set_geolocation( location => {
+        latitude  => 40.714353,
+        longitude => -74.005973,
+        altitude  => 0.056747
+    });
+
+ Output:
+    BOOLEAN - success or failure
+
+=cut
+
+sub set_geolocation {
+    my ( $self, %params ) = @_;
+    my $res = { 'command' => 'setGeolocation' };
+    return $self->_execute_command( $res, \%params );
+}
+
+=head2 get_geolocation
+
+ Description:
+    Get the current geographic location. Note that your webdriver must
+    implement this endpoint - otherwise, it will crash your session. At
+    the time of release, we couldn't get this to work on the desktop
+    FirefoxDriver or desktop Chromedriver.
+
+ Usage:
+    print $driver->get_geolocation;
+
+ Output:
+    { latitude: number, longitude: number, altitude: number } - The current geo location.
+
+=cut
+
+sub get_geolocation {
+    my ($self) = @_;
+    my $res = { 'command' => 'getGeolocation' };
+    return $self->_execute_command($res);
+}
+
+=head2 get_log
+
+ Description:
+    Get the log for a given log type. Log buffer is reset after each request.
+
+ Input:
+    Required:
+        <STRING> - Type of log to retrieve:
+        {client|driver|browser|server}. There may be others available; see
+        get_log_types for a full list for your driver.
+
+ Usage:
+    $driver->get_log( $log_type );
+
+ Output:
+    <ARRAY|ARRAYREF> - An array of log entries since the most recent request.
+
+=cut
+
+sub get_log {
+    my ( $self, $type ) = @_;
+    my $res = { 'command' => 'getLog' };
+    return $self->_execute_command( $res, { type => $type });
+}
+
+=head2 get_log_types
+
+ Description:
+    Get available log types. By default, every driver should have client,
+    driver, browser, and server types, but there may be more available,
+    depending on your driver.
+
+ Usage:
+    my @types = $driver->get_log_types;
+    $driver->get_log($types[0]);
+
+ Output:
+    <ARRAYREF> - The list of log types.
+
+=cut
+
+sub get_log_types {
+    my ($self) = @_;
+    my $res = { 'command' => 'getLogTypes' };
+    return $self->_execute_command($res);
+}
+
+
+=head2 set_orientation
+
+ Description:
+    Set the browser orientation.
+
+ Input:
+    Required:
+        <STRING> - Orientation {LANDSCAPE|PORTRAIT}
+
+ Usage:
+    $driver->set_orientation( $orientation  );
+
+ Output:
+    BOOLEAN - success or failure
+
+=cut
+
+sub set_orientation {
+    my ( $self, $orientation ) = @_;
+    my $res = { 'command' => 'setOrientation' };
+    return $self->_execute_command( $res, { orientation => $orientation } );
+}
+
+=head2 get_orientation
+
+ Description:
+    Get the current browser orientation. Returns either LANDSCAPE|PORTRAIT.
+
+ Usage:
+    print $driver->get_orientation;
+
+ Output:
+    <STRING> - your orientation.
+
+=cut
+
+sub get_orientation {
+    my ($self) = @_;
+    my $res = { 'command' => 'getOrientation' };
+    return $self->_execute_command($res);
+}
+
 =head2 send_modifier
 
  Description:

+ 52 - 5
t/01-driver.t

@@ -23,6 +23,12 @@ my $driver = Selenium::Remote::Driver->new(%selenium_args);
 my $website = 'http://localhost:63636';
 my $ret;
 
+my $chrome;
+eval { $chrome = Selenium::Remote::Driver->new(
+    %selenium_args,
+    browser_name => 'chrome'
+); };
+
 DESIRED_CAPABILITIES: {
     # We're using a different test method for these because we needed
     # to inspect payload of the POST to /session, and the method of
@@ -192,6 +198,14 @@ WINDOW: {
     ok(!$@,"Reset implicit wait timeout");
     $ret = $driver->get("$website/frameset.html");
     $ret = $driver->switch_to_frame('second');
+
+  SKIP: {
+        skip 'Cannot rotate desktop browsers', 3;
+        ok($driver->get_orientation eq 'PORTRAIT', 'Can get default orientation');
+        $ret = $driver->set_orientation('LANDSCAPE');
+        ok($ret, 'Can change orientation to LANDSCAPE');
+        ok($driver->get_orientation eq 'LANDSCAPE', 'Can get changed orientation');
+    }
 }
 
 COOKIES: {
@@ -424,13 +438,8 @@ USER_AGENT: {
 }
 
 STORAGE: {
-    my $chrome;
-    my %selenium_chrome_args = ( browser_name => 'chrome');
-    $selenium_chrome_args{remote_conn} = $selenium_args{remote_conn};
-
   SKIP: {
         eval {
-            $chrome = Selenium::Remote::Driver->new(%selenium_chrome_args);
             $chrome->get($website);
         };
 
@@ -450,6 +459,44 @@ STORAGE: {
     }
 }
 
+HTML5: {
+  SKIP: {
+        skip 'HTML5 Application Cache is not supported by firefox or chrome', 1 if 1;
+        $driver->get($website);
+        my $status = $driver->cache_status;
+        ok($status, 'we can get application cache status');
+    }
+
+  SKIP: {
+        skip 'Geolocation requires Chrome to test', 2 unless $chrome;
+
+        my $ret = $chrome->set_geolocation( location => {
+            latitude => 40.714353,
+            longitude => -74.005973,
+            altitude => 0.056747
+        });
+        ok($ret, 'can set geolocation');
+
+      TODO: {
+            local $TODO = 'GET geolocation has a cast Long to Double error in Chromedriver';
+            my $ret = {};
+            eval { $ret = $chrome->get_geolocation };
+            ok(exists $ret->{location}, 'get_geolocation returns a location dictionary.');
+        }
+    }
+}
+
+LOGS: {
+    $driver->get($website);
+
+    my $types = $driver->get_log_types;
+    ok(scalar @$types >= 4, 'Can get log types');
+    foreach (@$types) {
+        my $log = $driver->get_log($_);
+        ok(defined $log, 'Can get logs from the ' . $_);
+    }
+}
+
 QUIT: {
     $ret = $driver->quit();
     ok((not defined $driver->{'session_id'}), 'Killed the remote session');

+ 1 - 3
t/03-spec-coverage.t

@@ -35,6 +35,7 @@ my $todo_list = {
    'POST session/:sessionId/keys'                          => 1,
    'GET session/:sessionId/location'                       => 1,
    'POST session/:sessionId/location'                      => 1,
+   'POST session/:sessionId/window/:windowHandle/maximize' => 1,
    'GET session/:sessionId/local_storage'                  => 1,
    'POST session/:sessionId/local_storage'                 => 1,
    'DELETE session/:sessionId/local_storage'               => 1,
@@ -47,9 +48,6 @@ my $todo_list = {
    'GET session/:sessionId/session_storage/key/:key'       => 1,
    'DELETE session/:sessionId/session_storage/key/:key'    => 1,
    'GET session/:sessionId/session_storage/size'           => 1,
-   'POST session/:sessionId/log'                           => 1,
-   'GET session/:sessionId/log/types'                      => 1,
-   'GET session/:sessionId/application_cache/status'       => 1,
 };
 my @lines = split(/\n/, $data);
 my @methods;