Forráskód Böngészése

Add orientation endpoints. NB - only available for mobile

Daniel Gempesaw 11 éve
szülő
commit
0d03188fff
3 módosított fájl, 59 hozzáadás és 0 törlés
  1. 8 0
      lib/Selenium/Remote/Commands.pm
  2. 43 0
      lib/Selenium/Remote/Driver.pm
  3. 8 0
      t/01-driver.t

+ 8 - 0
lib/Selenium/Remote/Commands.pm

@@ -384,6 +384,14 @@ has '_cmds' => (
                 '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
             },
 

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

@@ -2149,6 +2149,49 @@ sub get_log_types {
     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:

+ 8 - 0
t/01-driver.t

@@ -198,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: {