Browse Source

Firefox extension command to switch context

geckodriver (Firefox>48) supports, the jsonwire extension for context
switching: /session/{sessionId}/moz/context

"Chrome" is a privileged scope where you can access things like the
Firefox UI itself. "Content" scope is where things like webpages live.
Vangelis Katsikaros 10 năm trước cách đây
mục cha
commit
0556d4b6c5
2 tập tin đã thay đổi với 72 bổ sung0 xóa
  1. 11 0
      lib/Selenium/Remote/Commands.pm
  2. 61 0
      lib/Selenium/Remote/Driver.pm

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

@@ -394,6 +394,17 @@ has '_cmds' => (
                 'url'                => 'session/:sessionId/orientation',
                 'no_content_success' => 0
             },
+            # firefox extension
+            'setContext' => {
+                'method'             => 'POST',
+                'url'                => 'session/:sessionId/moz/context',
+                'no_content_success' => 1
+            },
+            'getContext' => {
+                'method'             => 'GET',
+                'url'                => 'session/:sessionId/moz/context',
+                'no_content_success' => 0
+            },
 
             # /session/:sessionId/local_storage
             # /session/:sessionId/local_storage/key/:key

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

@@ -1188,6 +1188,67 @@ sub get_window_size {
     return $self->_execute_command($res);
 }
 
+=head2 get_context
+
+ Description:
+    Firefox extension: Retrieve browser's scope (chrome or content).
+    Chrome is a privileged scope where you can access things like the
+    Firefox UI itself. Content scope is where things like webpages live.
+
+ Output:
+    STRING - context (values: chrome or content)
+
+ Usage:
+    print $firefox_driver->get_context();
+
+=cut
+
+sub get_context {
+    my $self = shift;
+
+    if ( $self->isa('Selenium::Firefox') && $self->_is_old_ff ) {
+        return 0;
+    }
+    my $res = { 'command' => 'getContext' };
+    return $self->_execute_command($res);
+}
+
+=head2 set_context
+
+ Description:
+    Firefox extension: Set browser's scope (chrome or content).
+    Chrome is a privileged scope where you can access things like the
+    Firefox UI itself. Content scope is where things like webpages live.
+
+ Input:
+    Required:
+        <STRING> - Orientation {CHROME|CONTENT}
+
+ Usage:
+    $firefox_driver->set_context( $context  );
+
+ Output:
+    BOOLEAN - success or failure
+
+=cut
+
+sub set_context {
+    my ( $self, $context ) = @_;
+
+    if ( $self->isa('Selenium::Firefox') && $self->_is_old_ff ) {
+		return 0;
+	}
+
+    if ( not defined $context ) {
+        croak "Expecting context";
+    }
+    if ( $context !~ m/chrome|content/i ) {
+        croak "Expecting context value: chrome or content";
+    }
+    my $res = { 'command' => 'setContext' };
+    return $self->_execute_command( $res, { context => $context } );
+}
+
 =head2 get_window_position
 
  Description: